Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / crux-mathematicorum-M379.py
Created February 2, 2016 18:06
Solution to Crux Mathematicorum M379
"""
Problem M379, Crux Mathematicorum
Proposed by John Grant McLoughlin, University of New Brunswkci,
Fredericton, NB.
The integers 27+C, 555+C, and 1371+C are all perfect squares, the square
roots of which form an arithmetic sequence. Determine all possible values
of C.
"""
@Radcliffe
Radcliffe / walmart-closings.csv
Last active January 16, 2016 19:41
Walmart closings announced Jan 2016
Location DateClosedToPublic StoreNumber StoreType 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.3915109 34.1173155
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.4308169 34.5482599
720 N Hwy 71, Mansfield, AR 2016-01-28 2498 Walmart Express -94.2619279 35.077937
@Radcliffe
Radcliffe / reshape-expenditures.R
Last active January 5, 2016 05:07
Reshape expenditure data
library(dplyr)
d <- read.csv('expenditures.csv')
cats <- unique(d$ProgramCategory)
newnames <- gsub("[- ]", "", cats)
e <- d %>%
filter(ProgramCategory == cats[1]) %>%
select(Year:StudentsServed)
@Radcliffe
Radcliffe / Euler_four_square_identity.py
Created December 29, 2015 21:50
Proof of Euler's four square identity using Python and SymPy
"""
Euler's four square theorem states that
(x1^2 + x2^2 + x3^2 + x4^2) *
(y1^2 + y2^2 + y3^2 + y4^2) =
z1^2 + z2^2 + z3^2 + z4^2,
where
z1 = x1*y1 + x2*y2 + x3*y3 + x4*y4
z2 = x1*y2 - x2*y1 - x3*y4 + x4*y3