Skip to content

Instantly share code, notes, and snippets.

Avatar

Hannes Hapke hanneshapke

View GitHub Profile
View install_postgis_osx.sh
# 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 Jun 11, 2015
Lightning Talk: SQLAlchemy question for PUB (June 2015)
View flask_m2m_problem.py
'''
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.
View redis.config
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 / query_comparison.shell
Created Apr 15, 2013
Query comparison between Point and Polygon geometries
View query_comparison.shell
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 Apr 15, 2013
PostGreSQL/PostGIS query for closest point to giving location > raw SQL Django query
View query.shell
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]
View keras_bidirectional_tagger.py
# 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
View keras_bidirectional_tagger.py
# 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 / celery.sh
Last active Aug 23, 2017 — forked from amatellanes/celery.sh
Celery handy commands
View celery.sh
/* 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 / model.py
Last active Apr 16, 2018
Model definition for the CNN Visualization Demo
View model.py
sequence_input = Input(shape=(maxlen_text,))
x = Embedding(name='embedding_layer',
input_dim=max_words_to_keep,
output_dim=token_vec_size,
input_length=maxlen_text)(sequence_input)
x = Dropout(.20)(x)
x = Conv1D(64, 5, activation='relu', name='1-conv1d', padding='same')(x)
x = MaxPooling1D(pool_size=4)(x)
@hanneshapke
hanneshapke / extract_layer.py
Last active Apr 16, 2018
Extract Keras layers by layer name
View extract_layer.py
def get_conv_layer(model, layer_name):
conv_layer = model.get_layer(layer_name)
output_dim = conv_layer.output_shape[1]
return conv_layer, output_dim
You can’t perform that action at this time.