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 | |
def timer(): | |
start = time.time() | |
return lambda: time.time() - start | |
def timed(callback=None): | |
if callback is None: | |
callback = lambda *a, **kw: None | |
def wrapper(func): | |
def wrapped_call(*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
binary_operator_str = """ | |
def __{name}__(self, obj): | |
gen = lambda: (item {op} obj for obj in self) | |
return _proxy(gen) | |
#return GroupProxy([item {op} obj for item in self]) | |
def __r{name}__(self, obj): | |
gen = lambda: (obj {op} item for obj in self) | |
return _proxy(gen) | |
#return GroupProxy([obj {op} item for item in self]) |
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 re | |
import collections | |
CHANNELS = 'rgba' | |
DEFAULT_COLORS = [0, 0, 0, 255] | |
CHANNEL_SEARCH = re.compile('[^' + CHANNELS + ']').search | |
IS_MULTI_CHANNEL = lambda name: name and not bool(CHANNEL_SEARCH(name)) | |
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 wraps | |
class Factory(object): | |
def __init__(self, cls, *args, **kwargs): | |
self._cls = cls | |
self._args = args | |
self._kwargs = kwargs | |
@property | |
def instance(self): | |
return self._cls(*(self._args), **(self._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 functools import wraps | |
import collections | |
import bitstring | |
noop_init = lambda *a, **kw: None | |
passthrough = lambda v: v | |
def flatten(l, ltypes=collections.Sequence): |
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 types | |
import six | |
import sys | |
def handler(func): | |
''' | |
Decorator for creating handlers out of generator functions | |
Similar in usage to the @contextmanager decorator | |
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
public interface Poolable<E> { | |
E getNext(); | |
void setNext(E next); | |
boolean isActive(); | |
E reset(); | |
} | |
public enum PoolBehavior { | |
EXPAND, | |
DESTROY, |
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
public class RollingAverage { | |
private float resolution; | |
private float remainderDt; | |
private float remainder; | |
private float[] samples; | |
private int nsamples; | |
private int oldest; |
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
''' | |
Character substitution | |
==== | |
Not handled at all. Should be reasonably straightforward to plug into the existing code. | |
Roughly: | |
def expand_substitutions(wordlist, sub_map): | |
for word in wordlist: | |
for substitution in expand_word(word, sub_map): | |
yield substitution |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset='utf-8' /> | |
</head> | |
<body> | |
<div>Type some stuff and click send (or hit enter)</div> | |
<input type='text' id='input' onkeyup="onKeyUp(event)" autofocus="autofocus"></input> | |
<button onclick='send_text()'>Send</button> | |
<div id='output'></div> |
OlderNewer