Skip to content

Instantly share code, notes, and snippets.

@doug
doug / compose.go
Last active August 29, 2015 14:02
Compose converts middleware func(http.ResponseWriter, http.Response, http.HandlerFunc) to func(http.Handler)http.Handler | Negroni to Alice
type Middleware interface {
ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)
}
func Compose(m Middleware) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
m.ServeHTTP(rw, r, next.ServeHTTP)
})
}
@doug
doug / jskeyframeeffect.js
Last active August 29, 2015 14:00
JsKeyFrameEffect to extend web-animations.js
// JSKeyFrameEffect to extend web-animations.js
function JSKeyFrameEffect(model, keyframes) {
if (keyframes.length === 0) {
if (console) {
console.warn('Must provide keyframes.');
}
return function() {};
}
if (keyframes[0].offset === undefined) {
@doug
doug / visibility.js
Created March 15, 2014 23:18
show hide visibility
(function() {
var hidden = "hidden";
// Standards:
if (hidden in document)
document.addEventListener("visibilitychange", onchange);
else if ((hidden = "mozHidden") in document)
document.addEventListener("mozvisibilitychange", onchange);
else if ((hidden = "webkitHidden") in document)
document.addEventListener("webkitvisibilitychange", onchange);
@doug
doug / after.js
Created February 19, 2014 23:44
after.js
function after(counter, callback) {
return function() {
if (--counter <= 0) {
if (callback) {
callback();
}
}
};
}
@doug
doug / getgist.sh
Created December 13, 2013 06:24
Curl download extract and expand a gist. Useful for bootstrapping.
function getgist() {
curl -0 $1/download | tar -xz
set -- gist*
mv $1/* .
rmdir $1
}
var QueryString = function() {
// This function is anonymous, is executed immediately and
// the return value is assigned to QueryString!
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
// If first entry with this name
if (typeof query_string[pair[0]] === "undefined") {
@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
@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 / 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 / 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.