Skip to content

Instantly share code, notes, and snippets.

View philchristensen's full-sized avatar

Phil Christensen philchristensen

View GitHub Profile
@philchristensen
philchristensen / switch_idea.py
Created November 8, 2010 16:48
sketch idea for implementing case/switch with Python decorators
case_dict = {}
def case(key=None):
def case_builder(func):
case_dict[key] = func
return func
return case_builder
def switch(value):
return case_dict[value]
@philchristensen
philchristensen / git-prompt.bash
Created December 19, 2010 20:20
add current git branch to shell prompt
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "#"${ref#refs/heads/}
}
export PS1="\u@\h:\w\[\e[31;40m\]\$(parse_git_branch)\[\e[0m\] \$ "
@philchristensen
philchristensen / zappa-unix-names.md
Last active March 2, 2016 19:18
zappa-related unixlike names
stinkfoot
muffinman
grandwazoo
unclemeat
zombywoof
zootallures
lumpygravy
mudshark
jazzdischarge

partyhat

@philchristensen
philchristensen / karma.py
Created February 1, 2011 16:37
sketch of some karma calculation functions
import math
def get_confidence_interval(p, n, alpha=0.5):
assert p >= 0 and p <= 1
assert alpha > 0 and alpha < 1
z = pnorm(1-alpha/2)
return (p + (math.pow(z, 2)/(2*n)) - z * math.sqrt((p * (1 - p) + (math.pow(z, 2)/(4*n)))/n))
@philchristensen
philchristensen / svn-prompt.bash
Created February 16, 2011 15:29
add current svn branch to shell prompt
function parse_svn_branch {
if [ -d '.svn' ]; then
ref=$(svn info | grep URL | awk -F/ '{print $NF}' 2> /dev/null) || return
cur=$(pwd | awk -F/ '{print $NF}' 2> /dev/null) || return
if [ $ref != $cur ]; then
echo "#$ref"
fi
fi
}
@philchristensen
philchristensen / virtualenv-svn-git-prompt.bash
Created April 7, 2011 16:33
some useful functions and prompt configs for virtualenv-based development
function parse_svn_branch {
if [ -d '.svn' ]; then
ref=$(svn info | grep URL | awk -F/ '{print $NF}' 2> /dev/null) || return
cur=$(pwd | awk -F/ '{print $NF}' 2> /dev/null) || return
if [ $ref != $cur ]; then
echo -ne "\xE2\x9C\xB6${ref}"
fi
fi
}
@philchristensen
philchristensen / jargon-zork-unix-names.txt
Last active September 25, 2015 11:08
jargon- and zork-related unix names
foo
bar
baz
qux
quux
frobnitz
frob
frotz
frobnule
@philchristensen
philchristensen / twisted_django.py
Created July 10, 2011 20:17
bad idea for calling Twisted code from Django view
user_id = 2
def error(request, failure):
return 'error'
def parse(request):
def _response(r):
request.response = r
def _error(f):
r = error(request, f)
@philchristensen
philchristensen / bebop-cola
Created July 26, 2011 18:47
Bebop Cola flavors (unix machine names?)
Root Bird
Gilberto Grape
Artie Shawberry
Kiwi Holliday
Peachmo
John Cola-trane
Don Wild Cherry
Vince Guavaldi
Dave Bruberry
Cab Colaway