Skip to content

Instantly share code, notes, and snippets.

@nbessi
nbessi / gist:1200785
Created September 7, 2011 14:54
GeoEngine CRUD support phase 1
from shapely.wkt import dumps as wktdumps, loads as wktloads
from shapely.geometry import Polygon, MultiPolygon
import geojson
from base_geoengine import geo_model
class NPA(geo_model.GeoModel):
_inherit = "res.better.zip"
_columns = {
'the_geom' : fields.geo_multi_polygon('NPA Shape', required=False),
@nbessi
nbessi / gist:1270572
Created October 7, 2011 15:42
GeoEngine Relational ORM support
print self.geo_search(cursor, uid, domain=[('name', 'ilike', 'Lausanne')], geo_domain=[('the_geom', 'geo_greater', Polygon([(3, 0), (4, 1), (4, 0)]))])
print self.geo_search(cursor, uid, domain=[('name', 'ilike', 'Lausanne')], geo_domain=[('the_geom', 'geo_greater', 0)])
print self.geo_search(cursor, uid, domain=[('name', 'ilike', 'Lausanne')], geo_domain=[('the_geom', 'geo_intersect', {'geoengine.demo.automatic.retailing.machine.the_point': []})])
print self.geo_search(cursor, uid, domain=[('name', 'ilike', 'Lausanne')], geo_domain=[('the_geom', 'geo_intersect', {'geoengine.demo.automatic.retailing.machine.the_point': [('name','!=','Vallorbe')]})])
#will generate
"""
SELECT "res_better_zip".id FROM "res_better_zip" WHERE (res_better_zip."name" ilike E'%Lausanne%') AND ST_Area(res_better_zip.the_geom) > ST_Area(ST_GeomFromText('POLYGON ((3.0000000000000000 0.0000000000000000, 4.0000000000000000 1.0000000000000000, 4.0000000000000000 0.0000000000000000, 3.0000000000000000 0.0000000000000000))')) ORDER BY pr
@nbessi
nbessi / gist:1351717
Created November 9, 2011 15:11
Decorator with boilerplate for OSV methods.
#Thanks to Florent for the function.
#Really useful.
def osv_method(f):
"""Decorator with boilerplate for OSV methods."""
args, varargs, kwargs, defaults = getargspec(f)
len_argspec = len(args) - 4
# Sanity check: no *args or **kwargs parameters
@kennethreitz
kennethreitz / pr.md
Created September 12, 2012 20:56 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this: