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 subprocess | |
import os | |
def play_waveform(form): | |
s = 'echo %s | sox -r 8000 -b 8 -c 1 -t raw -s - -d' % form | |
print s | |
os.system(s) | |
#p = subprocess.Popen(['sox', '-r', '8000', '-b', '8', '-c', '1', '-t', 'raw', '-s', '-', '-d'], stdin=subprocess.PIPE) |
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 gc | |
class Foo(object): | |
"""Object which appears to take the name of the first reference name | |
>>> Foo().name | |
>>> f = Foo() | |
>>> f.name | |
'f' | |
>>> g = f |
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
prices = {'lollipop': 200} | |
candies = 100 | |
xp = 100 | |
has_map = False | |
def needs_map(func): | |
def new_func(): |
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
def by_token(fileobj): | |
for line in fileobj: | |
for token in line.split(): | |
yield token | |
import os | |
def open_file(func): | |
def newfunc(filename): |
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 sys | |
import tty | |
import Queue | |
import threading | |
import time | |
tty.setcbreak(sys.stdin) | |
events = Queue.Queue() |
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 numpy | |
#TODO do something cooler and more robust like | |
#http://stackoverflow.com/a/9059858/398212 | |
class AutoExtending(object): | |
"""Numpy array wrapper that automatically extends rows down | |
>>> a = AutoExtending(10, 14) | |
>>> a.shape |
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
"""Another way of formatting text: 2d char array and 3d formatting array""" | |
ON_GREY = 40 | |
ON_RED = 41 | |
ON_GREEN = 42 | |
ON_YELLOW = 43 | |
ON_BLUE = 44 | |
ON_MAGENTA = 45 | |
ON_CYAN = 46 | |
ON_WHITE = 47 |
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
"""implementations of readline control sequences to do with history | |
Implementing these similar to how they're done in bpython: | |
* never modifying previous history entries | |
* always appending the executed line | |
in the order of description at http://www.bigsmoke.us/readline/shortcuts | |
""" | |
import logging |
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 pickle | |
import glob | |
cache = {} | |
def fib(x): | |
if x in cache: | |
return cache[x] | |
if x < 2: return 1 |
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 ProxiedGetitem(object): | |
"""Dictionary whose keys are 2-element tuples; if one element tuple used, | |
the __getitem__ method is curried | |
>>> d = ProxiedGetitem() | |
>>> d # doctest: +ELLIPSIS | |
<__main__.ProxiedGetitem object at 0x...> | |
>>> d[1,2] = 'a' | |
>>> d[1,2] | |
'a' |