Skip to content

Instantly share code, notes, and snippets.

@akheron
akheron / setup.py
Created March 5, 2014 14:00
Minimal Django logging setup that works with Gunicorn
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
}
@akheron
akheron / gist:9502209
Created March 12, 2014 07:09
du -h sorted by size
# From http://derblub.com/human-readable-and-by-size-sorted-disk-usage-in-bash
function duf {
du -sk "$@" | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done
}

Keybase proof

I hereby claim:

  • I am akheron on github.
  • I am akheron (https://keybase.io/akheron) on keybase.
  • I have a public key whose fingerprint is B5D6 953E 6D50 59ED 7ADA 0F2F D365 7D24 D058 434C

To claim this, I am signing this object:

@akheron
akheron / .tmux.conf
Last active August 29, 2015 14:20
My tmux config
# Keybindings
unbind C-b
set -g prefix C-z
bind z send-prefix
bind escape copy-mode
bind C-z last-window
bind p select-pane -t :.-1
bind n select-pane -t :.+1
@akheron
akheron / settings.py
Created September 28, 2009 09:58
Django settings and root urlconf wrapper for loading them outside PYTHONPATH
# Usage:
# Run the server like this (for example):
# DJANGO_SETTINGS_FILE=/path/to/settings.py ./manage runserver --settings=pythonpath.to.settings
# where pythonpath.to is the directory containing this file and is found in PYTHONPATH.
def load_settings():
import os
del globals()['load_settings']
path = os.environ.get('DJANGO_SETTINGS_FILE',
@akheron
akheron / generate-alter-tables.sql
Last active September 8, 2015 12:33
Change foreign key constraints to point to a different table
-- PostgreSQL
SELECT
'ALTER TABLE ' || source_tbl.relname || ' ' ||
'DROP CONSTRAINT '|| constr.conname ||'; ' ||
'ALTER TABLE ' || source_tbl.relname || ' ' ||
'ADD CONSTRAINT ' || constr.conname || ' ' ||
'FOREIGN KEY (' || source_col.attname || ') ' ||
'REFERENCES new_table_name (primary_key_name);'
FROM pg_constraint constr
INNER JOIN pg_class target_tbl ON constr.confrelid = target_tbl.oid
@akheron
akheron / activate-venv.sh
Last active September 19, 2015 04:40
Automatically activate Git projects' virtual environments
# Automatically activate Git projects' virtual environments based on the
# directory name of the project. Virtual environment name can be overridden
# by placing a .venv file in the project root with a virtualenv name in it
function workon_cwd {
# Check that this is a Git repo
GIT_DIR=`git rev-parse --git-dir 2> /dev/null`
if [ $? == 0 ]; then
# Find the repo root and check for virtualenv name override
GIT_DIR=`\cd $GIT_DIR; pwd`
PROJECT_ROOT=`dirname "$GIT_DIR"`
@akheron
akheron / gist:827408
Created February 15, 2011 11:12
Unit test helper for diffing Python data structures
def eq_diff(a, b):
import json, difflib
from datetime import datetime
if a == b:
return
class DatetimeEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, datetime):
@akheron
akheron / config
Created April 7, 2011 06:32
How to generate a stango website in git post-receive hook
# Git repository configuration for a detached worktree.
#
# Create a bare repository:
#
# $ git init --bare
#
# Then change the config to match this file.
[core]
repositoryformatversion = 0
@akheron
akheron / async_map.py
Created April 7, 2011 13:20
Asynchronous map for Tornado's ioloop
from tornado.ioloop import IOLoop
# Calls fn for all items of iterable, saves result to a list, and
# calls callback with that list. This is most useful when fn works
# asynchronously.
def async_map(fn, iterable, callback, io_loop=None):
ioloop = io_loop or IOLoop.instance()
def loop():
try: