Skip to content

Instantly share code, notes, and snippets.

@ghing
ghing / server.py
Created April 30, 2013 13:16
Send OpenNI skeleton data over a websocket. Uses gevent-websocket for the websockety things.
#!/usr/bin/env python
## The equivalent of:
## "Working with the Skeleton"
## in the OpenNI user guide.
"""
This shows how to identify when a new user is detected, look for a pose for
that user, calibrate the users when they are in the pose, and track them,
sending updates about joint position over a websocket.
from haystack import indexes
# The easiest, per-object approach.
class CustomSearchIndex(indexes.SearchIndex, indexes.Indexable):
# The usual fields.
def prepare(self, obj):
prepared = super(CustomSearchIndex, self).prepare(obj)
@cspanring
cspanring / tastyhacks.py
Created February 8, 2012 18:25
Add GeoJSON support for geometry fields in django-tastypie
# Shamelessly stolen from https://github.com/newsapps/django-boundaryservice/blob/master/boundaryservice/tastyhacks.py
from django.contrib.gis.db.models import GeometryField
from django.utils import simplejson
from tastypie.bundle import Bundle
from tastypie.fields import ApiField, CharField
from tastypie.resources import ModelResource
@unixcharles
unixcharles / backbone.iframe.sync.js
Created October 11, 2011 14:14
Backbone.sync implementation that use iframe + multipart/form-data
(function () {
Backbone.syncWithoutUpload = Backbone.sync
Backbone.syncWithUpload = function(method, model, options) {
// Create iframe
var iframe_id = 'file_upload_iframe_' + Date.now()
, iframe = jQuery('<iframe id="' + iframe_id + '" name="' + iframe_id + '" ></iframe>').hide()
// Create an hidden form
var authToken = jQuery('meta[name=csrf-token]').attr('content')
, authParam = jQuery('meta[name=csrf-param]').attr('content')
@andrewjennings
andrewjennings / views.diff
Created July 28, 2011 17:49
Log request times
Index: views.py
===================================================================
--- views.py (revision 1402)
+++ views.py (working copy)
@@ -1143,6 +1143,8 @@
A JSON HttpResponse that contains the number of districts modified,
or an error message if adding fails.
"""
+ start = datetime.now()
+ sys.stderr.write('Received request at %s\n' % start)
OH State Senate
District 23 - Block in wrong district in CSV at line 251513
390351171011005,023 -> 390351171011005,025
District 11 - Not quite touching the water block. Needs a contiguity override
390950097002036 connected to 390950097003000
OH State House
District 49 - should be same override as Senate 11
@andrewjennings
andrewjennings / renest.sql
Created July 27, 2011 14:48
Re-nest geometries for Ohio
-- Gather the county geometries from the blocks
select b.id, b.name, st_union(a.geom) as geom into temp new_county_geoms from redistricting_geounit as a join redistricting_geounit as b on a.geom && b.geom where b.geolevel_id = 3 and a.geolevel_id = 1 and position(b.portable_id in a.portable_id) = 1 group by b.id, b.name;
-- Index the id column for a faster join when updating
create index new_county_id on new_county_geoms (id);
-- Update your counties
update redistricting_geounit as a set geom = multi(b.geom) from new_county_geoms as b where a.id = b.id;
-- Gather the place geometries from the blocks
anonymous
anonymous / pgis_tips.txt
Created July 8, 2011 20:53
PostGIS tips - Use at your own risk!
Database machine
Install postgres and postgis
make sure you can log on via md5 in pg_hba.conf
check listen addresses in postgresql.conf
set kernel parameters in sysctl.conf to allow for larger shared memory - http://www.postgresql.org/docs/8.3/static/kernel-resources.html
kernel.shmmax=2684354560
kernel.shmall=2097152