Skip to content

Instantly share code, notes, and snippets.

💭
Taking the specifications from the customer to the Software Engineers

Glen Robertson glenrobertson

💭
Taking the specifications from the customer to the Software Engineers
Block or report user

Report or block glenrobertson

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@glenrobertson
glenrobertson / extract_digits.py
Created Jun 11, 2017
Convert transcript to list of digits
View extract_digits.py
import sys
import re
words_to_digits = {
'zero': 0,
'one': 1,
'two': 2,
'three': 3,
'four': 4,
'five': 5,
@glenrobertson
glenrobertson / ballgametoday.py
Last active Sep 10, 2016
Ball game today AWS lambda slack webhook
View ballgametoday.py
import boto3
from base64 import b64decode
from urlparse import parse_qs
import logging
import urllib2
import json
logger = logging.getLogger()
logger.setLevel(logging.INFO)
@glenrobertson
glenrobertson / data_required_if.py
Created Jun 15, 2015
Conditional DataRequired wtforms validator
View data_required_if.py
class DataRequiredIf(wtforms.validators.DataRequired):
"""
Similar to DataRequired
Only evaluates if func(form.data) evaluates to True
"""
def __init__(self, func, *args, **kwargs):
super(DataRequiredIf, self).__init__(*args, **kwargs)
self.func = func
def __call__(self, form, field):
@glenrobertson
glenrobertson / index.html
Last active Aug 29, 2015
Map with TMS params
View index.html
<!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 Jun 30, 2019
Flask response cache decorator
View flask_cache_response_decorator.py
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 Aug 29, 2015
so tile much random wow
View index.html
<!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">
View moving_average.py
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
View lazy.sh
function py {
if [ -e manage.py ]
then
ipython manage.py shell
else
ipython
fi
}
@glenrobertson
glenrobertson / TileLayer.GeoJSON.js
Last active May 20, 2019
Leaflet GeoJSON Tile Layer Example
View TileLayer.GeoJSON.js
// 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 Dec 18, 2015
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
View get_shit_albums.py
#!/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 = {}
You can’t perform that action at this time.