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
#!/usr/bin/env python | |
import copy | |
import random | |
import functools | |
def memoize(fn): | |
memo = {} | |
@functools.wraps(fn) | |
def _wrapper(*args): |
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
#!/usr/bin/env python | |
import os | |
import json | |
import sqlite3 | |
import argparse | |
from collections import namedtuple, OrderedDict | |
from operator import attrgetter | |
from StringIO import StringIO |
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 example(): | |
... return 1, 2, 3 | |
... | |
>>> example() | |
(1, 2, 3) | |
>>> a, b, c = example() | |
>>> a | |
1 | |
>>> b | |
2 |
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
class OTIPAddr < IPAddr | |
attr_reader :mask_addr | |
def prefix_len | |
@mask_addr.to_s(2).count "1" | |
end | |
end |
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 argparse | |
def main(): | |
parser = argparse.ArgumentParser("Do a thing with stuff!") | |
parser.add_argument("number", type=int) | |
args = parser.parse_args() | |
print "nan" * args.number + " batman!" |
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 | |
import operator | |
import curator | |
import elasticsearch | |
class IndexFilter(object): | |
def __init__(self, | |
time_format="%Y.%m.%d", |
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
class Enumerable(object): | |
def map(self, fn): | |
acc = [] | |
self.each(lambda xs: acc.append(fn(xs))) | |
return self.__class__(acc) | |
collect = map | |
def filter(self, pred): | |
acc = [] |
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 print_function | |
import time | |
import functools | |
import contextlib | |
LOG_FMT = "{name}: {cp} @{total:0.4f}s ({dur:0.4f}s since {prev})" | |
def coroutine(f): | |
@functools.wraps(f) | |
def coro(*args, **kwargs): |
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 copy | |
class ReducedException(Exception): | |
def __init__(self, reduced_value): | |
super(ReducedException, self).__init__() | |
self.reduced_value = reduced_value | |
def conj(coll, *es): | |
"""Conjoin elements to coll. Works correctly for most collection types""" |
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 print_function | |
import time | |
import contextlib | |
def format_checkpoints(cps): | |
pairs = [cps[i:i+2] for i in range(len(cps)-1)] | |
fmts = ["{0[0]} to {1[0]} in {2:.04f}s".format(start, end, end[1] - start[1]) | |
for start, end in pairs] | |
return ", ".join(fmts) |