Skip to content

Instantly share code, notes, and snippets.

View hanneshapke's full-sized avatar

Hannes Hapke hanneshapke

View GitHub Profile
@hanneshapke
hanneshapke / query_comparison.shell
Created April 15, 2013 13:51
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>,)
@hanneshapke
hanneshapke / query.shell
Created April 15, 2013 14:00
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]
# Some good references are:
# http://russbrooks.com/2010/11/25/install-postgresql-9-on-os-x
# http://www.paolocorti.net/2008/01/30/installing-postgis-on-ubuntu/
# http://postgis.refractions.net/documentation/manual-1.5/ch02.html#id2630392
#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
hanneshapke / flask_m2m_problem.py
Created June 11, 2015 12:14
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.
packages:
yum:
gcc-c++: []
make: []
sources:
/home/ec2-user: http://download.redis.io/releases/redis-2.8.4.tar.gz
commands:
redis_build:
command: make
cwd: /home/ec2-user/redis-2.8.4
@hanneshapke
hanneshapke / Editable Fields with ReactJS and ES2015
Last active June 21, 2019 12:26
Simple editable field with ReactJS and ES2015
### Try it out with JSBin
(JSBin)[http://jsbin.com/dijefajalo/edit?html,js,console,output]
@hanneshapke
hanneshapke / track_celery.py
Created July 22, 2016 03:41
Decorator for Celery functions to measure the execution time and memory usage
import time
from memory_profiler import memory_usage
import logging
celery_logger = logging.getLogger('celery')
def track_celery(method):
"""
@hanneshapke
hanneshapke / celery.sh
Last active August 23, 2017 16:22 — forked from amatellanes/celery.sh
Celery handy commands
/* Useful celery config.
app = Celery('tasks',
broker='redis://localhost:6379',
backend='redis://localhost:6379')
app.conf.update(
CELERY_TASK_RESULT_EXPIRES=3600,
CELERY_QUEUES=(
Queue('default', routing_key='tasks.#'),
@hanneshapke
hanneshapke / keras_bidirectional_tagger.py
Created April 6, 2017 22:42 — forked from dirko/keras_bidirectional_tagger.py
Keras bidirectional LSTM NER tagger
# Keras==1.0.6
from keras.models import Sequential
import numpy as np
from keras.layers.recurrent import LSTM
from keras.layers.core import TimeDistributedDense, Activation
from keras.preprocessing.sequence import pad_sequences
from keras.layers.embeddings import Embedding
from sklearn.cross_validation import train_test_split
from keras.layers import Merge
from keras.backend import tf
@hanneshapke
hanneshapke / keras_bidirectional_tagger.py
Created April 6, 2017 22:42 — forked from dirko/keras_bidirectional_tagger.py
Keras bidirectional LSTM NER tagger
# Keras==1.0.6
from keras.models import Sequential
import numpy as np
from keras.layers.recurrent import LSTM
from keras.layers.core import TimeDistributedDense, Activation
from keras.preprocessing.sequence import pad_sequences
from keras.layers.embeddings import Embedding
from sklearn.cross_validation import train_test_split
from keras.layers import Merge
from keras.backend import tf