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 / lazy.sh
Created October 9, 2013 21:45
lazy.sh
function py {
if [ -e manage.py ]
then
ipython manage.py shell
else
ipython
fi
}
@glenrobertson
glenrobertson / TileLayer.GeoJSON.js
Last active August 2, 2021 07:11
Leaflet GeoJSON Tile Layer Example
// Load data tiles from an AJAX data source
L.TileLayer.Ajax = L.TileLayer.extend({
_requests: [],
_addTile: function (tilePoint) {
var tile = { datum: null, processed: false };
this._tiles[tilePoint.x + ':' + tilePoint.y] = tile;
this._loadTile(tile, tilePoint);
},
// XMLHttpRequest handler; closure over the XHR object, the layer, and the tile
_xhrHandler: function (req, layer, tile, tilePoint) {
@glenrobertson
glenrobertson / get_shit_albums.py
Last active December 18, 2015 16:48
Get the path names for all iTunes albums that I have with a total track play count of zero, where the album has between 3 and 50 tracks. This is so I can remove albums I don't care about to free up disk space
#!/usr/bin/python
import os
from appscript import app
itunes = app('iTunes')
# get all your tracks, takes a while
tracks = itunes.file_tracks()
# index all tracks by album name
tracks_by_album = {}
<!DOCTYPE html>
<html>
<head>
<title>GeoJSON Tile Layer</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.4.5/leaflet.css" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.4.5/leaflet.ie.css" />
<![endif]-->
<script src="http://cdn.leafletjs.com/leaflet-0.4.5/leaflet.js"></script>
@glenrobertson
glenrobertson / geojson-tiles.js
Created December 7, 2012 00:57 — forked from lxbarth/geojson-tiles.js
GeoJSON Leaflet Tile Layer
// Load tiled GeoJSON and merge into single geojson hash.
// Requires jQuery for jsonp.
L.TileLayer.GeoJSON = L.TileLayer.extend({
_geojson: {"type":"FeatureCollection","features":[]},
_requests: [],
geojson: function() {
if (this._geojson.features.length) return this._geojson;
for (k in this._tiles) {
var t = this._tiles[k];
if (t.geojson && t.geojson.features) {
@glenrobertson
glenrobertson / ec2_modify_instance_type.sh
Created November 25, 2012 21:28
bash function to change an ec2 instance type, given instance-id and instance-type parameters
# shuts down an instance-id $1, modifies the instance type $2, starts the instance-id $1
function ec2-modify-instance-type {
instanceId=$1;
instanceType=$2;
ec2-stop-instances $instanceId;
while [[ `ec2-modify-instance-attribute --instance-type $instanceType $instanceId | grep ^instanceType | wc -l | awk '{print $1}'` == 0 ]];
do echo 'waiting';
done;
echo 'done';
ec2-start-instances $instanceId;
@glenrobertson
glenrobertson / leaflet-geojson-gpolydecode.js
Created November 13, 2012 03:11
Handling for Google encoded polygons inside GeoJSON in Leaflet
// extend GeoJSON to handle google-encoded linestrings
// assumes that any array of coordinates that make up a linestring are replaced with the google encoded line string
L.extend(L.GeoJSON, {
// This function is from Google's polyline utility.
// Borrowed from: http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/decode.js
// Changed to return lng/lats instead of lat/lngs
decodeLine: function (encoded) {
var len = encoded.length;
var index = 0;
var array = [];
@glenrobertson
glenrobertson / nested_map.py
Created November 12, 2012 09:56
Apply function to items in nested list/tuple
def nested_map(self, collection, func):
if type(collection) == list:
return [nested_map(i, func) for i in collection]
elif type(collection) == tuple:
return tuple([nested_map(i, func) for i in collection])
else:
return func(collection)
@glenrobertson
glenrobertson / index.html
Created October 10, 2012 21:41
Leaflet Map with a marker
<!DOCTYPE html>
<html>
<head>
<title>Leaflet Markers</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.4.3/leaflet.css" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.4.3/leaflet.ie.css" />
<![endif]-->
<script src="http://cdn.leafletjs.com/leaflet-0.4.3/leaflet.js"></script>
<style type="text/css">
@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