I hereby claim:
- I am dgouldin on github.
- I am dgouldin (https://keybase.io/dgouldin) on keybase.
- I have a public key whose fingerprint is 0864 6C45 4C16 F447 D49C 33CD 42A6 BBC2 87C3 0C5A
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
from collections import OrderedDict | |
def groupby_unsorted(iterable, key=None): | |
''' | |
An implementation of itertools.groupby which eager evaluates groups and | |
therefore does not require its iterable to be pre-sorted. Groups are | |
returned in the order they are seen. | |
''' | |
key = key or (lambda x: x) | |
groups = OrderedDict() |
def index_of_first(iterable, value): | |
match_func = value if callable(value) else (lambda x: x == value) | |
for index, item in enumerate(iterable): | |
if match_func(item): | |
return index | |
raise ValueError('Value not found') |
#!/usr/bin/env python | |
from xml.etree import ElementTree | |
import requests | |
import unicodecsv as csv | |
import sys | |
url = "http://en.wikipedia.org/wiki/List_of_Game_of_Thrones_characters" | |
response = requests.get(url) | |
def get_characters(table): |
require("babel/register"); | |
var Imap = require('imap'); | |
var imap = new Imap({ | |
user: process.env.USERNAME, | |
password: process.env.PASSWORD, | |
host: 'imap.gmail.com', | |
port: 993, | |
tls: true | |
}); |
from django import template | |
register = template.Library() | |
token_formats = { | |
template.TOKEN_TEXT: '%s', | |
template.TOKEN_VAR: '%s%%s%s' % (template.VARIABLE_TAG_START, template.VARIABLE_TAG_END), | |
template.TOKEN_BLOCK: '%s%%s%s' % (template.BLOCK_TAG_START, template.BLOCK_TAG_END), | |
template.TOKEN_COMMENT: '%s%%s%s' % (template.COMMENT_TAG_START, template.COMMENT_TAG_END), | |
} |
def googol(): | |
def palindromes(end): | |
for odd_length in (True, False): | |
left = 0 | |
last_palindrome = 0 | |
while last_palindrome < end: | |
left += 1 | |
left_str = str(left) | |
right_str = left_str[::-1] | |
if odd_length: |
def googol(): | |
power = 100 | |
count = sum([2*9*10**n for n in range(power/2)]) | |
count_sum = sum([int(digit) for digit in str(count)]) | |
return (count, count_sum) |
from django.core import serializers | |
from django.utils import simplejson | |
def add_to_fixture(qs, filename): | |
f = open(filename, 'r') | |
data_python_existing = simplejson.loads(f.read()) | |
f.close() | |
data_json_unformatted = serializers.serialize('json', qs) | |
data_python_new = simplejson.loads(data_json_unformatted) | |
data_python_existing.extend(data_python_new) |
from django.core.cache import cache | |
def _incr_decr(key, incr=True, min=None, max=None, initial=None): | |
'''Incr/decr function which handles key creation as needed''' | |
# FIXME: min/max have rampant race conditions which could be fixed using | |
# memcache's "cas" feature, but current pylibmc + libmemcached causes a | |
# segfault when used. | |
initial = initial or min or 0 |