Skip to content

Instantly share code, notes, and snippets.

View mapmeld's full-sized avatar

Nick Doiron mapmeld

  • Chicago, IL
View GitHub Profile
@mapmeld
mapmeld / blockeeShareFeature.js
Created August 12, 2012 06:06
Blockee Share Feature
/*
* Manages Share Button.
*/
var ShareFeature = {
show: function() {
var longUrl = "http://blockee.org" + Backbone.history.fragment;
var url = "http://api.bitly.com/v3/shorten?longUrl=" + encodeURIComponent(longUrl) + "&login=o_cdttlflq9&apiKey=R_54cc6bcddf5bd50607743cc8158d722f";
$.getJSON(url, function(data) {
@mapmeld
mapmeld / GrabBlockee.js
Created August 18, 2012 04:34
GrabBlockee.js
// grab background: StreetView or uploaded
// 600 x 435 pixels
var bg = $('canvas')[1].parentNode.style.backgroundImage.substring(4);
bg = bg.substring(0, bg.length - 1);
var bgimage = new Image();
bgimage.onload = function(){
// grab image from foreground canvas
// 600 x 435 pixels to avoid menus
var uppercanv = $('canvas')[1].getContext('2d').getImageData(0, 0, 600, 435);
@mapmeld
mapmeld / OSM-Nework-Build.py
Created August 23, 2012 00:28
OSM-Network-Build.py
# OSM Points and Streets
# Build from nodes and ways
# For each way, add them to Streets
## Flag each node with the Street's ID
## If Street shares a node with a previous Street, build a connectsto relation between the two
# Optional firstToAdd parameter lets you pick up networking where you left off
firstToAdd = None
# firstToAdd = "featherdr"
@mapmeld
mapmeld / HouseNet.py
Created August 24, 2012 19:34
Upload housing cases into Neo4j graph database. Link them to their streets
# HouseNet.py
# upload housing cases into the graph database
import urllib, urllib2
cases = open('PROP1Cleanest.csv', 'r')
streetids = { }
skipto = "1903 houstonave";
skipcount = 0
for line in cases:
# add cases to neo4j
@mapmeld
mapmeld / NetworkAdder.py
Created August 25, 2012 23:00
Adding street network to cases prediction data
# HouseNet.py
# upload housing cases into the graph database
import urllib, urllib2
cases = open('cases-predicted.csv', 'r')
caseout = open('PROP1NetworkedResults.csv', 'w')
streetids = { }
streetmatches = { }
skipto = "1903 houstonave";
skipcount = 0
@mapmeld
mapmeld / NetworkStats.py
Created August 26, 2012 03:33
Collecting stats from networks
# NetworkStats.py
# compare demolition count (on network level) to other cases (on network level)
import urllib, urllib2
skipcount = 0
countable = 'class="point"'
neighbortotals = []
demototals = []
ratiototals = []
streetid = skipcount
countsbystreetid = { }
@mapmeld
mapmeld / PredictPrep-2yr.py
Created August 26, 2012 08:16
PredictPrep-2years
# Predict Cases
# Prepare housing cases CSV for Google Prediction API
# Now associates a case with where it is in three more years, not the ultimate result
# for example
# "Some", 19960909, Cut and Cleared
# "None", 19980101, Cut and Cleared
# "None", 19980202, No Violations (not predicted by previous because there were no violations)
# "Demolished", 20020808, Repaired (prediction should be demolished because demo comes in < 2 years)
# "Demolished", 20030101, Demolished
@mapmeld
mapmeld / Census2TennisRacket.py
Created September 2, 2012 04:18
Census2TennisRacket
# for GridMapper and GridMapAuth:
# Combine a custom grid and Census 2010 blocks shapefile in QGIS
# Run script
# Output JSON object with Census blocks overlapped by each grid
def squareName(i, j):
letter = chr(65+i)
return letter + str(j + 1)
# get the active layer (Census blocks)
@mapmeld
mapmeld / BlockInfo.py
Created September 2, 2012 05:36
BlockInfo
# Quick QGIS scripts to extract housing and population data from Census blocks
# get the active layer (Census blocks)
from PyQt4 import QtCore
activeLayer = qgis.utils.iface.activeLayer()
provider = activeLayer.dataProvider()
allAttrs = provider.attributeIndexes()
provider.select(allAttrs)
feat = QgsFeature()
while provider.nextFeature(feat):
@mapmeld
mapmeld / GeoJSON-USA.js
Created September 3, 2012 19:08
GeoJSON in Khan Academy CS
// Put your GeoJSON at the beginning
// Here are some more countries and each US state: https://github.com/johan/world.geo.json/tree/master/countries
// scroll to the bottom to write your own program, add images by latitude and longitude, and more
// Questions? Tweet to @mapmeld
var geojson = {"type":"FeatureCollection","features":[
{"type":"Feature","properties":{"name":"United States of America"},"geometry":{"type":"MultiPolygon","coordinates":[[[[-94.81758,49.38905],[-94.64,48.84],[-94.32914,48.67074],[-93.63087,48.60926],[-92.61,48.45],[-91.64,48.14],[-90.83,48.27],[-89.6,48.01],[-89.272917,48.019808],[-88.378114,48.302918],[-87.439793,47.94],[-86.461991,47.553338],[-85.652363,47.220219],[-84.87608,46.900083],[-84.779238,46.637102],[-84.543749,46.538684],[-84.6049,46.4396],[-84.3367,46.40877],[-84.14212,46.512226],[-84.091851,46.275419],[-83.890765,46.116927],[-83.616131,46.116927],[-83.469551,45.994686],[-83.592851,45.816894],[-82.550925,45.347517],[-82.337763,44.44],[-82.137642,43.571088],[-82.43,42.98