Skip to content

Instantly share code, notes, and snippets.

@maplambda
maplambda / thrift.py
Created March 18, 2013 07:06
Hacker news search Python interface
import requests
import urllib
import json
def get(url, params):
print url, params
return json.loads(requests.get(url, params=params).text)
def iter_flatten(data):
@maplambda
maplambda / gist:3786956
Created September 26, 2012 09:15
clean string
import string
letters = frozenset("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "0123456789_")
def clean(seq): return filter(lambda x: x in letters, seq)
if __name__ == '__main__':
print clean("test!!!!")
print clean("1__^^^***test!!!!")
@maplambda
maplambda / gist:3596595
Created September 2, 2012 10:35
friendly-age.py
import math
import time
def get_universal_time():
return time.time()
def plural(n, word):
return word if n == 1 else word + "s"
age_units = [("year", 365.25 * 24 * 60 * 60),
(def rand-string (n)
(let c "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
(with (nc 62 s (newstring n) i 0)
(w/infile str "/dev/urandom"
(while (< i n)
(let x (readb str)
(unless (> x 247)
(= (s i) (c (mod x nc)))
(++ i)))))
s)))