Skip to content

Instantly share code, notes, and snippets.

@williame
williame / debugwin.py
Created June 28, 2012 20:09
can watch variables; opens a window that continuously updates as the variable changes value
import sys, threading, Queue, weakref
try:
import Tkinter
_has_tk = True
_debug_win = None
except ImportError:
# quietly disable ourselves
_has_tk = False
var mandelbulbCanvas = document.getElementById('mandelbulb');
window.requestAnimFrame = (function(callback) {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 100);
<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>Collar7854</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>
<?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>
size=[14,48,25,33]
tilesize=2048
map_size=[(size[1]+size[3])*tilesize,(size[0]+size[2])*tilesize]
print '<html><head><title>',",".join("%s"%i for i in map_size),'</title></head><body><table cellspacing="0" cellpadding="0">'
for ns in "ns":
for y in range(48):
print "<tr>"
for x in range(25):