Skip to content

Instantly share code, notes, and snippets.

View anbnyc's full-sized avatar

Alec Barrett anbnyc

View GitHub Profile
@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 / 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 / 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 / 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:

{ 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 / 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"]
@anbnyc
anbnyc / code.py
Created March 21, 2017 21:36
Code Dojo (Hackerrank melodious passwords) solution
#!/bin/python3
import sys
import itertools
import functools
n = int(input().strip())
letters = [
[x for x in "aeiou"],
@anbnyc
anbnyc / index.html
Last active July 26, 2017 17:39
Implementation of Red-Black Tree in JavaScript
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.18.1/vis.min.js"></script>
<script
src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.0/js/materialize.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.0/css/materialize.min.css">
<style>
@anbnyc
anbnyc / lrucache.scm
Last active February 28, 2017 21:27
Implementation of LRU Cache in Scheme
;; LRU Cache Implementation
;; New items are added to the end and old items removed from the start.
;; Try running it at https://repl.it/languages/scheme
;; make-lru-cache: returns procedure with access to cache procedures
;; [arg] maxlen: maximum length of the cache
(define (make-lru-cache maxlen)
;; cache is initialized as empty list
;; first elem is actual cache, second elem is pointer to end of cache
@anbnyc
anbnyc / radix.py
Last active February 18, 2017 23:09
Implementation of radix sort in Python
import math
import functools
""" radix_sort
in: list_to_sort (list)
in: base (optional)
out: sorted list_to_sort
"""
def radix_sort(list_to_sort,base=10):
# number of significant digits of largest number