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 / index.html
Last active August 29, 2015 14:03
Map with TMS params
<!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;
@glenrobertson
glenrobertson / flask_cache_response_decorator.py
Last active January 15, 2022 21:15
Flask response cache decorator
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.
@glenrobertson
glenrobertson / index.html
Last active December 26, 2019 23:24
so tile much random wow
<!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">
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
@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;