Skip to content

Instantly share code, notes, and snippets.

View luhn's full-sized avatar

Theron Luhn luhn

View GitHub Profile
@luhn
luhn / sqlalchemy.py
Created July 10, 2012 18:19
SQLAlchemy pool_recylce
sqlalchemy.create_engine(settings['db_url'], pool_recycle=14400)
@luhn
luhn / stats.py
Created May 9, 2012 23:50
CDF and PDF without SciPy
#Taken from http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.norm.html
def pdf(x):
"""Normal probably distribution function."""
return exp(-x**2/2)/sqrt(2*pi)
#Taken from http://stackoverflow.com/a/809402/600247
def erfcc(x):
"""Complementary error function."""
z = abs(x)
t = 1. / (1. + 0.5*z)
@luhn
luhn / comprehensions.py
Last active October 3, 2015 09:37
Python one-liner
>>> [ range(x*5, x*5+5) for x in range(5) ]
[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]
@luhn
luhn / gist:2381814
Created April 14, 2012 03:11
Generic Getters and Setters
class Foo(object):
def setter(var):
def set(self, value):
setattr(self, var, value+' unicorn')
return set
def getter(var):
def get(self):
return getattr(self, var)+' sasquatch'