Skip to content

Instantly share code, notes, and snippets.

import networkx as nx
def main():
G = nx.Graph()
# states = ['new mexico', 'oklahoma', 'texas']
# states = ['new mexico', 'oklahoma', 'texas', 'arkansas', 'louisiana', 'mississippi']
@trhaynes
trhaynes / gist:2631808
Created May 8, 2012 01:16
I didn't write this code
AboutContent = {
defaultSection: "branching-and-merging",
init: function() {
if ($("body#about").length === 0) return;
AboutContent.observeNav(),
AboutContent.observePopState(),
AboutContent.showSection(AboutContent.getSection())
},
observePopState: function() {
if (window.history && window.history.pushState) return $(window).bind("popstate",
@trhaynes
trhaynes / gist:745508
Created December 17, 2010 19:04
Grabs all the start/active/shutdown/inactive events for the timeframe
sqlite> SELECT survey.user_id, q5, q6, event_code, timestamp FROM survey, events WHERE survey.user_id == events.user_id AND (event_code == 1 OR event_code == 2 OR event_code == 4 OR event_code == 5) AND timestamp/1000 >= CAST(strftime("%s", "2010-11-03 00:00:00") as INTEGER) AND timestamp/1000 < CAST(strftime("%s", "2010-11-10 00:00:00") as INTEGER);
@trhaynes
trhaynes / getsessions.py
Created December 17, 2010 19:02
Breaks the all_sessions_sorted.txt file into 10 minute chunks
import csv, sys
from datetime import datetime, timedelta
reader = csv.reader(open("all_sessions_sorted.txt", 'rb'), delimiter="|")
timestamp = None
user = 0
sessions = []
@trhaynes
trhaynes / gist:745316
Created December 17, 2010 17:26
Plots a week's worth of browsing data by age group
pdf(file="testing.pdf", width=11, height=4.5, family="Helvetica")
# read in table and remove rows with NAs
agedata <- na.omit(read.table("sessions_by_age_10min.txt", sep="|", header=T))
color <- c("#0000FF", "#FF1D25", "#009103", "#F7941E", "#00A8E2", "#FFA4D6")
# (probably an easier way to do this)
agedata$color[agedata$q6==0] <- color[1]
agedata$color[agedata$q6==1] <- color[2]