This file contains 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
class JSONFileData(object): | |
def __init__(self, fd, split, num_samples=None): | |
assert sum(split.values()) == 1 | |
self.fd = fd | |
self.split = split | |
self.num_samples = num_samples | |
self._parse_lines() | |
def _parse_lines(self): | |
if self.num_samples is None: |
This file contains 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 time | |
import contextlib | |
import inspect | |
_DEBUG = False | |
@contextlib.contextmanager | |
def Timer(name, debug=_DEBUG): | |
if not debug: |
This file contains 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
#!/usr/bin/env python2.7 | |
""" | |
Scrape thesession.org for all the yummy ABC files | |
""" | |
import os | |
import itertools as IT | |
from collections import deque | |
from operator import itemgetter | |
from urlparse import urljoin |
This file contains 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
#!/usr/bin/env python2.7 | |
""" | |
>>> import multigram_search | |
>>> mgs = multigram_search.MultigramSearch([("a", "b", "c"), ("o", "c", "z"), | |
('z','y')]) | |
>>> list(mgs.intersection("hello world you a b c foo".split(" "))) | |
[['a', 'b', 'c']] |
This file contains 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
$ # Fails on port 80 | |
$ curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: XXX.fastforwardlabs.com" -H "Origin: http://XXX.fastforwardlabs.com" http://XXX.fastforwardlabs.com/XXXX | |
HTTP/1.1 400 Bad Request | |
Server: nginx/1.4.6 (Ubuntu) | |
Date: Mon, 20 Oct 2014 23:22:48 GMT | |
Content-Type: text/html; charset=UTF-8 | |
Content-Length: 34 | |
Can "Upgrade" only to "WebSocket". |
This file contains 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
[ | |
{ | |
"name": "Lower East Side", | |
"center": [ | |
-73.9836180698, | |
40.7155233255 | |
] | |
}, | |
{ | |
"name": "Marble Hill", |
This file contains 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
# Why does this work | |
def split_chars(words, chars): | |
itr = (words,) | |
for c in chars: | |
itr = tuple(chunk for word in itr for chunk in word.split(c)) | |
return list(itr) | |
# but this not work | |
def split_chars_broken(words, chars): | |
itr = (words,) |
This file contains 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 functools import total_ordering | |
@total_ordering | |
class SuperNone(object): | |
# general properties / methods | |
def __getattr__(self, *args, **kwargs): | |
return self | |
def __call__(self, *args, **kwargs): | |
return self | |
def __setattr__(self, *args, **kwargs): |
This file contains 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 collections import OrderedDict | |
class S4LRU(object): | |
""" | |
Short and Simple [S4LRU][1]cache. Implemented by Micha Gorelick | |
(http://github.com/mynameisfiber) and released under the do whatever you | |
want license. | |
[1] http://www.cs.cornell.edu/~qhuang/papers/sosp_fbanalysis.pdf | |
""" |