Skip to content

Instantly share code, notes, and snippets.

@John-K
John-K / gist:ab9c2e98936a22dcb71d
Created December 21, 2015 20:08
Add a drive to running KVM instance
drive_add 0:1:1 file=/dev/sdb,format=raw,if=none,id=newdisk
device_add virtio-blk-pci,drive=newdisk
@John-K
John-K / gist:7f1aa15205545437899f
Created September 21, 2015 12:51
Git cherry-pick foreign
git --git-dir=../<some_other_repo>/.git \
format-patch -k -1 --stdout <commit SHA> | \
git am -3 -k
@John-K
John-K / gist:6333786adbb6f1afca13
Created May 21, 2015 00:24
bash oneliner: kill caffeinate when battery < 10% and not on AC power
while true; do VAR=`pmset -g batt|tr -d "'%;"`; if [ `echo $VAR | awk '{print $4}'` == 'Battery' ]; then if [ `echo $VAR|awk '{print $7}'` -lt 100 ]; then echo "Killing caffeinate"; pkill caffeinate; fi; fi; sleep 2; done
@John-K
John-K / gist:050af4014c5bbf6fd812
Created March 17, 2015 08:49
Generating ECDSA CSR for Comodo PositiveSSL and loading into lighttpd
#generate ECDSA key using secp256r1 (or as openssl knows it, prime256v1)
#heed warnings about this curve: http://safecurves.cr.yp.to/
openssl ecparam -out kelley.ca_ec_key.pem -genkey -name prime256v1
#generate your CSR
#note: Comodo PositiveSSL will issue the cert both with and without www. automatically if you prepend www to your CN
openssl req -new -key kelley.ca_ec_key.pem-nodes -out www_kelley_ca.csr -keyout www_kelley_ca.key -subj "/C=US/ST=California/L=San Francisco/O=John Kelley/CN=www.kelley.ca"
#submit your CSR and follow instructions
@John-K
John-K / gist:0db3129a428c73f1004f
Created March 12, 2015 05:40
ssh_agent .bash_profile
#
# setup ssh-agent
#
# set environment variables if user's agent already exists
SSH_AUTH_SOCK=$(ls -l /tmp/ssh-*/agent.* 2> /dev/null | grep $(whoami) | awk '{print $9}')
SSH_AGENT_PID=$(echo $SSH_AUTH_SOCK | cut -d. -f2)
[ -n "$SSH_AUTH_SOCK" ] && export SSH_AUTH_SOCK
[ -n "$SSH_AGENT_PID" ] && export SSH_AGENT_PID
# Quick and dirty Apple HTTP Live Stream ripping to MP4
# John_K 9/9/2014
# First, grab the mov URL from the website using Web Inspector
$ curl http://p.events-delivery.apple.com.edgesuite.net/14pijnadfpvkjnfvpijhabdfvpijbadfv09/refs/14oijhbaefvohi9_sl_ref.mov
?moov?rmra?rmdazrdrfurl fhttp://p.events-delivery.apple.com.edgesuite.net/14pijnadfpvkjnfvpijhabdfvpijbadfv09/m3u8/sl_mvp.m3u8rmdr
# Then grab the playlist that's referred to in it
$ curl http://p.events-delivery.apple.com.edgesuite.net/14pijnadfpvkjnfvpijhabdfvpijbadfv09/m3u8/sl_mvp.m3u8
#EXTM3U
@John-K
John-K / git-author-rank
Last active October 4, 2015 07:18
One liner to show lines per committer in a git repo
git ls-tree --name-only -r `git branch|grep \*|awk '{print $2}'` | while read a; do git blame $a; done | perl -nle 'm/\(([A-Za-z ]+)/; $name = $1; $name =~ s/^\s+//; $name =~ s/\s+$//; print $name' | sort | uniq -c | sort -n