Skip to content

Instantly share code, notes, and snippets.

@michaelhood
michaelhood / ec2-ssh-instance.sh
Created September 22, 2012 04:05
EC2 SSH-by-Instance-ID
# ssh $(ec2ip i-a1b2c3d)
function ec2ip() { if [ "$#" -gt 0 ]; then ip=$(ec2din --show-empty-fields -H $1 | grep "^INST" | cut -f17); echo $ip; fi }
function ec2pip() { if [ "$#" -gt 0 ]; then ip=$(ec2din --show-empty-fields -H $1 | grep "^INST" | cut -f18); echo $ip; fi }
function ec2host() { if [ "$#" -gt 0 ]; then ip=$(ec2din --show-empty-fields -H $1 | grep "^INST" | cut -f4); echo $ip; fi }
# ec2ssh i-a1b2c3d
function ec2ssh() { if [ "$#" -gt 0 ]; then ip=$(ec2din --show-empty-fields -H $1 | grep "^INST" | cut -f4); echo $ip; ssh $ip; fi }
@michaelhood
michaelhood / gist:3892179
Created October 15, 2012 12:21
dtruss "drop" privileges
mh@mbp:~% sudo dtruss -f sudo -u\#$UID whoami 2>/dev/null
mh
mh@mbp:~% sudo dtruss -f -t fakesyscall sudo -u\#$UID touch /
PID/THRD SYSCALL(args) = return
28082/0xad253: fork() = 0 0
touch: setting times of ‘/’: Permission denied
mh@mbp:~% # note that i only used these methods to hide output
mh@mbp:~% # to keep the demo short. dtruss is functional.
@michaelhood
michaelhood / gist:4412203
Created December 30, 2012 11:01
git patches for a pull request
for c in $(curl -su michaelhood:$ppp https://api.github.com/repos/github/developer.github.com/pulls/183/commits | fgrep "git/commits" | sed "s/\/git\//\//g" | awk '{print $NF;}' | tr -d \",); do echo "\n### START: $c ###\n\n"; curl -u michaelhood:$ppp -H "Accept: application/vnd.github.beta.diff" $c; done
@michaelhood
michaelhood / onload-network-graph-fix.js
Last active December 10, 2015 15:08
fix github network graph for chrome retina
/*
MIT: https://raw.github.com/github/hubot/1455b62e5b6daffeacb7472db83ccf6502396bea/LICENSE.md
refs:
http://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/HTML-canvas-guide/SettingUptheCanvas/SettingUptheCanvas.html
http://www.html5rocks.com/en/tutorials/canvas/hidpi/
https://code.google.com/p/chromium/issues/detail?id=127852 (WONTFIX)
*/
(function(doc) {
@michaelhood
michaelhood / repro.md
Last active December 11, 2015 01:19
GFM has undocumented difference in hN parsing

GFM requires space between # and string to create an hN.

% curl -d '{"text": "#asdf", "mode": "gfm"}' https://api.github.com/markdown
<p>#asdf</p>

% curl -d '{"text": "# asdf", "mode": "gfm"}' https://api.github.com/markdown
<h1>asdf</h1>

markdown doesn't.

@michaelhood
michaelhood / mdbrowser.sh
Last active December 11, 2015 01:58
markdown to browser demo (via github api)
#!/usr/bin/env bash
echo "# sup markdown" > sup.md
cat sup.md | { _t=$(mktemp --suffix=\.html); curl -s -H "Content-type: text/plain" -d @/dev/stdin https://api.github.com/markdown/raw > $_t ; open $_t ; rm -f $_t; }
@michaelhood
michaelhood / clone-in-mac-git-not-https.js
Last active December 11, 2015 08:58
make 'clone in mac' links on github use git:// not https://
(function(doc) {
$("#repo_details div.url-box ul.native-clones li a span.mini-icon-apple").
parent().
attr('href', function(i,v) { return v.replace(/https:\/\//, "git://"); });
}(document));
@michaelhood
michaelhood / 00-github-app-tabspacing.md
Last active December 11, 2015 18:28
github.app tabspacing

tabspacing in github.app's changes view is broken.

if you have characters fully leading up to an exact tabstop (8, in the app), an additional tab should be created:

this is a correct diff of adding the attached badger2.txt:

@@ -0,0 +0,1 @@
+ abcdef  hi
  # ---^
 col 8
@michaelhood
michaelhood / github-bigquery.sql
Last active December 12, 2015 05:38
regexp match leaderboard bigquery for githubarchive
SELECT repository_url, repository_description, COUNT(*) AS c
FROM [githubarchive:github.timeline]
WHERE REGEXP_MATCH(repository_name, r'github([^\.]|$)')
GROUP BY repository_url, repository_description
ORDER BY c DESC
LIMIT 100
#!/usr/bin/env bash
trap outdirty SIGINT SIGTERM
function out() {
echo "out, cleaning up"
}
function outgood() {
echo "success"