Skip to content

Instantly share code, notes, and snippets.

@Radcliffe
Radcliffe / aclu-anti-mosque-activity.csv
Last active February 5, 2016 05:33
ACLU - Nationwide Anti-Mosque Activity
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 9 columns, instead of 6 in line 4.
"Id","City","State","Month","Year","Summary","Source","lon","lat"
1,"Bella Vista","Arkansas","September",2010,"The Bella Vista City Council met to consider banning the construction of mosques and the practice of Sharia Law within city limits.","http://nwahomepage.com/fulltext-news?nxd_id=188955 http://jonah-m-tebbetts.blogspot.com/2010/09/new-jerusalem-in-benton-cou...",-94.2732642,36.481464
2,"Phoenix","Arizona","December",2015,"Vandals shattered windows at the Islamic Cultural Center.","http://www.abc15.com/news/region-phoenix-metro/north-phoenix/vandalism-reported-at-islamic-community-center-in-phoenix-",-112.0740373,33.4483771
3,"Glendale","Arizona","August",2010,"Two men threw an acid bomb - a soda bottle filled with acid at a mosque - targeting mosque officials standing nearby.","http://www.reuters.com/article/idUSN0833871920070808",-112.1859866,33.5386523
4,"Phoenix","Arizona","August",2010,"Vandals threw paint on the floor, shot out windows, and wrote anti-Muslim slurs on the walls of a local mosque."
@Radcliffe
Radcliffe / run_distribution_in_coin_tosses.py
Last active February 10, 2016 22:41
Probability distribution of the longest run of heads or tails in N tosses of a fair coin
# Find the probability distribution of the longest run of heads or tails in N tosses of a fair coin.
N = 10 # Number of coin tosses
from itertools import product, imap, groupby
from collections import Counter
# Adapted from http://stackoverflow.com/a/22214180/677398
def longest_run(sequence):
return max(sum(1 for _ in group) for key, group in groupby(sequence))
@Radcliffe
Radcliffe / run_distribution_in_coin_tosses_2.py
Last active February 12, 2016 04:59
Expected distribution of maximum runs in a sequence of coin flips
# -*- coding: utf-8 -*-
"""
Let a[n; c, r] = number of sequences of n coin flips
ending with a streak of c heads or tails
and having a longest streak of r heads or tails.
We can show that
a[n; 1, r] = sum (i=1 to r) a[n-1; i, r]
and
a[n; r, r] = a[n-1; r-1, r-1] + a[n-1; r-1, r]
@Radcliffe
Radcliffe / ZIP_code_to_Congressional_District.R
Created February 20, 2016 06:46
Zip codes and congressional disricts -- R script
# This R script generates a correspondence between ZIP codes and
# US Congressional Districts (113th Congress)
# by merging two data files from the US Census Bureau website.
#
# Note that the relation is many-to-many, since a ZIP code can cross
# several districts, and a district can cross several ZIP codes.
library(data.table)
district_zip <- fread(
@Radcliffe
Radcliffe / MN-Licensed-Staff-Count-2015.csv
Created February 27, 2016 23:26
Minnesota Licensed Teaching Staff Counts for 2015
Year Assignment Description Head Count FTE
2015 SUPERINTENDENT 341 300.27
2015 SCHOOL NURSE 731 507.95
2015 ANIMAL SCIENCE AND TECHNOLOGY 72 19.81
2015 MIDDLE/JUNIOR HIGH VISUAL ARTS 440 230.65
2015 FOUNDATIONS OF STUDIO ART 274 119.22
2015 VOCAL MUSIC 891 548.92
2015 BAND 1183 630.39
2015 COMPREHENSIVE LANGUAGE ARTS 3261 2334.3
2015 LITERATURE 783 355.61
@Radcliffe
Radcliffe / MN-Libraries.csv
Last active March 5, 2016 19:07
Minnesota Public Libraries
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 9.
"Library","Phone","City","County","Zip","Latitude","Longitude","Street.Address"
"Ada Public Library","(218) 784-4480","Ada","Norman County","56510",47.3005818,-96.511009,"107 4th Avenue East"
"Adrian Branch Library","(507) 483-2541","Adrian","Nobles County","56110",43.6346305,-95.9331177,"214 Maine Avenue"
"Aitkin Public Library","(218) 927-2339","Aitkin","Aitkin County","56431",46.5326296,-93.7046646,"110 1st Avenue Northeast"
"Great River Regional Library - Albany","(320) 845-4843","Albany","Stearns County","56307",45.62953,-94.568801,"400 Railroad Avenue"
"Albert Lea Public Library","(507) 377-4350","Albert Lea","Freeborn County","56007",43.6501866,-93.3664103,"211 East Clark Street"
"Douglas County Library","(320) 762-3014","Alexandria","Douglas County","56308",45.8845467,-95.3792711,"720 Fillmore Street"
"Great River Regional Library - Annandale Branch","(320) 274-8448","Annandale","Wright County","55302",45.2638168,-94.1233636,"30 Cedar Street East"
"Rum River Library","(763) 576-4695","Anoka","Anoka Co
@Radcliffe
Radcliffe / cryptarithm-half-fifth-tenth-whole.py
Created March 9, 2016 23:34
Cryptarithm: HALF + FIFTH + TENTH + TENTH + TENTH = WHOLE
import itertools
for a,e,f,h,i,l,t,n,o,w in itertools.permutations(range(10)):
if h > 0 and t > 0 and f > 0 and w > 0:
half = 1000*h + 100*a + 10*l + f
fifth = 10100*f + i*1000 + t*10 + h
tenth = 10010*t + 1000*e + n*100 + h
whole = w*10000 + h*1000 + o*100 + l*10 + e
if half + fifth + 3*tenth == whole:
print "%s + %s + %s + %s + %s = %s" % (
half, fifth, tenth, tenth, tenth, whole)
@Radcliffe
Radcliffe / walmart-closings.csv
Created March 23, 2016 21:47
Walmart Store Closings Jan 2016
Location DateClosed StoreNumber StoreTypes lon lat
14331 Count Rd. 99, Headland, AL 2016-01-28 2173 Walmart Express -85.3259952 31.3607946
18 Apple Way, Ashford, AL 2016-01-28 2011 Walmart Express -85.237821 31.1765287
952 E. Lawrence Harris Hwy, Slocomb, AL 2016-01-28 2165 Walmart Express -85.5907905 31.1076635
407 West Washington St., Abbeville, AL 2016-01-28 2186 Walmart Express -85.2594391 31.5737215
6361 Hwy 72 East Gurley, AL 2016-01-28 2235 Walmart Express -86.3700933 34.6947341
87395 US Hwy 278, Snead, AL 2016-01-28 2260 Walmart Express -86.8494742 34.17204
3530 Cathedral Caverns Hwy, Grant, AL 2016-01-28 3769 Walmart Express -86.2611173 34.5014024
10188 Hwy 431 South, New Hope, AL 2016-01-28 3779 Walmart Express -86.3911528 34.5277698
720 N Hwy 71, Mansfield, AR 2016-01-28 2498 Walmart Express -94.2619279 35.077937
@Radcliffe
Radcliffe / list-of-fields-medalists.csv
Created May 13, 2016 19:10
List of Fields Medalists
YearAwarded Name Gender Citizenship SecondCitizenship BirthYear Remarks Affiliation AgeAtAward
2014 Artur Avila Cordeiro de Melo Male Brazil France 1979   CNRS - Institut de Mathématiques de Jussieu-Paris Rive Gauche 35
2014 Manjul Bhargava Male Canada United States 1974   Princeton University, 40
2014 Martin Hairer Male Austria   1975   University of Warwick 39
2014 Maryam Mirzakhani Female Iran   1977   Stanford University 37
2010 Ngô Bao Châu Male Vietnam France 1972   Université Paris-Sud 11 and Institute for Advanced Study 38
2010 Elon Lindenstrauss Male Israel   1970   Hebrew University of Jerusalem 40
2010 Stanislav K. Smirnov Male Russia   1970   University of Geneva 40
2010 Cédric Villani Male France   1973   École Normale Supérieure de Lyon and Institut Henri Poincaré 37
2006 Andrei Okounkov Male Russia   1969   Princeton University 37
@Radcliffe
Radcliffe / quicksort.js
Created June 15, 2016 14:07
Quicksort in JavaScript
function partition(arr, lo, hi) {
var swap = function (i, j) {
var tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
var pivot = arr[hi];
var pivotLoc = lo;
var i;