Skip to content

Instantly share code, notes, and snippets.

@glyphobet
glyphobet / immutabledict.py
Created May 13, 2012 10:52
Immutable dictionary in Python
class ImmutableDict(dict):
def __setitem__(self, key, value):
raise TypeError("%r object does not support item assignment" % type(self).__name__)
def __delitem__(self, key):
raise TypeError("%r object does not support item deletion" % type(self).__name__)
def __getattribute__(self, attribute):
if attribute in ('clear', 'update', 'pop', 'popitem', 'setdefault'):
raise AttributeError("%r object has no attribute %r" % (type(self).__name__, attribute))
#!/usr/bin/env bash
# Recommended sort: -k2,2 -k1,1
REMOTE='origin'
BRANCHES=$(git branch -r | grep $REMOTE | grep -v 'HEAD -> ')
for BRANCH in $BRANCHES ; do
git log -n 1 --pretty="%C(yellow)%ci%Creset %x00 %C(cyan)%an%Creset %x00 %C(blue)<%ae>%Creset %x00 %Cred${BRANCH:7}%Creset" $BRANCH
done | sort -t '\0' $@
echo `echo $BRANCHES | wc -w` "remote ($REMOTE) branches found."
First shalt thou take out the Holy Space Bar, then shalt thou count
to four, no more, no less. Four shall be the number thou shalt count,
and the number of the counting shall be four. Five shalt thou not count,
neither count thou three, excepting that thou then proceed to four.
Tabs are right out. Once the number four, being the fourth number, be
reached, then typest thou thy Holy Source Line of Code towards thy
editor, which being syntactical in My sight, shall execute.
# Like this:
def function(
arg, kurz="klein",
really_long_argument_name="really long default value",
):
my_result = do_something(
# multiple short arguments on the same line are ok
arg, kurz=kurz,
really_long_argument_name=do_something_else(
one,
@glyphobet
glyphobet / pip.txt
Last active December 19, 2015 11:58
Nobody installs the Spanish Inquisition.
First shalt thou take out the Holy Virtualenv. Then, shalt thou
install using pip, no more, no less. pip shall be the installer
that thou shalt run. easy_install shalt thou not, nor either shalt
thou setup.py install, excepting that thou run setup.py via pip.
Sudo is right out. Once pip, being the installer you used, be used,
then installest thou thy Holy Package of Python Module towards
thine Virtualenv, which, being an .egg in my sight, shall install.
@glyphobet
glyphobet / muni.txt
Last active December 19, 2015 11:58
The MUNI prayer
Punctual MUNI, which art in transit,
Punctual be thy name.
Thy arrival come.
Thy will be done, in Noe,
As it is in Dogpatch.
Give us this day our daily transfer.
And forgive us our fare evasions,
As we forgive them that do not know to step down.
And lead us not into Hunter's Point,
But deliver us from our stop.
@glyphobet
glyphobet / size.py
Last active December 15, 2015 12:49
Sort size letters like XS, S, M, L, XL, LL, XXL
def size_cmp(sizea, sizeb):
return cmp(size_value(sizea), size_value(sizeb))
def size_value(size):
size = size.upper()
return (size.count('L') - size.count('S')) * (size.count('X') + 1)
@glyphobet
glyphobet / post-checkout.sh
Last active December 12, 2015 10:09
self-installing git-hook to remove stale *.pyc files and empty directories when switching branches.
#!/bin/bash
mybasename=`basename $0`
if [ ! -e .git/hooks/${mybasename} ] ; then
ln -s ../../git-hooks/${mybasename} .git/hooks/${mybasename}
fi
if [ $3 ] && [ $3 -eq '1' ] ; then
# Start from the repository root.
pushd ./$(git rev-parse --show-cdup) > /dev/null
@glyphobet
glyphobet / engineering_guidelines.md
Last active December 11, 2015 15:38
Technical Maxims
@glyphobet
glyphobet / gist:4175875
Created November 30, 2012 14:00
Arrrgh git
$ git pull
remote: Counting objects: 36, done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 27 (delta 19), reused 20 (delta 12)
Unpacking objects: 100% (27/27), done.
Von github.com:glyphobet/myproject
581f38f..a83e75b mybranch -> origin/mybranch
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details