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
try: | |
import builtins | |
except ImportError: | |
# PY2 compat | |
import __builtin__ as builtins | |
import re | |
import math | |
from functools import partial |
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
# "Of being lazy" February 2, 2013 by Paul Masurel | |
# http://fulmicoton.com/posts/lazy/ | |
class LazyObject(object): | |
__slots__ = [ "_recipe", "_result", "_evaluated" ] | |
def __init__(self, recipe): | |
object.__setattr__(self, "_recipe", recipe) | |
object.__setattr__(self, "_result", None) |
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 | |
"""Electrum Wallet Seed Generator (use at own risk). | |
Usage: | |
-h --help | |
-s --seed-bits=<bits> Size of the wallet seed in bits | |
[default: 256] | |
-i --iterations=<iterations> Number of pbkdf2 iterations | |
[default: 500000] |
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 eval_sexpr(sexpr): | |
fn = sexpr[0] | |
args = sexpr[1:] | |
args = tuple(eval_sexpr(e) if isinstance(e, tuple) else e for e in args) | |
return fn(*args) | |
import operator as op | |
eval_sexpr((op.add, (op.mul, 3, 4), (op.mul, 2, 5))) |
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 codecs | |
from os.path import getmtime | |
from time import time | |
class FreshFile(object): | |
def __init__(self, filename, mode='r', encoding='utf-8', process_func=None, | |
max_age=0): | |
self._filename = filename |
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 random import randint | |
class REDict(dict): | |
def __init__(self, maxsize, *args, **kwargs): | |
self._maxsize = maxsize | |
self._keys = [] | |
self._evict_cb = kwargs.pop('_evict_cb', None) | |
dict.__init__(self, *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
class Memoizer(object): | |
"""Memoizer for pure functions with positional hashable arguments. | |
Eviction from cache is done more or less at random, which | |
in practice is surprisingly close to a LRU strategy. | |
""" | |
def __init__(self, func, maxsize=10000): | |
self.func = func | |
self.maxsize = maxsize |
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 os | |
def filepaths(rootdir, ext_filter=None): | |
if isinstance(ext_filter, basestring): | |
_filter = lambda p: p.endswith(ext_filter) | |
elif isinstance(ext_filter, tuple): | |
_filter = lambda p: os.path.splitext(p)[1] in ext_filter | |
else: | |
_filter = ext_filter |
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
/* KSON: Keyless Schemafied Object Notation | |
* | |
* Version: 0.1 Alpha | |
* | |
* A serialization format with two goals in mind: | |
* 1. Easily parsable using minimal javascript. | |
* 2. Reduce serialized size compared to JSON. | |
* | |
* 1. is accomplished by using the (comparativly fast) JSON parse/stringify | |
* functions, thus reducing the task of KSON to packing/unpacking the values |
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
イërnâ七iônàنلzætiøn |