Skip to content

Instantly share code, notes, and snippets.

View seanlinehan's full-sized avatar

Sean Linehan seanlinehan

  • San Francisco, CA
View GitHub Profile
@seanlinehan
seanlinehan / GenBoxShadow.php
Created October 4, 2012 03:07
Create a pure-CSS version of any image
// Do whatever you'd like with the script! Show it off, mod it up, post it places, or whatever. :)
// (If you do, I wouldn't mind a Twitter shoutout at @_slinehan when appropriate!)
$imageURL = "URL HERE";
$image = imagecreatefromjpeg($imageURL);
$width = imagesx($image);
$height = imagesy($image);
// First, let's resize the image to something manageable while maintaining aspect ratio.
@seanlinehan
seanlinehan / gist:4371554
Last active December 10, 2015 02:58
Returns first occurrence of a key in a multidimensional object. If anybody has a more efficient method, tweet at me! @_slinehan
# Returns first occurrence of a key in a multidimensional object
# Haystack can either be a dict or a list, but needle must be
# a dict key name or a list of dict key names
# Example:
# deepObject = {
# 'Sky': {
# 'Planes': 2.5,
# 'Rockets': 3.5,
# 'Missiles': 3.0,
@seanlinehan
seanlinehan / InsertIfNotExist.py
Last active December 10, 2015 12:08
Inserts a dictionary of column names, values into a MySQL database if a record doesn't currently exist based on a dictionary of constraints.
import MySQLdb as mdb
## Get the a hash ID from the database
## If it doesn't exist, add it to the database and return the new ID
## value_map is flattened before insertion so any single column should be in the entire dict.
## con (MySQLdb): current MySQLdb connection
## table (string): table name to update
## pk (string): column name of the primary key (id)
## value_map (dict): needs are necessary constraints, needsone are only-one-needed constraints, others are for insert if not exist
## {
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
blob = "[Nuzzel JSON Blob]"
obj = json.loads(blob)
twitter_user_ids = []
# Thanks for calling all these awesome people friends, Nuzzel
for friend in obj['results']['friends']:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import oauth2 # <- pip install oauth2
import time
# Oauth request helper. Mostly copy-pasta from Twitter's docs.
def oauth_req(url, http_method="GET"):
consumer = oauth2.Consumer(key='YOUR TWITTER API KEY', secret='YOUR TWITTER API SECRET')
client = oauth2.Client(consumer)
#!/usr/bin/env python
from collections import defaultdict
# Convenience method
def get_intersection(users):
# pull out the users' following list
list_of_follower_lists = map(lambda x: x[1], users)
# return a list containing the common followers amongst them all
return set(list_of_follower_lists[0]).intersection(*list_of_follower_lists)
# Limit the list to people who have at least 43 followers in the set
filtered = {
followed: follower_sets[followed]
for followed in follower_sets.keys()
if len(follower_sets[followed]) >= 43
}
#!/usr/bin/env python
from __future__ import division
import random, sys, math
from collections import defaultdict
# Convenience
def remove_at_index(l, index):
return l[:index] + l[index+1:]
def sort_population(population):
def optimize(population, rounds):
population = sort_population(population)
# Set our seed set to a pretty good default
test_set = population[:10]
# To compare other sets against
highest_exposure = len(get_intersection(test_set))
print "Baseline: %d" % highest_exposure
print "=============="
for i in range(rounds):
Steve Case
https://twitter.com/SteveCase
Russell Fradin
https://twitter.com/rfradin
Adam D'Augelli
https://twitter.com/adaugelli
William Peng