Skip to content

Instantly share code, notes, and snippets.

@doug
doug / video-dat.py
Created March 2, 2011 21:46
serve webm files on app engine
#!/usr/bin/env python
#
import os
import urllib
from google.appengine.ext import blobstore
from google.appengine.ext import webapp
from google.appengine.ext.webapp import blobstore_handlers
from google.appengine.ext.webapp import template
@doug
doug / pixelsperem.py
Created April 8, 2011 09:58
pixels per em
def pixels_per_em(fontsize=12, resolution=72):
return fontsize*(resolution/72.0)
@doug
doug / gist:971302
Created May 13, 2011 20:53
select a object by id number in gql
SELECT * FROM Object where __key__ = KEY('Object', 1)
@doug
doug / dump_json.py
Created September 5, 2012 22:41
dump json with extras
import json
import datetime
import time
def json_extras(obj):
if hasattr(obj, 'utctimetuple'):
ms = time.mktime(obj.utctimetuple()) * 1000
ms += getattr(obj, 'microseconds', 0) / 1000
return int(ms)
return None
@doug
doug / http.js
Created October 11, 2012 18:38
simple http request for json
// Do checks for minimum requirements
if (!XMLHttpRequest || !JSON) {
throw Error('Browser does not support the minimum requirements of ' +
'XMLHttpRequest, JSON' +
'. Try adding modernizer to polyfill.');
}
function http(method, url, data, success) {
var r = new XMLHttpRequest();
r.open(method, url, true);
@doug
doug / gaeutils.py
Created April 19, 2013 23:18
gae utils
from google.appengine.ext import db
from google.appengine.api import memcache, users
import logging
import functools
import datetime, time
import sys, os, re
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
@doug
doug / sparkline.svg
Created June 12, 2013 20:36
Simple svg sparkline from http://kryogenix.org/days/2012/12/30/simple-svg-sparklines <object src="sparkline.svg?1,3,4,4,1,2" width=100 height=15></object>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@doug
doug / cors.xml
Created June 19, 2013 00:01
cors.xml for cross domain serving of videos
<?xml version="1.0" ?>
<CorsConfig>
<Cors>
<Origins>
<Origin>*</Origin>
</Origins>
<Methods>
<Method>GET</Method>
<Method>HEAD</Method>
<Method>OPTIONS</Method>
@doug
doug / autodeploy.zsh
Last active December 18, 2015 16:59
Poll git repo and deploy to app engine when git hooks are not possible.
# iterate through all git repos in projects folder
# fetch for any changes to remote
# for each branch, if it is different pull the changes and deploy
echo "Starting"
while true; do
for project in $(ls projects); do
echo "Checking for updates to $project"
cd "projects/$project"
branches=$(git remote -v update 2>&1 | grep -oEi "^\W+.*\w+$" | grep -v "up to date" | grep -oEi "\w+$")
@doug
doug / Guardfile
Last active December 27, 2015 11:58
Recursive watch Guardfile example
#!/usr/bin/env python
# AppEngine Guardfile
# More info at https://github.com/lepture/python-livereload
from livereload.task import Task
from livereload.compiler import shell
def recursive_watch(directory, filetypes, *args, **kwargs):
import os