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:46
Time lapse map of UFO sightings
@anbnyc
anbnyc / heap.py
Last active January 27, 2017 23:16
Implementation of min/max heap
import math
"""Implementation of min heap
Works with Python 2 or 3
Run from terminal:
`python heap.py`
"""
class Heap(object):
@anbnyc
anbnyc / hash.py
Last active February 3, 2017 20:11
Implementation of hash table
### Implementation of Hash Table
# Methods: insert, search, delete
# Language: Python 2 or Python 3
import json
## initialize hash_table
# arg n (int): length of the hash table
class hash_table(object):
def __init__(self,n=10):
self.length = n
@anbnyc
anbnyc / Readme.md
Last active July 24, 2019 01:36
Recreate functionality from NYT's "You draw it"

Recreate NYT's "You Draw It"

Inspired by the New York Times' You Draw It, which allows the user to trace a line with the mouse that immediately appears on the screen, with specific constraints. Mouse event technique from https://bl.ocks.org/mbostock/4198499.

@anbnyc
anbnyc / Readme.md
Last active February 13, 2017 02:06
Subway (1) line as network graph

#Subway (1) Line as Network Graph

Created using Vis.js

I set out to create a map of the entire subway as a network graph. I got bogged down with cleaning the data, which I drew from two NYC Open Data sets. Until I can get the full subway system working, here is what one subway line looks like.

Data sources

The subway stations data set does not indicate the order of the stations, and the lines dataset does not have the stations in it. I'm working on devising a better system of placing stations on the lines, but in the mean time I have resorted to a heuristic where a station is on a line if it is "close enough" to the line.

@anbnyc
anbnyc / index.html
Last active February 13, 2017 22:53
Data structure visualization
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.18.1/vis.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.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">
@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
@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 / 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 / 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"],