Skip to content

Instantly share code, notes, and snippets.

@MichaelBlume
MichaelBlume / abkiller.user.js
Created April 9, 2011 05:55
kills the action bar on okcupid profiles
// ==UserScript==
// @name ABKiller
// @namespace http://www.github.com/MichaelBlume/
// @description Kill the action bar on OKCupid profiles
// @include http://www.okcupid.com/profile/*
// @include http://okcupid.com/profile/*
// ==/UserScript==
var action_bar = document.getElementById('action_bar');
action_bar.parentNode.removeChild(action_bar);
@MichaelBlume
MichaelBlume / Orphan a Commit
Created April 10, 2011 23:54
Script for orphaning a single commit. Useful in conjunction with .git/info/grafts
git filter-branch -f --parent-filter '
if [ "$GIT_COMMIT" = "SHA_GOES_HERE" ];
then
echo ''
else
read parents;
echo $parents;
fi' -- --all
@MichaelBlume
MichaelBlume / comitter rename
Created April 10, 2011 23:57
rename a comitter (works with AUTHOR in place of COMITTER, of course)
git filter-branch -f --commit-filter '
if [ "$GIT_COMMITTER_NAME" = "name" ];
then
GIT_COMMITTER_NAME="New Name";
GIT_COMMITTER_EMAIL="new@email.com.com";
git commit-tree "$@";
else
git commit-tree "$@";
fi' -- --all
@MichaelBlume
MichaelBlume / Lose SVN IDs
Created April 10, 2011 23:58
Strip off the SVN IDs appended by the git-svn-clone command
git filter-branch --msg-filter 'sed -e "/^git-svn-id:/d" ' -- --all
@MichaelBlume
MichaelBlume / git-aliases.bash
Created April 11, 2011 18:34
Some git-svn workflow stuff from my .bash_aliases, before our office switched to git and I switched to .gitconfig
alias g="git"
alias com="g commit"
alias add="g add"
alias dif="g diff"
alias res="g reset"
alias co="g checkout"
alias branch="g branch"
alias merge="g merge"
alias st="g status"
@MichaelBlume
MichaelBlume / gitconfig
Created April 12, 2011 17:51
my git config file
[advice]
# I know this stuff by now
pushNonFastForward = false
statusHints = false
[alias]
a = add
ai = add --interactive
ap = add --patch
b = branch
bl = blame
@MichaelBlume
MichaelBlume / deepdict.py
Created May 6, 2011 18:49
deepdict: quickly create highly nested dictionary structures without lots of initialization steps.
'''deepdict: quickly create highly nested dictionary structures without lots
of initialization steps.'''
from collections import defaultdict
class deepdict(defaultdict):
def __init__(self, *a, **kw):
defaultdict.__init__(self, deepdict, *a, **kw)
def __add__(self, num):
return num
@MichaelBlume
MichaelBlume / localdict.py
Created May 6, 2011 21:18
Localdict -- reduce your typing by half when constructing a dictionary literal from objects in the local context.
'''Localdict -- reduce your typing by half when constructing a dictionary
literal from objects in the local context.
params = {'foo': foo, 'bar': bar, 'baz': baz}
can be replaced ith
params = localdict('foo', 'bar', 'baz')
'''
@MichaelBlume
MichaelBlume / compose_defaults
Created May 23, 2012 18:05
The dumps param in simplejson.dumps is often helpful, but sometimes you want to quickly pass in multiple default actions. This should help.
def compose_defaults(*defaults):
'''I got annoyed that simplejson.dumps doesn't let you pass multiple
defaults. So here's this.'''
def new_default(obj):
for default in defaults:
try:
return default(obj)
except:
pass
raise TypeError("no default functions succeeded")
qualia = ("red", "blue", "cold", "pleasure")
memory_associations = { "red": ("anger", "hot")
, "blue": ("cold", "calm")
, "pleasure": ("hot", "good")
, "cold": ("blue", "calm")
}
def experience_qualia(in_qual):
for q in qualia:
if in_qual == q: