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() { | |
window.batch_function = function(target) { | |
var state = "clean"; | |
var lastArgs = [window, []]; | |
var run = function() { | |
if (state === "clean") { | |
state = "running"; | |
target.apply(this, arguments); | |
} | |
else { |
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
/* | |
* This is the compiled css for Bootstrap tabs and pills. | |
* Compiled from bootstrap 2.3.2 (less/navs.less) | |
*/ | |
.clearfix { | |
*zoom: 1; | |
} | |
.clearfix:before, | |
.clearfix:after { |
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
from PIL import Image | |
import os, argparse, sys | |
import imghdr | |
parser = argparse.ArgumentParser(description='Create thumbs for all the images in a directory') | |
parser.add_argument('dir', help="The directory the images are in") | |
parser.add_argument('--width', help="Thumbnail max-width", type=int, default=128) | |
parser.add_argument('--height', help="Thumbnail max-height", type=int, default=128) | |
args = parser.parse_args() |
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
{ | |
"metadata": { | |
"name": "", | |
"signature": "sha256:5897937ca974f647822cf4323d573b62f4b92a81227691433746e3340b6fce59" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ |
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
"""Ultra-minimalist logger with context | |
e.g.: | |
from context_log import Log | |
Log.out = open('report.txt') | |
Log.formatter = lambda dictionary: "%(filename)s>%(lineno)03d: %(session)s: %message" % dictionary | |
Log.context['session'] = 'Cammping Trip' | |
Log.warn("There's a bear behind you") |
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
def async(func): | |
"""A decorator to make a function run in its own thread and return its result on .join()""" | |
def launch(*args, **kwargs): | |
target = ThreadedFunction(func, *args, **kwargs) | |
target.start() | |
return target | |
return launch | |
class ThreadedFunction(threading.Thread): | |
def __init__(self, func, *args, **kwargs): | |
self.args = args |
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 threading | |
class ReadWriteLock(object): | |
""" An implementation of a read-write lock for Python. | |
Any number of readers can work simultaneously but they | |
are mutually exclusive with any writers (which can | |
only have one at a time). | |
This implementation is reader biased. This can be harmful | |
under heavy load because it can starve writers. | |
However under light load it will be quite perfomant since |
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
// This function plays an audio/video element and creates a promise | |
// that resolves when the audio/video finishes playing | |
// It's nice :) | |
function HTML5Play(target){ | |
var t = $(target); | |
if(t.length != 1 || !t.is('audio, video')) return undefined; //These are invalid cases | |
var deferred = new $.Deferred(); | |
t.on('ended', function(){ deferred.resolve(t) }) |