Skip to content

Instantly share code, notes, and snippets.

View dgouldin's full-sized avatar

David Gouldin dgouldin

  • Clara Labs
  • San Francisco, CA
View GitHub Profile
@dgouldin
dgouldin / gist:3485236
Created August 27, 2012 03:10
Dead letter exchange based celery countdown implementation
class FrealCountdownTask(task.Task):
abstract = True
@classmethod
def apply_async(self, args=None, kwargs=None,
task_id=None, producer=None, connection=None, router=None,
link=None, link_error=None, publisher=None, add_to_parent=True,
**options):
try:
@dgouldin
dgouldin / gist:3696240
Created September 11, 2012 05:45
Candidates running against supporters of SOPA
https://www.votizen.com/matt-helt-for-us-house/
https://www.votizen.com/phil-jennerjahn-for-us-house-1/
https://www.votizen.com/candace-duval-for-us-house/
https://www.votizen.com/brad-morris-for-us-house/
https://www.votizen.com/robert-estes-for-us-house/
https://www.votizen.com/henry-ross-for-us-house/
https://www.votizen.com/jim-bourland-for-us-house/
https://www.votizen.com/danny-bedwell-for-us-house/
https://www.votizen.com/chris-potts-for-us-house/
https://www.votizen.com/philip-scollo-for-us-house/

Tunneling a public URL to your local machine

On the public web server

Sample lighttpd conf:

$HTTP["host"] == "d.gould.in" {
  proxy.server = ( "" => ( ( "host" => "127.0.0.1",
                             "port" => 20020 ) ) )
@dgouldin
dgouldin / gist:3836859
Created October 4, 2012 22:24
haproxy logs -> list of python dicts
import datetime
import re
HAPROXY_LOG_PATH = '/path/to/haproxy.log'
haproxy_re = re.compile(
r'haproxy\[(?P<pid>\d+)\]: '
r'(?P<client_ip>(\d{1,3}\.){3}\d{1,3}):(?P<client_port>\d{1,5}) '
r'\[(?P<date>\d{2}/\w{3}/\d{4}(:\d{2}){3}\.\d{3})\] '
r'(?P<listener_name>\S+) (?P<server_name>\S+) '
r'(?P<Tq>(-1|\d+))/(?P<Tw>(-1|\d+))/(?P<Tc>(-1|\d+))/(?P<Tr>(-1|\d+))/'
Monospaced fonts still have plenty of valid uses, so I BEG. TO. DIFFER.
@dgouldin
dgouldin / gist:4112800
Created November 19, 2012 18:47
django orm order by list of ids
from django.contrib.auth.models import User
user_ids = list(User.objects.values_list('id', flat=True)[:10])
reverse_user_ids = user_ids[::-1]
values_str_parts = ['(%s, %s)' % (i, id) for i, id in enumerate(reverse_user_ids)]
values_str = 'VALUES %s' % ' '.join(values_str_parts)
users = User.objects.raw("""
SELECT u.*
FROM auth_user AS u
JOIN (%s) AS i (ordering, id) on u.id = i.id
@dgouldin
dgouldin / gist:4120897
Created November 20, 2012 20:35
Get django's auth user model in a backwards compatible way
try:
from django.contrib.auth import get_user_model
except ImportError:
from django.contrib.auth.models import User as UserModel
else:
UserModel = get_user_model()
@dgouldin
dgouldin / foodiebox.rst
Created December 16, 2012 05:52
"Made in SF" foodie box

Keybase proof

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:

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()