1. icon for News
  2. icon for TCHOW

News

Wednesday, August 29, 2012

Finally documented the 2011 midwinter hunt

It's been sitting on my hard drive in more-or-less complete state for a while now, but I've finally gotten around to posting the documentation of the 2011 midwinter puzzle-hunt I wrote.
I hope this is the start of a trend toward actually documenting some of the things I do/make, if just for the sake of my own later self.

Sunday, August 26, 2012

Updated Backend

Over the last few days, I've massively restructured the way that tchow.com is served.On the surface, you shouldn't notice any big differences, but under the hood things have gotten dramatically simpler.

How it was

From sometime around 2007 until just a few days ago, tchow.com was hosted on a VPS partition from RapidVPS.The partition was set up running a pretty standard stack: Gentoo GNU/Linux, the Apache web server, and PHP5.
I designed my content serving system to be future-proof, simple to use, and to contain minimal redundancy.This meant that I wanted visitors to see clean URLs (no file extensions; file types determined by Content-Type header), and those that looked at the markup to see nice xhtml with a clear separation of content and chrome.Internally, I wanted to be able to serve the web page from a filesystem, provide content with my favorite text editor (and/or scp), and do so in a not-too-idiosyncratic format.
In order to make this work, the following happened on each page load:first, mod_rewrite rules would take the user's URL and turn it into a query string for a dispatch.php script;this script, in turn, would crawl the backend directory structure to find the proper page (a file containing an html fragment),then paste in appropriate templates for navigation and analytics.

What I didn't like about it

This old setup was nice, but it was also overkill -- php was re-generating the same (static) content over and over again, opening and reading through tens of files on each page view.This seems really inefficient (and, honestly, the "standard" answer of wrapping this in a caching web server seems even sillier).
Additionally, external URLs were clean-ish, but I never really resolved where a trailing slash was appropriate, which led almost everything having absolute links all the time.
Also, I ended up storing my page content in an svn repository (to move edits between my staging and live pages), but since svn has no way of updating all of htdocs at once, this creates potential race conditions in page viewing during updates.Besides, I've been using git for a number of years, and it feels so much snappier than svn that it was getting to be a drag to do page updates.
Added to these design concerns, I'd noticed that Digital Ocean was offering a VPS partition of similar size to my RapidVPS partition (but with unlimited bandwidth) for about half the price.So it was time to change.

How it works now

First off, I ditched Apache -- which provided way more than I need -- and switched to Lighttpd; this also provides way more than I need, but at root it's a lot more comprehensible.Indeed, I get nice clean URLs using just two modules: mod_rewrite for hostname correction (e.g. so that www.tchow.net redirects here properly) and mod_magnet for URL dispatch.I no longer have php re-generating static content over and over again;instead, I have a python script that I call on the (git) content repository which regenerates just those pages that need it.
But mod_magnet is really the key to the whole setup because of the way it works:you provide Lighttpd with the path to a lua script, and it runs that script to determine which physical path corresponds to given query string (the script can also do things like trigger redirects and add headers).The cool thing here is that now every page view goes through dispatch.lua (in my case, nothing more than a url -> file mapping table), and it's one file, which means that if I atomically update it then I've atomically updated the web page.So this setup gives me the satisfaction of being able to update the content on tchow all at once, and without race conditions (as long as my scripts are careful to not overwrite any content referenced by the active dispatch.lua).
I also re-worked a few things around the urls so that the semantics are much clearer, changed the styling a smidge, drew some new calendar icons, and did various other tidying.But mostly, I'm satisfied that I've gotten rid of a lot of systems that tchow.com didn't need, and pared things down to a really slick-n-slim software stack that still satisfyingly serves what it should.

Wednesday, February 8, 2012

Checkpointable Box2D

