Skip to content

Instantly share code, notes, and snippets.

@williame
williame / git_churn
Created September 12, 2011 11:36
git churn script
#!/usr/bin/env python
import sys, datetime, subprocess
churn = {} # lines per date
# get a list of tracked files
git = subprocess.Popen(("git","ls-files"),stdout=subprocess.PIPE)
files = git.communicate()[0].strip().split("\n")
if git.returncode: sys.exit(1)
@williame
williame / gist:1267214
Created October 6, 2011 11:44
shows idea of single-static-type-assignment
<html><head><title>test.py</title>
<style>
.v { font-weight: bold; color: navy; }
.error { font-weight: bold; color: yellow; background-color: red; }
.unused { font-weight: light; color: darkgray; }
</style>
<script type="text/javascript">
var highlight = {};
function clear_highlight() {
for(var id in highlight) {
<html>
<head>
<script type="text/javascript">
<!--
function onkey(event) {
if(event.target.id == "b") {
var c = document.getElementById("c");
if(!c) {
document.getElementById("a").innerHTML += "<br/><input id=\"c\" type=\"text\"/>";
c = document.getElementById("c");
@williame
williame / gist:2669194
Created May 12, 2012 21:28
Perspective correcting a quad
import array
# these routines copied shamelessly from http://threeblindmiceandamonkey.com/?p=16
# multiply matrix: c = a * b
cdef inline void multiplyMatrix(double a[3][3], double b[3][3], double c[3][3]):
c[0][0] = a[0][0]*b[0][0] + a[0][1]*b[1][0] + a[0][2]*b[2][0]
c[0][1] = a[0][0]*b[0][1] + a[0][1]*b[1][1] + a[0][2]*b[2][1]
c[0][2] = a[0][0]*b[0][2] + a[0][1]*b[1][2] + a[0][2]*b[2][2]
c[1][0] = a[1][0]*b[0][0] + a[1][1]*b[1][0] + a[1][2]*b[2][0]
<html>
<head>
<title>Will's quick mandelbulb GLSL</title>
<script type="application/javascript">
var canvas, gl, program;
function start() {
window.onerror = function(msg, url, lineno) {
alert(url + '(' + lineno + '): ' + msg);
function createOrtho2D(left,right,top,bottom) {
var near = -1, far = 1, rl = right-left, tb = top-bottom, fn = far-near;
return [2/rl,0,0,0,
0,2/tb,0,0,
0,0,-2/fn,0,
-(right+left)/rl, -(top+bottom)/tb, -(far+near)/fn,1];
}
createOrtho2D(0,canvas.offsetWidth,0,canvas.offsetHeight) * [10,10,0] = [-0.9804878048598766,0.9450549436733127,0]
@williame
williame / tiny_git_webserver.py
Created August 10, 2012 22:42
A super-simple web-server to serve up files in a git (bare) repo
import os, subprocess, base64
import tornado.ioloop
import tornado.web
from tornado.options import define, options, parse_command_line
define("port",default=8888,type=int)
define("branch",default="master")
define("access",type=str,multiple=True)
class MainHandler(tornado.web.RequestHandler):
@williame
williame / gist:3481066
Created August 26, 2012 15:21
print client.name, client.keys, client.roll_speed, client.pitch_speed, client.rot, client.pos, move
[I 120826 17:42:18 web:1447] 304 GET /index.html (127.0.0.1) 21.74ms
[I 120826 17:42:19 web:1447] 304 GET /game.js (127.0.0.1) 27.38ms
[I 120826 17:42:19 web:1447] 304 GET /glutil.js (127.0.0.1) 15.00ms
[I 120826 17:42:19 web:1447] 304 GET /ui.js (127.0.0.1) 30.35ms
[I 120826 17:42:19 web:1447] 304 GET /g3d.js (127.0.0.1) 17.36ms
[I 120826 17:42:19 web:1447] 304 GET /logo.jpg (127.0.0.1) 11.59ms
[I 120826 17:42:19 web:1447] 304 GET /bitstream_vera_sans.png (127.0.0.1) 9.04ms
[I 120826 17:42:19 web:1447] 304 GET /bitstream_vera_sans.xml (127.0.0.1) 12.62ms
[I 120826 17:42:19 web:1447] 304 GET /grid.png (127.0.0.1) 9.49ms
[I 120826 17:42:19 web:1447] 304 GET /fighter2.g3d (127.0.0.1) 13.74ms
@williame
williame / gist:3692157
Created September 10, 2012 17:01
simple dump of various 8-bit-aligned binary datatypes
import sys, struct, datetime
fmts = ("b","<h",">h","<H",">H","<i",">i","<I",">I","<f",">f","<d",">d")
s = file(sys.argv[1],"r").read()
print sys.argv[1]
print "ofs,",", ".join(fmts)
for i in xrange(len(s)-8):
print "%d,"%i,", ".join("%s"%struct.unpack(fmt,s[i:i+struct.calcsize(fmt)])[0] for fmt in fmts),
print "'%s',"%datetime.datetime.fromtimestamp(struct.unpack("<I",s[i:i+4])[0]).strftime('%Y-%m-%d %H:%M:%S'),
print "'%s'"%datetime.datetime.fromtimestamp(struct.unpack(">I",s[i:i+4])[0]).strftime('%Y-%m-%d %H:%M:%S')
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<name>Collar9007</name>
<description>GPS Plus - http://www.vectronic-aerospace.com</description>
<Style id="FirstFix">
<IconStyle>
<Icon>
<href>http://maps.google.com/mapfiles/kml/shapes/square.png</href>
</Icon>