Skip to content

Instantly share code, notes, and snippets.

View mlevans's full-sized avatar

Michael Lawrence Evans mlevans

  • Office of Emerging Technology, City of Boston
  • Boston, MA
View GitHub Profile
@mlevans
mlevans / index.html
Created May 25, 2011 21:21
Displaying Map Tiles from TileStream
<!Doctype html>
<html>
<head>
<title>311 Density</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="https://github.com/CloudMade/Leaflet/raw/master/dist/leaflet.css" />
<!--[if lte IE 8]><link rel="stylesheet" href="https://github.com/CloudMade/Leaflet/raw/master/dist/leaflet.ie.css" /><![endif]-->
</head>
<body>
@mlevans
mlevans / polygonize.py
Created April 26, 2012 03:39 — forked from migurski/polygonize.py
Polygonize a bag of lines
from sys import argv
from shapely.ops import polygonize
from shapely.geometry import asShape, LineString
import json
if __name__ == '__main__':
input = argv[1]
input = json.load(open(input))
@mlevans
mlevans / gist:2506045
Created April 27, 2012 05:08
Convert Latitude/Longitude Pair to Tile Coordinates
function latLngToCoords(zoom,lat,lon) {
var n = Math.pow(2,zoom);
var lat_rad = lat * (Math.PI / 180);
var x_coord = n * ((lon + 180) / 360);
var y_coord = .5 * n * (1 - (Math.log (Math.tan(lat_rad) + (1/Math.cos(lat_rad))) / Math.PI));
return {x: Math.floor(x_coord), y: Math.floor(y_coord)};
@mlevans
mlevans / gist:2650008
Created May 10, 2012 00:21
Simple Sorting Tutorial
// Load d3
var val_arr = [];
function sortFunction(a,b) {
return a - b;
}
function loadData(){
d3.csv('data.csv',function(data){
@mlevans
mlevans / lambert.js
Created May 15, 2012 00:13 — forked from migurski/lambert.js
Lambert projection for Modest Maps
var LambertProjection = function(lat0, lon0, lat1, lat2, xmin, ymin, xmax, ymax)
{
var pi = Math.PI, ln = Math.log, pow = Math.pow,
sin = Math.sin, cos = Math.cos, tan = Math.tan,
atan = Math.atan, sqrt = Math.sqrt;
function sec(t) { return 1 / cos(t); }
function cot(t) { return 1 / tan(t); }
function deg2rad(deg) { return pi * deg / 180; }
var π = Math.PI; // uni_pi = '\u03C0';
console.log(π);
// >> 3.141592653589793
@mlevans
mlevans / latency.txt
Created May 31, 2012 23:41 — forked from jboner/latency.txt
Latency numbers every programmer should know
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns
Mutex lock/unlock 25 ns
Main memory reference 100 ns
Compress 1K bytes with Zippy 3,000 ns
Send 2K bytes over 1 Gbps network 20,000 ns
Read 1 MB sequentially from memory 250,000 ns
Round trip within same datacenter 500,000 ns
Disk seek 10,000,000 ns
@mlevans
mlevans / gunicorn-slayer.py
Created June 21, 2012 08:23 — forked from migurski/gunicorn-slayer.py
Gunicorn Slayer
from sys import argv
from time import time
from glob import glob
from os import stat, kill, getuid
from os.path import basename, dirname, join
from datetime import datetime
from random import choice
from signal import SIGTERM
if __name__ == '__main__':
@mlevans
mlevans / index.html
Created June 24, 2012 21:31 — forked from jasondavies/index.html
Multiple sparkline transition strangeness
<!DOCTYPE html>
<html>
<head>
<title>Animated Sparkline</title>
<script src="http://mbostock.github.com/d3/d3.js?2.7.2"></script>
<style type="text/css">
path {
stroke: steelblue;
stroke-linecap: round;
@mlevans
mlevans / gist:3052009
Created July 5, 2012 07:28
Find Duplicates in a List
# Finding duplicates in a list
import collections
the_list = [2,2,2,1,1,0]
count = collections.Counter(the_list)