Skip to content

Instantly share code, notes, and snippets.

@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
@isaacs
isaacs / node-and-npm-in-30-seconds.sh
Last active March 8, 2024 02:11
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@justintv
justintv / .bashrc
Created August 17, 2009 00:53
Display git branch in bash prompt
# If you work with git, you've probably had that nagging sensation of not knowing what branch you are on. Worry no longer!
export PS1="\\w:\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)\$ "
# This will change your prompt to display not only your working directory but also your current git branch, if you have one. Pretty nifty!
# ~/code/web:beta_directory$ git checkout master
# Switched to branch "master"
# ~/code/web:master$ git checkout beta_directory
# Switched to branch "beta_directory"