This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
## { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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']: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Steve Case | |
https://twitter.com/SteveCase | |
Russell Fradin | |
https://twitter.com/rfradin | |
Adam D'Augelli | |
https://twitter.com/adaugelli | |
William Peng |
OlderNewer