Skip to content

Instantly share code, notes, and snippets.

Hannes Hapke hanneshapke

Block or report user

Report or block hanneshapke

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View redis.config
gcc-c++: []
make: []
command: make
cwd: /home/ec2-user/redis-2.8.4
hanneshapke /
Created Jun 11, 2015
Lightning Talk: SQLAlchemy question for PUB (June 2015)
This code example is a little gist example of the m2m problem
I am facing with flask and sqlalchemy. The purpose of this short
code sample is to select one or many grocery lists (List) based
on the grocery items (Grocery).
All query examples return either an empty list or all lists which contain
any of the items (OR selection instead of AND)
Below I have listed three approaches I have tried without any luck.
# Some good references are:
#1. Install PostgreSQL postgis and postgres
brew install postgis
initdb /usr/local/var/postgres
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
hanneshapke /
Created Apr 15, 2013
PostGreSQL/PostGIS query for closest point to giving location > raw SQL Django query
data_point = WindData.objects.raw('SELECT * FROM meteo_winddata ORDER BY location <-> ST_SetSRID(ST_MakePoint(%s, %s),4326) LIMIT 1', [location.x, location.y])[0]
hanneshapke /
Created Apr 15, 2013
Query comparison between Point and Polygon geometries
In [1]: data_point = WindData.objects.raw('SELECT * FROM meteo_winddata ORDER BY geom <-> ST_SetSRID(ST_MakePoint(%s, %s),4326) LIMIT 1', [foo.location.x, foo.location.y])[0]
DEBUG (0.282) SELECT * FROM meteo_winddata ORDER BY geom <-> ST_SetSRID(ST_MakePoint( -0.12574, 51.50853),4326) LIMIT 1; args=[-0.12574, 51.50853]
In [2]: data_point = WindDataPolygon.objects.get(geom__intersects = foo.location)
DEBUG (0.003) SELECT "meteo_winddatapolygon"."id", "meteo_winddatapolygon"."lat", "meteo_winddatapolygon"."lng", "meteo_winddatapolygon"."windspeed", "meteo_winddatapolygon"."geom" FROM "meteo_winddatapolygon" WHERE ST_Intersects("meteo_winddatapolygon"."geom", ST_GeomFromEWKB('\x0101000020e6100000f146e6913f18c0bf7784d38217c14940'::bytea)); args=(<django.contrib.gis.db.backends.postgis.adapter.PostGISAdapter object at 0x11080f810>,)
You can’t perform that action at this time.