Skip to content

Instantly share code, notes, and snippets.

View dcolish's full-sized avatar

Dan dcolish

View GitHub Profile
@dcolish
dcolish / fun_with.py
Created December 30, 2010 19:07
I really wanted to show how much you can abuse a language even if the designers try to stop you.
class FooManager(object):
def __init__(self, data, trys_left=3):
self.data = data
self.trys_left = trys_left
def __enter__(self):
return self
def badfunc(self):
@dcolish
dcolish / vcs.sh
Created January 6, 2011 00:05
If you use HG or GIT, now you dont need to remember type of repo you're in
function selectvcs() {
case `stat -qn -f "%N" $1/.{git,hg}` in
*.git) echo "git" ;;
*.hg) echo "hg" ;;
//./) exit -1 ;;
*) $(selectvcs "`dirname ${1}`") ;;
esac
}
$(selectvcs $PWD) $@
@dcolish
dcolish / AstCheck.py
Created January 7, 2011 15:23
Check a Python AST for a few issues I'd like to avoid
from ast import Name, NodeTransformer, parse, Return
from itertools import chain
import sys
from warnings import warn
class StaticTransformer(NodeTransformer):
def _check_none(self, x):
if isinstance(x, Name) and x.id == 'None':
@dcolish
dcolish / pypy-bouncer.py
Created February 22, 2011 03:51
Url bouncer for redirecting svn urls to bitbucket
from urlparse import urljoin
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util, WSGIApplication
class Bouncer(webapp.RequestHandler):
def __init__(self, mapping=()):
super(Bouncer, self).__init__(self)
@dcolish
dcolish / Makefile
Created April 30, 2011 17:55
Makefile for buildling xapian ocaml bindings
SWIG=../../swig/preinst-swig
INCLUDE=-I. -I./../generic $(shell xapian-config --cxxflags)
LINK=$(shell xapian-config --libs)
all: static
static: libs
ocamlc -pp "camlp4o ./swigp4.cmo" -c smoketest.ml
ocamlfind ocamlc -g -ccopt -g -cclib \
-g -custom -o smoketest \
@dcolish
dcolish / simple.py
Created May 12, 2011 19:37
Simple printer of nester list printers
import xmlrpclib
client = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
packages = client.search({'summary': 'simple printer of nested lists'})
header = ''.join(['-'] * 80)
for package in packages:
print """{header}
{name} - {version}: {summary}""".format(header=header, **package)
print header
@dcolish
dcolish / migration.sh
Created June 8, 2011 23:10
Migrations done in bash
#!/bin/bash
RUN_SQL?="$(which psql) i3"
function _info(){
echo "At migration version: $(cat .migration-version)"
}
function _init() {
echo 0 > .migration-version
@dcolish
dcolish / cmdflow.py
Created June 21, 2011 19:51
Shell like command pipeline in python
from collections import namedtuple
from os import unlink
from os.path import join as pjoin
from subprocess import PIPE, Popen
class Path(object):
def __init__(self, pathname):
self.pathname = pathname
@dcolish
dcolish / bad.py
Created June 21, 2011 22:38
nasty badness
class Foo(object):
def __repr__(self):
return "<Silly Human, I'm not real>"
def __eq__(self, b):
return True
def __getattr__(self, meh):
return Foo()
@dcolish
dcolish / safeimport.py
Created September 10, 2011 03:21
Safe Importer for RTD
import imp
import sys
class ErrorlessImport(object):
def find_module(self, name, path):
try:
return imp.find_module(name, path)
except ImportError: