Skip to content

Instantly share code, notes, and snippets.

View anbnyc's full-sized avatar

Alec Barrett anbnyc

View GitHub Profile
@anbnyc
anbnyc / .block
Last active July 31, 2018 20:02
Composition
license: mit
height: 500
border: no
@anbnyc
anbnyc / readme.md
Created May 31, 2018 19:29
Statewide election results over years, 2012-2017

Compiled from publicly available news sources including NY Times, CNN, NPR, and Wikipedia.

Pct_point_diff is calculated as (Dem vote percentage - GOP vote percentage).

@anbnyc
anbnyc / districts.dsv
Created May 31, 2018 18:20
House districts presidential election results 2016 and incumbent status in 2018
CD;Incumbent;Party;Pres;Open;Not running
AK-AL;Young, Don;(R);Trump;FALSE;
AL-01;Byrne, Bradley;(R);Trump;FALSE;
AL-02;Roby, Martha;(R);Trump;FALSE;
AL-03;Rogers, Mike;(R);Trump;FALSE;
AL-04;Aderholt, Rob;(R);Trump;FALSE;
AL-05;Brooks, Mo;(R);Trump;FALSE;
AL-06;Palmer, Gary;(R);Trump;FALSE;
AL-07;Sewell, Terri;(D);Clinton;FALSE;
AR-01;Crawford, Rick;(R);Trump;FALSE;
@anbnyc
anbnyc / counties.dsv
Last active May 31, 2018 21:48
County presidential election results change in Dem advantage from 2008 and 2012 to 2016
per_point_diff_2016|per_point_diff_2012|per_point_diff_2008|state_abbr|county_name|per_point_diff_12_16|per_point_diff_08_16
-0.4947893435|-0.460579698|-0.4784061588|AL|Autauga County|-0.03420964548|-0.01638318471
-0.5778616219|-0.5582317504|-0.5144755752|AL|Baldwin County|-0.01962987149|-0.0633860467
-0.05611164581|0.02914739506|-0.01453138435|AL|Barbour County|-0.08525904087|-0.04158026146
-0.5554412437|-0.4684781313|-0.4584683017|AL|Bibb County|-0.08696311238|-0.096972942
-0.813819729|-0.7414512093|-0.6950591338|AL|Blount County|-0.07236851962|-0.1187605952
0.5086151883|0.5280180519|0.4838411819|AL|Bullock County|-0.01940286364|0.02477400636
-0.1352907311|-0.07529262891|-0.1335873931|AL|Butler County|-0.05999810223|-0.001703338005
-0.4138382303|-0.3194636678|-0.3252101864|AL|Calhoun County|-0.09437456251|-0.0886280439
-0.148062128|-0.0510232111|-0.08478202728|AL|Chambers County|-0.09703891693|-0.06328010075
@anbnyc
anbnyc / star.js
Created March 3, 2018 12:22
SVG polygon points for a five-pointed star
const star = radius =>
[0, .4, .8, .2, .6, 0].map(d =>
Math.round(1000* radius*Math.cos(2*Math.PI*d - .5*Math.PI) )/1000
+","+
Math.round(1000* radius*Math.sin(2*Math.PI*d - .5*Math.PI) )/1000
).join(' ')
star(7.5)
This file has been truncated, but you can view the full file.
[
{
"tree_id": 190422,
"spc_common": "honeylocust",
"Latitude": 40.77004563,
"longitude": -73.98494997
},
{
"tree_id": 190426,
"spc_common": "honeylocust",
@anbnyc
anbnyc / index.html
Created February 1, 2018 16:27
Treemap based on NYC 2015 Tree Census
<html>
<head>
<style>
.menu {
display: block; }
.menu select {
margin: 10px; }
.menu .legend {
margin: 10px;
position: relative;
@anbnyc
anbnyc / dataprep.R
Created February 1, 2018 16:22
Rollup of NYC 2015 Tree Census data
library(dplyr)
library(tidyr)
library(jsonlite)
#https://data.cityofnewyork.us/Environment/2015-Street-Tree-Census-Tree-Data/pi5s-9p35
raw <- read.csv("~/Downloads/2015StreetTreesCensus_TREES.csv", stringsAsFactors = F)
trees <- tbl_df(raw) %>%
group_by(boroname, nta_name, spc_common, health) %>%
summarise(n = n())
write(toJSON(trees), "~/Desktop/trees.json")
@anbnyc
anbnyc / brookhaven.r
Created August 29, 2017 13:01
clean voter file
voters <- read.csv("~/Downloads/voter_file.csv", stringsAsFactors = F)
voters_sub <- voters[c("SBOEID","DOB","REGDATE","ENROLLMENT","LASTVOTEDATE","COUNTYCODE","ED","WARD","SD","AD","LD")]
existing_eds <- tbl_df(voters_sub) %>%
group_by(ED, ENROLLMENT) %>%
summarise(count = n()) %>%
spread(ENROLLMENT, count) %>%
mutate(TOTAL = sum(BLK,CON,DEM,GRE,IND,OTH,REF,REP,WEP,WOR,na.rm=T),
DEM_PCT = DEM/TOTAL)
new_dems_eds <- tbl_df(voters_sub) %>%
filter(REGDATE >= 20161109) %>%