Skip to content

Instantly share code, notes, and snippets.

View albertsun's full-sized avatar

Albert Sun albertsun

View GitHub Profile
@albertsun
albertsun / gist:674563
Created November 12, 2010 19:44
Parse GeoJSON for Raphael
var allPolygons = [];
function setPolys(geom) {
/* geom: a GeoJSON object.
Parse geom, and add it as a child to the global Raphael object, R.
*/
//geom.type either Polygon or MultiPolygon
var translationFunction = function(coords) {
var projected = Projections.contiguous.forward(coords);
var x = 217+(projected[0]*190/2400000);
==> Downloading http://postgis.refractions.net/download/postgis-1.5.2.tar.gz
File already downloaded in /Users/albert/Library/Caches/Homebrew
/usr/bin/tar xf /Users/albert/Library/Caches/Homebrew/postgis-1.5.2.tar.gz
==> ./configure --disable-dependency-tracking --prefix=/usr/local/Cellar/postgis/1.5.2 --with-projdir=/usr/local
./configure --disable-dependency-tracking --prefix=/usr/local/Cellar/postgis/1.5.2 --with-projdir=/usr/local
configure: WARNING: unrecognized options: --disable-dependency-tracking
checking build system type... i386-apple-darwin10.7.0
checking host system type... i386-apple-darwin10.7.0
checking for gcc... /usr/bin/cc
checking whether the C compiler works... yes
Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected dylibs:
/usr/local/lib/libfreenect.0.0.1.dylib
/usr/local/lib/libfreenect_sync.0.0.1.dylib
/usr/local/lib/libntfs-3g.54.0.0.dylib
/usr/local/lib/libntfs.9.0.0.dylib
@albertsun
albertsun / linebreaks_wp.py
Created August 21, 2011 05:44
Python port of WordPress's wpautop filter
import re
from django import template
from django.utils.functional import allow_lazy
from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe, SafeData
from django.utils.encoding import force_unicode
from django.utils.html import escape
from django.utils.text import normalize_newlines
register = template.Library()
@albertsun
albertsun / calculate_pareto_median.py
Created September 27, 2011 18:18
Pareto Interpolation
# http://en.wikipedia.org/wiki/Pareto_interpolation
# Example Pareto interpolation to calculate household median income.
# Assumes that incomedata is a list of 17 elements containing table B19001 from the United States ACS 5-year summary file
from math import log
def calculate_median(incomedata):
bucket_tops = [10000, 15000, 20000, 25000, 30000, 35000, 40000, 45000, 50000, 60000, 75000, 100000, 125000, 150000, 200000]
total = incomedata[0]
for i in range(2,18):
@albertsun
albertsun / vectortilemaptype.js
Created November 1, 2011 21:08
VectorTileMapType
/*
VectorTileMapType implementing the Google Maps API V3 MapType Interface
http://code.google.com/apis/maps/documentation/javascript/maptypes.html#MapTypeInterface
Used for http://censusmapmaker.com/
*/
function VectorTileMapType() {
this.minZoom = 13;
this.maxZoom = 18;
}
@albertsun
albertsun / query.js
Created November 1, 2011 21:09
LoadCensusBlockTiles
/* Author: Albert Sun
WSJ.com News Graphics
*/
/*jslint white: false, nomen: false, debug: false, devel: true, onevar: false, plusplus: false, browser: true, bitwise: false, es5: true, maxerr: 200 */
/*global jQuery: false, $: false, log: false, window: false, WSJNG: false, _: false, google: false, localStorage: false */
// Necessary functions
if (!window.typeOf) {
window.typeOf = function(b){var a=typeof b;if(a==="object")if(b){if(b instanceof Array)a="array"}else a="null";return a};
@albertsun
albertsun / views.py
Created November 1, 2011 21:10
geojson tiles views.py
from redistricting.apps.features.models import CensusBlock, CensusTract, CensusCounty, DataBlock
from redistricting.utils import gmerc
from django.http import HttpResponse, Http404, HttpResponseForbidden
from django.contrib.gis.geos import GEOSGeometry
from django.shortcuts import render_to_response
from django.template.loader import render_to_string
from django.template import RequestContext
@albertsun
albertsun / models.py
Created November 1, 2011 21:10
census data models.py
from django.contrib.gis.db import models
# generated by running ogrinspect against shapefiles
# ./manage.py ogrinspect ../state_tabblock_shapefiles/tl_2010_01_tabblock10/tl_2010_01_tabblock10.shp CensusBlock --srid=4326 --mapping --multi
# ./manage.py ogrinspect ../state_tract_shapefiles/tl_2010_01_tract10/tl_2010_01_tract10.shp CensusTract --srid=4326 --mapping --multi
class CensusBlock(models.Model):
statefp10 = models.CharField(max_length=2)
countyfp10 = models.CharField(max_length=3)
@albertsun
albertsun / hackshackerspresentation.txt
Created November 1, 2011 21:14
How We Made Our Maps Links
How We Made Our Maps
http://meetupnyc.hackshackers.com/events/37680122/
Presentation Links
http://censusmapmaker.com/draw/
http://redistrictinggame.org/launchgame.php?level=basic&mission=1
http://www.publicmapping.org/