Skip to content

Instantly share code, notes, and snippets.

brainsik / gist:775788
Created January 12, 2011 06:43
Wolever, put this in your .ssh/config
Host foo
User blah
Port 42
brainsik / gist:971526
Created May 13, 2011 23:57
sudo -H for Fabric
import fabric.api
from contextlib import contextmanager
def shell(new_shell):
old_shell, =, new_shell
yield = old_shell
brainsik / gist:976895
Created May 17, 2011 17:20 — forked from mwhooker/gist:969121
ambient steampunk
good discussion at
some interesting first starts
your life will get very strange for a little while after clicking this link
brainsik / postactivate
Created June 5, 2011 20:42
Keep per virtualenv postactivate scripts in WORKON_HOME
# This hook is run after every virtualenv is activated.
script="$VIRTUALENVWRAPPER_HOOK_DIR/postactivate-"$(basename $VIRTUAL_ENV)
if [ -r $script ]; then
source $script
brainsik /
Created June 11, 2011 00:31
Override Python's dict with this for JS style dot notation access :-)
# encoding: utf-8
class DotDict(dict):
def __init__(self, *a, **kw):
dict.__init__(self, *a, **kw)
for key in self:
def _validate_key(self, key):
brainsik /
Created July 31, 2011 15:49
hack so mkvirtualenv uses a different interpreter
# create a temporary directory
mkdir tmp_python; cd tmp_python
# symlink "python" to the interpreter you want
ln -s `which python2.6` python
# have mkvirtualenv use the python symlink
PATH="$PWD:$PATH" mkvirtualenv py26party
# clean up
cd ..; rm -rf tmp_python
brainsik /
Created September 24, 2011 03:51
ANSI colored Python logging
import logging
from termcolor import colored
class ColorLog(object):
colormap = dict(
debug=dict(color='grey', attrs=['bold']),
warn=dict(color='yellow', attrs=['bold']),
brainsik / gist:4280136
Created December 13, 2012 21:31
A simple way for Python cron tasks to exit if another process is currently running. Does not use a pidfile.
import os
import subprocess
import shlex
def bail_if_another_is_running():
cmd = shlex.split("pgrep -u {} -f {}".format(os.getuid(), __file__))
pids = subprocess.check_output(cmd).strip().split('\n')
if len(pids) > 1:
brainsik /
Created October 31, 2013 21:15
Solves the "coding" challenge at
x=''; while :; do r=`curl -s -H "Accept: application/json" $x`; x=`echo $r | grep -E -o 'http[^"]+'`; if ! echo "$x" | grep -q http; then echo $r; break; fi; echo $x; done
brainsik /
Created November 14, 2013 22:21
Monocle Twisted Redis subscriber
# encoding: utf-8
import sys
import monocle
from monocle import _o
from monocle.stack import eventloop
import txredis.client
from twisted.internet import reactor, protocol