Skip to content

Instantly share code, notes, and snippets.

View akaptur's full-sized avatar

Allison Kaptur akaptur

View GitHub Profile
@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 / 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: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
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: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.
@akaptur
akaptur / gist:5399666
Created April 16, 2013 21:08
python's this.py
s = """Gur Mra bs Clguba, ol Gvz Crgref
Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf orggre guna pbzcyvpngrq.
Syng vf orggre guna arfgrq.
Fcnefr vf orggre guna qrafr.
Ernqnovyvgl pbhagf.
Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf.
@akaptur
akaptur / gist:5239387
Created March 25, 2013 18:26
Trivial generators example
>>> def gen():
... yield 1
... yield 2
... yield 3
...
>>> for i in gen():
... print i
...
1
2
@akaptur
akaptur / gist:4431890
Last active December 10, 2015 12:08
Surprised by stable sort
def two_sort(ex):
ex_copy = ex[:]
ex.sort(key=lambda tup: tup[1])
ex.reverse()
print "Ex: ", ex
ex_copy.sort(key=lambda tup: tup[1], reverse=True)
print "Copy:", ex_copy
@akaptur
akaptur / activate
Created December 23, 2012 23:02
The version of virtualenv's activate on my machine
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly
deactivate () {
unset pydoc
# reset old environment variables
if [ -n "$_OLD_VIRTUAL_PATH" ] ; then
PATH="$_OLD_VIRTUAL_PATH"
export PATH
@akaptur
akaptur / gist:4348873
Last active December 10, 2015 00:09
A small depiction of issues with floating point arithmetic in python.
def naive_add(lis):
total = 0
for elem in lis:
total += elem
return total
def recursive_add(lis):
if len(lis) == 1:
return lis[0]
elif len(lis) == 0: