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 | |
assert int(True) == 1 and int(False) == 0 | |
# Who knew that __bulitins__ was a different object depending on whether you | |
# run a module directly or import it into another module? | |
if isinstance(__builtins__, types.ModuleType): | |
__builtins__.True, __builtins__.False = False, True | |
else: | |
__builtins__['True'], __builtins__['False'] = False, True |
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
prompt_in1 '>>> ' | |
prompt_in2 '... ' | |
prompt_out '' | |
prompts_pad_left 0 | |
nosep 1 | |
confirm_exit 0 | |
banner 0 | |
pprint 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
def run_proc(cmd, stdin=None, env=None): | |
"""Runs the given cmd as a subprocess, where cmd is a list suitable | |
for passing to subprocess.call. Returns a 3-tuple of | |
(exit code, stdout, stderr) | |
If stdin is not None, it will be passed into the subprocess on STDIN. If | |
env is not None, it will be used to augment the environment of the | |
subprocess. | |
""" |
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
Compiling <LessCompiler src:../bitly2/templates/beta_sign_up_sign_in.html assets:1> | |
Inlined asset duplicated 2x: /s/beta/graphics/homepage/bubbles-2.png | |
Inlined asset duplicated 7x: /s/beta/graphics/homepage/top.png | |
Inlined asset duplicated 2x: /s/beta/graphics/homepage/seaweed.png | |
Compiling <LessCompiler src:../bitly2/templates/hamburger_base.html assets:1> | |
Inlined asset duplicated 2x: /s/beta/graphics/fs_littlefb_bblue.png | |
Inlined asset duplicated 2x: /s/beta/graphics/fs_big_blue_spinner.gif | |
Inlined asset duplicated 2x: /s/beta/graphics/vis/archive-big.png | |
Inlined asset duplicated 2x: /s/beta/graphics/vis/x-yellow.png |
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
A A---B | |
| \ \ | | |
| \ \ | | |
B---C C | |
B---C C | |
| / / | | |
| / / | | |
A A---B |
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 random | |
import types | |
# Two ways to create "bound" methods from plain functions | |
def bind(instance, f): | |
"""Bind function f to the given instance.""" | |
return lambda *args, **kwargs: f(instance, *args, **kwargs) | |
def make_method(instance, 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
#!/bin/sh | |
app=$1 | |
shift; | |
open -a $app $@ |
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
#!/bin/sh | |
set -e | |
ssh mccutchen@$(remote_host) pbcopy |
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 mock_async_func(func, data): | |
"""The challenge: Mock an "async" function (ie, a function that takes a | |
callback arg that it calls with its result instead of returning it) | |
without needing to manually duplicate (and maintain) the original | |
function's signature. | |
Given this original function: | |
def get_page(url, callback): | |
libbitly.async_http.http_fetch(url, callback=callback) |
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 gen_batches(xs, size, overlap=0): | |
"""Given a sequence xs and a batch size, yield batches from the sequence as | |
lists of length size, where the last batch might be smaller than the | |
rest. | |
An optional overlap amount may be given as a float specifying a percentage | |
of the batch size or as an int specifying the number of items to overlap. | |
""" | |
assert size > 0 | |
if isinstance(overlap, float): |