While working on rktcr, I've spent a while thinking about how to checkpoint Box2D simulations so that one can rewind and play them back exactly.(Useful for replays, or time control when you really care about doing it right.)This turns out to be both harder and easier than one would expect:harder, because some of the simulation state (e.g. order of contact processing) is hard to access, much less properly save;easier, because one can hook memory allocations in Box2D and just save everything.This is one of those hacks where I'm very glad I use a language that can talk about memory.
I'm releasing this code as public domain -- you can find it from GitHub here.There is a small patch you'll need to apply to Box2D included.If you enjoy (or are confused), please let me know,

Saturday, August 20, 2011

Added Sworderation

I've added a game I worked on in 2004 -- Sworderation -- to the games section.I just played through it again, and it's still fun.I hope you think so too.

Monday, July 12, 2010

ICFP 2010

(This legacy post contained a description of what I did for gate encoding in the 2010 ICFP. I have moved this content to the projects section.)

Sunday, July 12, 2009

wmiirc and Disks

(From the not-useful-unless-you-use-Linux-like-I-do department.)
So, I've been using wmii as the window manager on my laptop.Other than changing its default meta key to be the winkey (I should really do something about that branding), setting it to launch uxterms, configuring it to show CPU and battery info, and setting up pidgin to change a tag color on new messages, I haven't had to change its default settings at all.
That may seem like a lot, but in the world of "nonstandard" window managers, well, it isn't.Programmers (the probable main consumers of -- and face-slappingly-obviously main producers of -- such WMs) are picky people.Indeed, the fact that I didn't have to edit the source code to do any of this is right civilized!(Unlike switching the meta key in, say, Fluxbox.)
However, I did manage to do something stupid when performing that second-to-last tweak.First some background:wmii has a status line at the bottom of the screen.In the wmiirc script there is a function -- status() -- whose output is pasted into the lower right at some frequency.To display battery information you simply create a program (likely a shell script) to echo the information you'd like displayed and have status() call it.I learned as much from this forum post, which also includes a handy script to produce exactly the sort of info I wanted to display.Thus, I adapted this script to my needs and it has been quietly working ever since.
But my hard drive has been being accessed every five seconds (even when the computer is apparently idle) ever since I set that script up.Turns out that here-documents in bash create temp files.Creating temp files is disk activity.Disk activity makes kjournald decide to write a journal every five seconds.Which is probably not good for the disk, definitely not good for battery life, and quite annoying.Here'my version with that problem fixed:
#!/bin/sh
#based on http://bbs.archlinux.org/viewtopic.php?id=1809

rate=`grep 'present rate' /proc/acpi/battery/BAT0/state | tr -d -c 0-9`
current=`grep 'remaining capacity' /proc/acpi/battery/BAT0/state | tr -d -c 0-9`
total=`grep 'last full capacity' /proc/acpi/battery/BAT0/info | tr -d -c 0-9`
percent=`echo "100 * $current / $total" | bc`

speed=`grep -m1 -o 'cpu MHz.*\.' /proc/cpuinfo | tr -d -c '\n0-9'`

if grep -q discharging /proc/acpi/battery/BAT0/state
then
 minutes=`echo "60 * $current / $rate" | bc`
 echo $speed $minutes $percent'%'
else
 echo $speed $percent'%'
fi
By the way, should you find yourself in a similar pickle, echo '1' > /proc/sys/vm/block_dump.It will produce kernel messages (viewable by dmesg -- you probably want to turn off your system logger while doing this) which will let you know who is causing blocks to need writeback.

Monday, January 19, 2009

SIGGRAPH Panic

(Reported far after the deadline.)
SIGGRAPH is crazy. What do you do when you need more space to edit your video? Well, to be fair, I had those backed up on another computer. Still, it was the most convenient spare 10+ gig.
And kdenlive is quite buggy (not old days cinelerra bad, but...). I've resisted up to now, but I may have to write my own nonlinear video editor. Or maybe try blender's built-in editor. The key is to write up a library that can load and seek video files in a frame-accurate way, with minimal pre-processing and memory overhead.