Skip to content

Instantly share code, notes, and snippets.

View glenrobertson's full-sized avatar
💭
Taking the specifications from the customer to the Software Engineers

Glen Robertson glenrobertson

💭
Taking the specifications from the customer to the Software Engineers
View GitHub Profile
@glenrobertson
glenrobertson / auto-restart-gunicorn.sh
Created August 1, 2012 22:17
auto restart gunicorn
pip install watchdog
watchmedo auto-restart --directory=. ./manage.py -- run_gunicorn --workers=15
@glenrobertson
glenrobertson / osmosis_polygon_to_django_multipolygon.py
Created August 6, 2012 00:02
osmosis_polygon_to_django_multipolygon
from django.contrib.gis.geos import MultiPolygon, Polygon, LinearRing
def to_mpoly(osmosis_file):
""" Parse an Osmosis polygon filter file
Accept a sequence of lines from a polygon file,
return a django.contrib.gis.MultiPolygon object.
http://wiki.openstreetmap.org/wiki/Osmosis/Polygon_Filter_File_Format
@glenrobertson
glenrobertson / L.Icon.Hover.js
Created August 19, 2012 23:06
leaflet icon hover class
L.Icon.Hover = L.Icon.extend({
options: {
iconSize: new L.Point(25, 41),
iconAnchor: new L.Point(13, 41),
popupAnchor: new L.Point(1, -34),
shadowSize: new L.Point(41, 41)
},
@glenrobertson
glenrobertson / geojson_serializer.py
Created August 20, 2012 22:43
GeoJSON serializer for Geodjango
"""
Modified from: https://gist.github.com/967274
CHANGES:
* Serialize pk in feature.id and remove from feature.properties
* Added default date format and time format for encoder
* Allow geometryfield option, which doesn't have to be a field, e.g. a @property
USAGE:
@glenrobertson
glenrobertson / fadeColour.js
Created August 25, 2012 07:37
animate colour change with a callback in javascript
// create div and call animate on it, from start to end colour for the duration
// for each step of the colour change, invoke the callback
function fadeColour(start_colour, end_colour, duration, callback) {
var ele = $('<div></div>');
$(ele).css('color', start_colour);
$(ele).animate({
color: end_colour
}, {
duration: duration,
@glenrobertson
glenrobertson / cool_story_bro.md
Created August 30, 2012 22:15
git access behind http proxy

I shouldn't have to do this shit..

  1. Install corkscrew

  2. Setup corkscrew auth file

     echo your_proxy_username:your_proxy_password > ~/.corkscrew_auth
    
  3. Add to ~/.ssh/config

@glenrobertson
glenrobertson / EditableCircleMarker.js
Created September 5, 2012 05:17
leaflet editable circle with marker
/*
L.EditableCircleMarker is a marker with a radius
The marker can be moved and the radius can be changed
*/
L.EditableCircleMarker = L.Class.extend({
includes: L.Mixin.Events,
options: {
weight: 1,
@glenrobertson
glenrobertson / TileLayer.GeoJSON.js
Created September 15, 2012 00:02
GeoJSON Leaflet Tile Layer
/*
GeoJSON layer with mouse hover events to properties for each feature
Requires JQuery to handle the AJAX requests
Currently only supports FeatureCollections
Features must have ID's, so they can be deduplicated across tiles (not rendered twice).
*/
/*
Control that shows HTML content for a point on hover
*/
@glenrobertson
glenrobertson / image_gradient_view.py
Created September 15, 2012 00:36
Image gradient Django view
"""
Django view to generate a gradient image.
Inputs:
* colour_model: "rgb" or "hsl"
* direction: "horizontal" or "vertical"
* start_rgb: hex colour string, e.g: #BADA55
* end_rgb: hex colour string, e.g: #BEEFED
* width: image pixel height
* height: image pixel width
@glenrobertson
glenrobertson / geo_hstore_manager.py
Created October 4, 2012 21:35
Combine Django GeoManager with HStoreManager
# pip install django-orm-extensions
from django.contrib.gis.db.models.query import GeoQuerySet
from django.contrib.gis.db.models import GeoManager
from django_orm.postgresql.hstore.queryset import HStoreQuerySet
from django_orm.postgresql.hstore.manager import HStoreManager
class GeoHStoreQuerySet(GeoQuerySet, HStoreQuerySet):
pass