Skip to content

Instantly share code, notes, and snippets.

@williame
williame / diff1.py
Created November 18, 2010 09:35
zip to folder delta calc
to_mem = True # set to False if you want a actual zip file of the delta made (e.g. you want to recompress it with 7z)
import zipfile
import sys, os, cStringIO
if len(sys.argv) != 3:
print "Diffs a zip file against a folder, and computes a file-granularity delta"
print "usage: python diff1.py prev.zip newfolder"
print "e.g. is MRise_1.0.zip is in your current directory, and you have the 1.6 directory tree in a folder called MRise_1.6, then:"
print " python diff1.py MRise_1.0.zip MRise_1.6"
@williame
williame / dep.py
Created November 25, 2010 11:56
A simple attempt at working out what files are in and out of a mod, and if its broken
import os, sys, string
import xml.dom.minidom as minidom
from struct import unpack
from itertools import chain
class File:
"""a file (type and path)"""
MAP = "map"
SCENARIO = "scenario"
=== Mod check failed ===
(model BROKEN techs/megapack/factions/persian/units/swordman/models/guard_attacking.g3d (referenced by: unit ../swordman.xml)) ('Error reading G3D file', IOError(2, 'No such file or directory')), ('File does not exist',)
(model BROKEN techs/megapack/factions/tech/units/swordman/models/guard_attacking.g3d (referenced by: unit ../swordman.xml)) ('Error reading G3D file', IOError(2, 'No such file or directory')), ('File does not exist',)
(model BROKEN techs/vbros_pack_1/factions/canadians/units/beaver/models/worker_standing_loaded_wood.g3d (referenced by: unit ../beaver.xml)) ('Error reading G3D file', IOError(2, 'No such file or directory')), ('File does not exist',)
(model BROKEN techs/vbros_pack_1/factions/canadians/units/inuit_man/models/minstrel_summoning.g3d (referenced by: unit ../inuit_man.xml)) ('Error reading G3D file', IOError(2, 'No such file or directory')), ('File does not exist',)
(particle BROKEN techs/megapack/factions/persian/units/worker/particle_splash.xml (referenced
@williame
williame / glest_mod_pack.py
Created November 26, 2010 13:09
a mod packing tool for Glest, MegaGlest and GAE
# glest_mod_pack is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
@williame
williame / test_tornado_async_error.py
Created May 31, 2011 07:28
For me at least, raising an exception in a callback does not do anything to the request
from tornado import ioloop, web, httpserver, httpclient
PORT = 8080
class TestHandler(web.RequestHandler):
@web.asynchronous
def get(self):
url = "http://www.google.com"
print "fetching",url
@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) {
import java.util.Random; // for test code
final class BFS {
/* finds nearest ant to a destination in a maze.
You give it a (partial) map and it plots a route using naive BFS.
As you discover more obstacles you can call addWater() for them.
It makes extensive use of pre-allocated data for intermediate results,
so you must extract the path for each call to findNearestAnt() or you
lose it. */
<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]