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 / mute-words-twitter-emotions.txt
Last active April 15, 2024 01:00
Mute these words on Twitter to eliminate some negativity from your life
appalled
ashamed
asshole
complicit
deplorable
deplore
disgraceful
disgusted
fuck
fucking
Steve Case
https://twitter.com/SteveCase
Russell Fradin
https://twitter.com/rfradin
Adam D'Augelli
https://twitter.com/adaugelli
William Peng
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):
#!/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):
# 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 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)
#!/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
# -*- 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']:
@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
## {
@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,