Skip to content

Instantly share code, notes, and snippets.

View akaptur's full-sized avatar

Allison Kaptur akaptur

View GitHub Profile
@akaptur
akaptur / gist:5769182
Last active December 18, 2015 10:29
Victory Bot: About Me
Victory Bot is so excited for you!
Want more/better gifs? Open a pull request!
Bot driving you crazy? It responds to `@victorybot mute` which will mute it (for everyone).
Unmuting requires a password.
It also responds to PMs, whenever you need a little pick-me-up.
import re
import timeit
import string
double = re.compile(r"([a-z])(\1)")
double_var = double = re.compile(r"([a-z])\1")
single = re.compile(r"([a-z])")
# Make this string raw!
@akaptur
akaptur / gist:6082462
Created July 25, 2013 18:32
Spot the difference between these two pieces of code!
WORDS = (word.strip() for word in open('sowpods.txt').readlines())
def find_palindromes():
pals = []
for word in WORDS:
mid = len(word) / 2
if word[:mid] == "".join(reversed(word[-mid:])):
pals.append(word)
longest = max(pals, key=len)
return longest
@akaptur
akaptur / disbuzz.py
Last active December 20, 2015 09:30
disbuzz
import dis
def ifbuzz(x):
if x % 5 == 0 and x % 3 == 0:
print "FizzBuzz"
else:
if x % 3 == 0:
print "Fizz"
else:
if x % 5 == 0:
print "Buzz"
@akaptur
akaptur / gist:6766420
Last active December 24, 2015 07:49
Tune-up
Tune-up prep
Macs
Move everything in .bash_profile to .bashrc
Have .bash_profile source .bashrc:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
Install Xcode + Command Line Tools
@akaptur
akaptur / gist:7173535
Created October 26, 2013 19:28
Example output of tox on byterun, passing a command to nosetest
(byterun_env)byterun [assorted-fixes $%] ⚲ tox -- tests.test_basic:TestIt
GLOB sdist-make: /Users/afk/Dropbox/python/byterun_env/byterun/setup.py
py27 inst-nodeps: /Users/afk/Dropbox/python/byterun_env/byterun/.tox/dist/Byterun-1.0.zip
py27 runtests: commands[0] | nosetests tests.test_basic:TestIt
..........................
----------------------------------------------------------------------
Ran 26 tests in 0.280s
OK
py33 inst-nodeps: /Users/afk/Dropbox/python/byterun_env/byterun/.tox/dist/Byterun-1.0.zip
@akaptur
akaptur / gist:7217177
Created October 29, 2013 15:45
Possible misunderstanding of how `cause` interacts with context manager silencing in python 3
>>> class FalseContext(object):
... def __enter__(self):
... l.append('i')
... return self
... def __exit__(self, exc_type, exc_val, exc_tb):
... l.append('o')
... return False
...
>>> class TrueContext(object):
... def __enter__(self):
>>> class Thing(object):
... def __init__(self, name, description):
... self.name = name
... self.desc = description
...
>>> b = Thing('box', 'empty')
>>> c = Thing('cat', 'fuzzy')
>>> collection = {'box': b, 'cat' : c}
>>> collection['box']
<__main__.Thing object at 0x1073a2150>
@akaptur
akaptur / gist:9137899
Created February 21, 2014 16:45
Class variables vs. instance variables in python
>>> class Test(object):
... var = 7
... def __init__(self):
... self.ivar = 2
...
>>> t = Test()
>>> s = Test()
>>> t.__dict__
{'ivar': 2}
>>> t.var
@akaptur
akaptur / gist:6ca2347bf250bfd4f87a
Created July 25, 2014 19:59
error message from generator bug in byterun
FAIL: test_generator_from_generator2 (tests.test_functions.TestGenerators)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/afk/Dropbox/python/byterun_env/byterun/tests/test_functions.py", line 239, in test_generator_from_generator2
""")
File "/Users/afk/Dropbox/python/byterun_env/byterun/tests/vmtest.py", line 86, in assert_ok
self.assert_same_exception(vm_exc, py_exc)
File "/Users/afk/Dropbox/python/byterun_env/byterun/tests/vmtest.py", line 96, in assert_same_exception
self.assertEqual(str(e1), str(e2))
nose.proxy.AssertionError: AssertionError: "unsupported operand type(s) for *: 'NoneType' and 'NoneType'" != 'None'