This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in *.svg; do inkscape -f "$i" -e "$i.png"; done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dateutil import parser | |
from datetime import timedelta | |
date = "Mar 11th 2013" | |
def addweeks(date,week=0): | |
x = parser.parse(date) | |
new = x + timedelta(weeks=week) | |
return(new.strftime("%b %d %Y")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division | |
from functools import partial | |
def nonemptykeypct(x): | |
""" | |
Returns the percentage of keys that have non-null values in an object (as decimal). | |
Usage: | |
>>> x = {'a': 'meow', 'b': {'c': 'asd'}, 'd': [{'e': 'stuff', 'f': 1}, {'e': 'more stuff', 'f': 2}], 'g': ''} | |
>>> nonemptykeypct(x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def listNkeys(obj, prefix=''): | |
""" | |
This lets you list ALL the keys of large nested dictionaries a la mongodb documents. | |
from: http://stackoverflow.com/questions/17952981/return-a-list-of-all-variable-names-in-a-python-nested-dict-json-document-in-dot | |
Usage: | |
>>> x = { | |
'a': 'meow', | |
'b': { | |
'c': 'asd' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def unique(x): | |
return(list(set(x))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
ARTS = ['dance','photography','art therapy'] | |
def string_found(string1, string2): | |
if re.search(r"\b" + re.escape(string1) + r"\b", string2): | |
return 1 | |
return 0 | |
def string_count(string1, string2): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ eval "$(ssh-agent)" | |
$ ssh-add ~/.ssh/id_rsa |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find . -type f -exec grep -l "wordofinterest" {} + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from multiprocessing import Pool | |
from functools import partial | |
x = [1,2,3] | |
y = 10 | |
# NOTE, f CANNOT be a lambda function: http://stackoverflow.com/questions/17657571/python-multiprocessing-map-function-error | |
def f(x,y): | |
return(x**2+y) | |
# ordinary map works: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://feldboris.alwaysdata.net/blog/python-trick-how-to-flatten-dictionaries-values-composed-of-iterables.html | |
from itertools import chain | |
def flatten_dict_values(dictionary): | |
return chain(*dictionary.values()) |