Skip to content

Instantly share code, notes, and snippets.

View hampelm's full-sized avatar

Matt Hampel hampelm

View GitHub Profile
results = [(p1.address, p1.program), (p2.address, p2.program)]
grouped_results = {}
for elt in results:
if elt.address in grouped_results:
grouped_results[elt.address].append(elt.program)
else:
grouped_results[elt.address] = [elt.program]
# To print out the groupings:
@hampelm
hampelm / PostGIS Recipes
Created April 27, 2012 15:10
PostGIS Recipes
echo "CREATE USER project_name WITH PASSWORD \'password\';" | psql postgres
createdb -O project_name project_name -T template_postgis
ogr2ogr -f PostgreSQL PG:dbname=databasename infile.shp
SELECT parcels FROM detroit where ST_Touches(current_parcel, detroit.geometry_column)
where current_parcel is a polygon geometry object in PostGIS
and detroit.geometry_column is the name of the column in the database with the polygon objects
@hampelm
hampelm / gist:2722214
Created May 17, 2012 23:16
Parcel clustering algorithm
n = maximum number of parcels that can be in a cluster
Get list of parcels to survey.
Create an empty list of clusters.
Find top-leftmost parcel.
Find up to n-1 parcels that border that parcel.
Only select parcels with the same street name.
Only select parcels that aren't already in a cluster
Put the selected parcels in the same cluster.
<<<<<<< HEAD [aka the thing you just pulled]
hello
=======
goodbye
>>>>>>> experiment:... [aka your files]
library(ggplot2)
library(RJSONIO)
library(foreign)
input_dir = "~/projects/cfa/misc/stats/"
snow = read.csv(paste(input_dir, "snow_pot.csv", sep=""))
?read.csv
class(snow)
dim(snow)
library(ggplot2)
library(RJSONIO)
library(foreign)
input_dir = "~/projects/cfa/misc/stats/"
snow = read.csv("~/projects/cfa/misc/stats/snow_pot.csv")
props = read.dbf("~/projects/cfa/misc/stats/SeoncAuctionProperties/SecondAuctionProperties.dbf")
income = fromJSON("~/projects/cfa/misc/stats/medianIncomeByTract.json")
incomeEdu = fromJSON("~/projects/cfa/misc/stats/medianIncomesByEduAndTract.json")
@hampelm
hampelm / jquery.ba-tinypubsub.js
Created July 18, 2012 01:02 — forked from cowboy/HEY-YOU.md
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
/* jQuery Tiny Pub/Sub - v0.7 - 10/27/2011
* http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
(function($) {
var o = $({});
$.subscribe = function() {
o.on.apply(o, arguments);
@hampelm
hampelm / gist:3252667
Created August 3, 2012 23:30
expansion
render: ->
$(this.el).html this.template()
bookHTML = for book in Books
(new BookView model: book).render().el
this.$('.book_list').append bookHTML
({
render: function() {
var book, bookHTML;
/api/map/?points__within={ "type": "Polygon", "coordinates": [[[-125.363617, 48.656273], [-123.254242, 31.608656], [-77.902679, 26.068811], [-65.597992, 44.301984], [-125.363617, 48.656273]]]}
if(options.query != undefined) {
this.pages = new LW.collections.Pages(options.query);
}else {
this.pages = new LW.collections.Pages();
}