This file contains hidden or 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></title> | |
| <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" /> | |
| <script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script> | |
| <style type="text/css"> | |
| html, body, #map { | |
| margin: 0; | |
| padding: 0; |
This file contains hidden or 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
| import datetime | |
| import time | |
| from functools import wraps | |
| from wsgiref.handlers import format_date_time | |
| from flask import make_response | |
| def cache(expires=None, round_to_minute=False): | |
| """ | |
| Add Flask cache response headers based on expires in seconds. |
This file contains hidden or 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>Stupid Map</title> | |
| <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css" /> | |
| <!--[if lte IE 8]> | |
| <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.ie.css" /> | |
| <![endif]--> | |
| <script src="http://cdn.leafletjs.com/leaflet-0.7/leaflet.js"></script> | |
| <style type="text/css"> |
This file contains hidden or 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
| class MovingAverage: | |
| total_sum = 0 | |
| total_count = 0 | |
| def add_number(self, num): | |
| self.total_sum += num | |
| self.total_count += 1 | |
| def get_average(self): | |
| return self.total_sum / self.total_count |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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; |