Skip to content

Instantly share code, notes, and snippets.

View andrewjennings's full-sized avatar

Andrew andrewjennings

  • Philadelphia, PA
View GitHub Profile
<?php
namespace Afj\CourseBundle\Twig;
use Afj\CourseBundle\Util\DateUtil;
class CourseExtension extends \Twig_Extension
{
public function getName()
{
@andrewjennings
andrewjennings / composer.lock
Created November 13, 2012 18:35
Composer lockfile for Training Day 2
{
"hash": "b601d90d37f9b93a4bfda3ba539ddda1",
"packages": [
{
"name": "doctrine/common",
"version": "2.3.x-dev",
"source": {
"type": "git",
"url": "https://github.com/doctrine/common",
"reference": "bb0aebbf234db52df476a2b473d434745b34221c"
@andrewjennings
andrewjennings / composer.json
Created November 13, 2012 18:34
Composer.json for training day 2
{
"name": "symfony/framework-standard-edition",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-0": { "": "src/" }
},
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.1.*",
"doctrine/orm": ">=2.2.3,<2.4-dev",
@andrewjennings
andrewjennings / get_mod.py
Created March 14, 2012 15:16
Grab a python module by name
def _get_service_by_name(self, service_name):
module, separator, class_name = service_name.rpartition('.')
m = __import__( module )
path = service_name.split('.')[1:]
for p in path:
m = getattr(m, p)
return m
@andrewjennings
andrewjennings / export_plan.sh
Created September 15, 2011 19:20
Exporting a plan to a shapefile
#!/bin/bash
# This will export the plan with id 1270, called "mf_exact", to
# a shapefile called mf_exact.shp
pgsql2shp -f mf_exact -u publicmapping -P <password_here> -h <hostname> publicmapping "select d.geom, d.name,
from redistricting_district as d
join (select max(version) as latest, district_id, plan_id from redistricting_district where plan_id = 1270 group by district_id, plan_id) as v on d.district_id = v.district_id and d.plan_id = v.plan_id and d.version = v.latest
where not (ST_IsEmpty(d.geom) or d.district_id = 0);"
@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
Index: /projects/publicmapping/trunk/django/publicmapping/redistricting/models.py
===================================================================
--- /projects/publicmapping/trunk/django/publicmapping/redistricting/models.py (revision 1404)
+++ /projects/publicmapping/trunk/django/publicmapping/redistricting/models.py (working copy)
@@ -413,19 +413,19 @@
# Searching inside the boundary
if level != base_geolevel:
# Search by geometry
- q_geom = Q(geom__within=boundary)
+ q_geom = Q(geom__within=boundary.buffer(1))
@andrewjennings
andrewjennings / calculators.diff
Created July 12, 2011 18:51
Add options to Contiguity calculators
Index: calculators.py
===================================================================
--- calculators.py (revision 1396)
+++ calculators.py (working copy)
@@ -788,6 +788,8 @@
count = 0
for district in districts:
+ if district.geom.empty:
+ continue