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
# report will be something like: | |
# | |
# { test_name: 'signup button', | |
# alternatives: ['Red', 'Green'], | |
# results: [ | |
# { attempted: 248, | |
# completed: 12 | |
# }, | |
# { | |
# attempted: 226, |
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 | |
from HTMLParser import HTMLParser | |
whitespace = re.compile('(\w+)') | |
class HTMLAbbrev(HTMLParser): | |
def __init__(self, maxlength, *args, **kwargs): | |
HTMLParser.__init__(self, *args, **kwargs) | |
self.stack = [] |
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 flask import Flask | |
app = Flask(__init__) | |
@app.route('/', methods=['GET']) | |
def getindex(): | |
return 'You did a GET' | |
@app.route('/', methods=['POST']) | |
def postindex(): | |
return 'You did a POST' |
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 adder(amt): | |
... def inner(start): | |
... return start + amt | |
... return inner | |
... | |
>>> plusone = adder(1) | |
>>> plusone(4) | |
5 |
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 openFiles(object): | |
def __init__(self, *args): | |
if not all(isinstance(arg, tuple) for arg in args): | |
raise TypeError('arguments to openFiles must all be 2-tuples') | |
if not all(len(arg) in (1, 2) for arg in args): | |
raise TypeError('arguments to openFiles must all be 2-tuples') | |
self.args = args | |
def __enter__(self): | |
self.fhs = [file(*arg) for arg in self.args] |
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 Equalizer(object): | |
def __init__(self, rv): | |
self._rv = rv | |
def __eq__(self, other): | |
assert self._rv == other | |
class Puny(object): |
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
Guess the output: | |
>>> def exec_code_object_and_return_x(codeobj, x): | |
... exec codeobj | |
... return x | |
... | |
>>> co1 = compile("""x = x + 1""", '<string>', 'exec') | |
>>> co2 = compile("""del x""", '<string>', 'exec') | |
>>> exec_code_object_and_return_x(co1, 1) | |
# What do you get here? |
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 | |
class TheModule(object): | |
def __getattr__(self, name): | |
# you can do whatever you want with `name` here | |
print (self, name) | |
sys.modules[__name__] = TheModule() |
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
-----> Heroku receiving push | |
-----> Python app detected | |
-----> Preparing Python interpreter (2.7.2) | |
-----> Creating Virtualenv version 1.7.2 | |
New python executable in .heroku/venv/bin/python2.7 | |
Not overwriting existing python script .heroku/venv/bin/python (you must use .heroku/venv/bin/python2.7) | |
Installing distribute..................................................................................................................................................................................................done. | |
Installing pip................done. | |
Overwriting .heroku/venv/bin/activate with new content | |
Overwriting .heroku/venv/bin/activate.fish with new content |
OlderNewer