This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function py { | |
if [ -e manage.py ] | |
then | |
ipython manage.py shell | |
else | |
ipython | |
fi | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |