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 typing import Callable | |
class A: pass | |
class B: pass | |
class C: pass | |
def composition(aToB: Callable[[A], B], | |
bToC: Callable[[B], C]) -> Callable[[A], C]: | |
"""Returns a callable that takes an A and returns a C""" |
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
a simple remix file format | |
Files are always UTF-8 | |
a syntax like | |
episode <episode query> of <podcast url> | |
play from <time> to <time> [at 2x speed] [at +12 dB] | |
example: |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
tomb@localhost:~$ strace python myPythonScript.py 2>&1 >/dev/null | grep open | grep -v ENOENT | grep -o '".*"' | grep -v '\.pyc' | |
"/etc/ld.so.cache" | |
"/lib/x86_64-linux-gnu/libpthread.so.0" | |
"/lib/x86_64-linux-gnu/libc.so.6" | |
"/lib/x86_64-linux-gnu/libdl.so.2" | |
"/lib/x86_64-linux-gnu/libutil.so.1" | |
"/lib/x86_64-linux-gnu/libz.so.1" | |
"/lib/x86_64-linux-gnu/libm.so.6" | |
"/usr/lib/python2.7/site.py" | |
"/usr/lib/python2.7/os.py" |
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 tty | |
import termios | |
import sys | |
class Cbreak(object): | |
def __enter__(self): | |
self.original_stty = termios.tcgetattr(sys.stdin) | |
tty.setcbreak(sys.stdin, termios.TCSANOW) |
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 socket | |
listener = socket.socket() | |
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
listener.bind(('', 8000)) | |
listener.listen(5) | |
while True: |
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 preview(content): | |
import webbrowser | |
import tempfile | |
import time | |
with tempfile.NamedTemporaryFile(suffix='.html') as f: | |
f.write(content) | |
f.flush() | |
print f.name | |
webbrowser.open_new_tab('file://'+f.name) | |
time.sleep(1) |
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 | |
def tokenize(s): | |
""" | |
>>> tokenize("(1.1 + 2 * 3)") | |
['(', '1.1', '+', '2', '*', '3', ')'] | |
""" | |
return re.findall("[0123456789.a-zA-Z]+|[*+/\-()=]", s) |
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 python2 | |
import sys | |
import urllib2 | |
import json | |
def do_gist_json(s): | |
""" Use json to post to github. """ | |
gist_public = False | |
gist_url = 'https://api.github.com/gists' |
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 random | |
def write_data(filename, num_bytes=1000000): | |
with open(filename, 'w') as f: | |
for _ in range((num_bytes / 1000) + 1): | |
f.write(''.join(random.choice('ab') for _ in range(1000))) | |
def read_chunks(filename, num_bytes=1000): | |
with open(filename, 'r') as f: | |
while True: |