Skip to content

Instantly share code, notes, and snippets.

View gavinwahl's full-sized avatar

Gavin Wahl gavinwahl

  • Fusionbox
  • Colorado
View GitHub Profile
@gavinwahl
gavinwahl / gist:3768115
Created September 22, 2012 22:44
simple python-like expressions
import ast
import operator
ops = {
ast.Add: operator.add,
ast.Mult: operator.mul,
ast.Sub: operator.sub,
ast.Div: operator.truediv,
ast.FloorDiv: operator.floordiv,
@gavinwahl
gavinwahl / commit-msg
Created December 7, 2011 23:54
commit-msg hook that checks Verheoff checksums
#! /usr/bin/env python
# Verhoeff implementation from Hermann Himmelbauer,
# http://en.wikibooks.org/wiki/Algorithm_Implementation/Checksums/Verhoeff_Algorithm#Python
verhoeff_table_d = (
(0,1,2,3,4,5,6,7,8,9),
(1,2,3,4,0,6,7,8,9,5),
(2,3,4,0,1,7,8,9,5,6),
(3,4,0,1,2,8,9,5,6,7),
@gavinwahl
gavinwahl / tags.py
Created September 28, 2011 19:34
tmb and div nodes
from django import template
register = template.Library()
class ParseClassesNode(template.Node):
def parse_until(self, parser, token, end):
contents = token.split_contents()
self.classes = ' '.join(contents[1:])
self.nodelist = parser.parse((end,))
parser.delete_first_token()
@gavinwahl
gavinwahl / gist:1244417
Created September 27, 2011 05:43
relation algebra
(define (zip-cons a b)
(if (null? a)
'()
(cons (cons (car a) (car b))
(zip-cons (cdr a) (cdr b)))))
(define (p c r)
(cond
((null? c) (map (lambda (x) '()) r))
((eq? (car c) (caar r))
expand (Plus a) = foldr interleave [] $ do
match <- expand a
return $ match:(map (match++) (expand (Plus a)))
expand (Plus a) = (concat . ap (iterate . liftM2 (++) . expand) expand) a