Skip to content

Instantly share code, notes, and snippets.


Chris Van Horne cwvh

  • Seattle, WA, USA
View GitHub Profile
#!/usr/bin/env python
# Copyright 2009 Chris Van Horne
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
from django.contrib import admin
from foobar import models
class CommonSearchCriteria(admin.ModelAdmin):
search_fields = ('title',)
class AdvancedOptions(admin.ModelAdmin):
fieldsets = (
('Advanced options', {
'classes': ('collapse',),
View gist:268448
(setq frame-title-format (concat "%b - emacs@" system-name))
(setq inhibit-startup-screen t)
(setq make-backup-files nil)
(setq require-final-newline t)
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t)
(fset 'yes-or-no-p 'y-or-n-p)
(setq-default indent-tabs-mode nil)
View gist:519799
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
/* IEEE-754 values taken from page 2 of:
* "Introduction to Floating point calculations and IEEE 754 standard"
* Jamil Khatib, August 10, 2000
typedef uint32_t uint;
cwvh /
Created Dec 1, 2011
Take a list of PIL-supported images and turn them into a gif meme.
# -*- coding: utf-8 -*-
# Copyright (c) 2010, Almar Klein, Ant1, Marius van Voorden
# This code is subject to the (new) BSD license:
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
cwvh / scopelift.rb
Created Dec 2, 2011
The Hoarder Pattern: beautiful on the outside, dead kittens on the inside. Thanks Sinatra!
View scopelift.rb
## Making kick-ass global objects for fun-and-profit DSLs.
module ScopeLifting
class Application
attr_accessor :options
def initialize
@options =
cwvh /
Created Dec 9, 2011
Clean code with better named captures.
"""`namedmatch` mimics `re.match` but also creates attributes based on the
values of the named captures.
>>> string = 'foo bar baz'
>>> match = namedmatch(r'(?P<start>\w+) (?P<end>\w+)', string)
>>> print match.start
>>> print match.end
cwvh /
Created Dec 9, 2011
Example of asymmetric and symmetric multimethods.
from mm import multimethod, symmultimethod
class Ship(object):
def __init__(self, name): = name
def __str__(self):
class Asteroid(object):
def __init__(self, name):
cwvh /
Created Dec 9, 2011
Simple counting bloom filter in Python.
def hashfn(item):
h = hash(item)
return (1 << (h%64)) | (1 << (h/64%64))
def mask(val):
return bin(hashfn(val))[2:]
class CountingBloom(object):
def __init__(self):
self.items = [0] * 64
cwvh /
Created Dec 10, 2011
Simple parsing with pretty decorators.
import os
import re
class Env(object):
"""Maintains the environment variables for local and global scope."""
def __init__(self, env={}, parent=os.environ):
self.env = env.copy()
self.parent = parent.copy()