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
class GradeLevel
attr_accessor :number
def initialize(num)
@number = num
end
def order_index
number =~ /K(\d)/ ? $1.to_i : (number.to_i + 2)
end
end
@mlevans
mlevans / gist:3725694
Created September 15, 2012 00:06
Xcode 4.2 installed, but I need gcc-4.2
In a temporary directory:
curl -O http://opensource.apple.com/tarballs/gcc/gcc-5666.3.tar.gz
tar zxf gcc-5666.3.tar.gz
cd gcc-5666.3
mkdir -p build/obj build/dst build/sym
gnumake install RC_OS=macos RC_ARCHS='i386 x86_64' TARGETS='i386 x86_64' SRCROOT=`pwd` OBJROOT=`pwd`/build/obj DSTROOT=`pwd`/build/dst SYMROOT=`pwd`/build/sym
sudo ditto build/dst /
@mlevans
mlevans / gist:3318783
Created August 10, 2012 22:58
Get a chunk of 100,000 lines from a text file (from line 500000)
head -n 500000 larger_file.txt | tail -n 100000 > smaller_file.txt
@mlevans
mlevans / gist:3288218
Created August 7, 2012 18:43
Find Random Map Tiles in the United States
import random
import ModestMaps
# import whereami # this script borrows bits from whereami: https://github.com/migurski/whereami
# Using rough boundaries of the United States
lat_bounds = [32,41.5]
lng_bounds = [-116.5,-80]
num_of_places = 1000
@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)
@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 / 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 / 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
var π = Math.PI; // uni_pi = '\u03C0';
console.log(π);
// >> 3.141592653589793
@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; }