Skip to content

Instantly share code, notes, and snippets.

View hkupty's full-sized avatar

Henry John Kupty hkupty

View GitHub Profile
@hkupty
hkupty / profile.py
Created August 20, 2014 12:41
Profiling Decorator
import cProfile
import pstats
def measure(func):
""" The decorator. """
def profiling(*args, **kwargs):
""" The profiler. """
prof = cProfile.Profile()
prof.enable()
@hkupty
hkupty / curry.py
Last active August 29, 2015 14:04
Currying python functions
from functools import partial
curry = lambda f, g: partial(
lambda F, G, *args, **kwargs: F(G(*args,**kwargs)),
f, g
)
@hkupty
hkupty / oneliner_querystring.py
Created March 25, 2014 20:29
Querystring from dict oneliner
lambda filters: "&".join(map(lambda kv: '%s=%s' % kv, filters.iteritems()))
@hkupty
hkupty / oneliner_dict.py
Created March 25, 2014 20:27
Dict intersection one-liner
# Get the intersected dict from x and y
lambda x,y: {i:x[i] for i in set(x.keys()) & set(y.keys())}
# Get from x only the keys in list y, assuming y is a list, tuple or set..
lambda x,y: {i:x[i] for i in set(x.keys()) & set(y)}