Skip to content

Instantly share code, notes, and snippets.

View joeljacobs's full-sized avatar

Joel Jacobs joeljacobs

  • Perfect Pitch Tehnologies
  • Utah
View GitHub Profile
@joeljacobs
joeljacobs / vmmem
Last active April 18, 2018 01:56
virsh mem
function vmmem { free="$(free -h)";echo "$free";memtotal=0 ; for i in $(virsh list --name); do mem=$(( $(virsh dommemstat $i |head -1|cut -d " " -f 2) /1024/1024));memtotal=$(( $memtotal + $mem)); printf "%-20s%10s\n" $i $mem; done; echo " Total VM ${memtotal}G"; echo " Difference: $(( $(echo "$free" |grep "Mem:"|cut -d " " -f 12|rev|cut -c 2-|rev) - $memtotal))G"|sort -V; }
@joeljacobs
joeljacobs / zfsswap
Created April 17, 2018 22:02
Add ZFS swap
function zfsswap { pool=${1-rpool}; gigs=${2-50};zfs create -V ${gigs}G -b $(getconf PAGESIZE) -o compression=zle -o logbias=throughput -o sync=always -o primarycache=metadata -o secondarycache=none -o com.sun:auto-snapshot=false $pool/swap && mkswap -f /dev/zvol/$pool/swap && echo /dev/zvol/$pool/swap none swap defaults 0 0 >> /etc/fstab && swapon -av ; }
@joeljacobs
joeljacobs / pibackup
Last active December 22, 2020 06:56
Modified Script to Backup All partitions of a RaspberryPi. Added incremental rsync.
#!/bin/bash
if [[ $1 == "" ]]
then
echo "You must specify the copy-to device as the first argument"
echo "You may also specify a source device as the 2nd argument. Default= mmcblk0"
echo "If you want no prompts and incremental, specify -a as the last argument"
echo "i.e.: backup sda [nbd0] [-a]"
@joeljacobs
joeljacobs / externalip.sh
Created February 7, 2018 20:15
External IP script (from Jon)
#!/bin/bash
## Get my external IP
timeout=2 # seconds to wait for a reply before trying next server
#verbose=1 # prints which server was used to STDERR
dnslist=(
"dig +short myip.opendns.com @resolver1.opendns.com"
"dig +short myip.opendns.com @resolver2.opendns.com"
@joeljacobs
joeljacobs / - instructions
Last active April 20, 2024 14:02
Rico SP C250DN Toner Reset on Raspberry Pi
Below are single-line commands to run in BASH on a Raspberry Pi to rewrite the toner chips to "full" for a Ricoh SP C250DN Printer.
You will need to have the 4 files below in the same directory: "black" "cyan" "magenta" and "yellow".
The chip is near one edge of the cartridge. The pad closest to the edge is GND, followed by VCC, DATA, and Clock.
On the Pi, connect VCC and GND to +3.3V and GND. Connect Data to (physical numbering) 3 and 5. They are the I2C Data and Clock pins.
Be sure i2c is enabled and installed.
modprobe -r i2c_bcm2708 ;modprobe i2c_bcm2708 baudrate=9600
@joeljacobs
joeljacobs / release_non-swarm.sh
Created September 16, 2017 00:07
Bash threaded parallel with getopt example
#!/bin/bash
OPTS=`getopt -o vhns: --long service:,sha:,server: -n 'parse-options' -- "$@"`
fail=false
if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
eval set -- "$OPTS"
servers=()
while true; do
filldisk(){
DISKNUM=$2
if [[ ! $2 =~ [0-9] ]]; then echo must specify disk num as 2nd arg;return 1;fi
SKIP="${3:-0}"
BS="${4:-4}"
SIZE=$(( (2 * 1024 *1024) - ($SKIP * 1024) ))
gnumfmt --format=%.3f --to=iec --from=iec ${SIZE}M\
case $1 in
random)
@joeljacobs
joeljacobs / Swarm docker ps format
Last active August 17, 2017 02:36
Ridiculous docker ps format for Swarm
docker ps --format 'table {{.ID}}|{{.Image}}|{{.Command}}|{{.RunningFor}}|{{.Status}}|{{.Ports}}|{{.Names}}'|sed -e 's/dev\.perfectpitchtech\.com:4567\/service\///' -e 's/\(^.*|.*|.*|.*|.*|\)\(.*\)\(|[^|]*$\)/\1+\2+\3/' -e 's/\(\|[a-z0-9]\{3\}[^\.]+\)\(\.[^|]\{4\}\)[^|]*$/\1\2\.\.\./'|(while read jerk; do ports=$(echo "$jerk"|sed 's/\(^.*+\)\(.*\)\(+.*$\)/\2/');newports=$(echo $ports|sed -e 's/\/[ut][dc]p\(,\)* */\1/g'|cut -c 1-12); echo $jerk|sed "s/+.*+/${newports}.../"; done)|column -tns "|"
# du with only 1 filesystem
du -achxd1 |sort -h
# Ubuntu14 Service Management
update-rc.d -f <service> remove
service --status-all
@joeljacobs
joeljacobs / puppet_notes.txt
Last active May 4, 2017 23:34
Puppet Zero Padding sprintf each split match
#$pp_num_raw = split($::hostname, 'pp')[1]
#$pp_num = sprintf("%0#2i", $pp_num_raw)
#$pp_num = split($::hostname, 'pp')[1].sprintf"%0#2i"
#$pp_num = sprintf("%0#2i", "${::hostname}".split('pp')[1])
$pp_num = sprintf("%0#2i", "${::hostname}".match(/(pp)([0-9]+)([^[0-9]]*)/)[2])
["api", "live", "upload"].each|$local_suffix|{
file { "/etc/nginx/conf.d/ppcc.local.$local_suffix":
content => template("pp_nginx_manager/conf.d/ppcc.local.${local_suffix}.erb"),
ensure => present,
}