Skip to content

Instantly share code, notes, and snippets.

View chl's full-sized avatar

Christian Langreiter chl

View GitHub Profile
@chl
chl / renderst.py
Created July 22, 2008 15:10 — forked from earl/renderst
#!/usr/bin/env python
# earl, 2008-07-22
from __future__ import with_statement
import stringtemplate3, simplejson, sys
def main():
with open(sys.argv[1]) as template_file:
template = stringtemplate3.StringTemplate(template_file.read())
template.attributes = simplejson.load(sys.stdin)
sys.stdout.write(unicode(template).encode('utf-8'))
// start w/ ringo-web j2d
// j2d/config.js
exports.urls = [['/', 'actions']];
exports.app = require("ringo/webapp").handleRequest;
// j2d/actions.js
import("binary");
require("ringo/processing").wire(this);
function setup() {
size(800, 600);
colorMode(RGB, 1);
background(0);
stroke(0.8);
strokeWeight(10);
}
# chl, 2010-04-27
# http://blog.tech.stylefeeder.com/2008/05/27/generating-primary-keys/
import math
NUM = "0123456789"
LOWER = "abcdefghijklmnopqrstuvwxyz"
UPPER = LOWER.upper()
ALPHANUM = NUM + LOWER + UPPER
ASCII_94 = [chr(33 + x) for x in xrange(94)]
# chl, 2010-05-18
# jaccard coefficient experiment, inspired by @datajunkie
from __future__ import with_statement, division
import collections
S = collections.defaultdict(set)
T = collections.defaultdict(set) # inverse
// Adapted from Jonathan Feinberg's Python port of original code by luis2048
// http://github.com/jdf/processing.py/blob/master/examples.py/Topics/Effects/Metaball/Metaball.py
require("ringo/processing").wire(this);
var coord = [
[0, 0],
[90, 120],
[90, 45]
];
@chl
chl / json-select.py
Created January 17, 2012 00:37
Select fields (at depth) from one-record-per-line JSON streams
#!/usr/bin/env python
import sys
import argparse
import re
import simplejson
parser = argparse.ArgumentParser(description="Select fields (at depth) from one-record-per-line JSON streams")
parser.add_argument("-d", default=".", help="Path delimiter (default: .)")
parser.add_argument("-x", default="@", help="Array indexing prefix (default: @)")
@chl
chl / gist:3948727
Created October 24, 2012 20:40
List Coursera courses available in self-study mode
curl -s "https://www.coursera.org/maestro/api/topic/list?full=1" | jq ".[] | select(.self_service_course_id) | [{name, self_service_course_id}]"