Skip to content

Instantly share code, notes, and snippets.

@mtth
mtth / gist:9458430
Created March 10, 2014 02:17
Late variable binding in python
#!/usr/bin/env python
# encoding: utf-8
"""Testing late binding of variables."""
# last value of j is used everywhere
bars = [lambda i: j * i for j in range(5)]
assert all(b(1) == 4 for b in bars), "for lambda functions"
@mtth
mtth / gist:8637593
Created January 26, 2014 19:04
Python descriptors.
class Desc(object):
def __get__(self, obj, type=None):
return 'd'
def __set__(self, obj, value):
pass
class A(object):
pass
@mtth
mtth / sql2csv
Created September 26, 2013 06:09
Parse SQL dump into csv.
#!/usr/bin/env bash
# convert sql dumps to csv, tsv, ssv...
# also can filter fields using a sed pattern
# only works on linux
function usage
{
echo "usage: $0 [-sc CORES] [-o OUTFILE] [-p PATTERN] SQLFILE" 2>&1 && exit 1
}