Skip to content

Instantly share code, notes, and snippets.

View anbnyc's full-sized avatar

Alec Barrett anbnyc

View GitHub Profile
@anbnyc
anbnyc / astar.py
Created March 22, 2017 02:03
A* Search Implementation in Python
def astar(source, target, obstacles):
def g(start,neighbor):
return 10 if start[0] == neighbor[0] or start[1] == neighbor[1] else 14
def h(start,target):
return 10 * (abs(start[0] - target[0]) + abs(start[1] - target[1]))
def f(neighbor):
previous_g = to_see[current]["g"]
{ width: 400, height: 200, values: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@anbnyc
anbnyc / Readme.md
Last active July 26, 2017 17:37
Neighboring states

Neighboring States

Produced at TWO-N. How many neighbors does each state have? This map reimagines the states as regular polygons with one side for each neighbor. Click a state to see its neighbors up close!

Methodology

When you click on a state, the position of its neighbors approximate their true relative geographic position. The relative positions are calculated using the geographic centers of each state.

Sources

With inspiration and code from:

@anbnyc
anbnyc / index.html
Last active July 26, 2017 17:33
Wallpaper illustrator v0
<html>
<head>
<style type="text/css">
canvas {
border: solid black 1px;
}
div.controls{
width: 300px;
@anbnyc
anbnyc / index.html
Last active July 26, 2017 17:31
Game of Thrones d3.pack layout
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.9.1/d3.min.js"></script>
<style>
h1{
text-align: center;
}
h1, p, text{
font-family: Palatino;
@anbnyc
anbnyc / Readme.md
Last active July 26, 2017 17:59
Child growth charts in Vega

Growth charts data from WHO and CDC.

@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) %>%
@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 / 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;
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",