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 / similarity.py
Created June 6, 2015 09:53
Twitter friend similarity
from __future__ import division
import json
import os
import urlparse
from collections import defaultdict
from datetime import datetime
from dateutil.relativedelta import relativedelta
from requests import HTTPError
from requests_oauthlib import OAuth1Session
@dgouldin
dgouldin / server.es6
Last active August 29, 2015 14:19
Gmail IDLE test
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
});
#!/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):
@dgouldin
dgouldin / requests_http.py
Created June 5, 2014 18:29
Requests-based Suds transport
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from requests import Session
from requests.adapters import BaseAdapter
from requests.auth import HTTPBasicAuth
from requests.models import Response
from suds.properties import Unskin
from suds.transport import Transport, TransportError, Reply
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')
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()

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:

@dgouldin
dgouldin / foodiebox.rst
Created December 16, 2012 05:52
"Made in SF" foodie box
@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 / 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