Posts

Automatically appending content to served HTML - Apache and IIS

Let's say you want to append content to HTML pages you're serving - like analytics tracking code. If you're like me you're serving at least some static HTML pages and not relying on PHP or other insanity. More specifically, here are the configurations I care about: "cloud hosted" apache2 server, purely static content served out of good old public_html "cloud hosted" IIS server with a .NET-based application apache2 This is fairly simple, but involves writing a CGI script like it's 1995. Create public_html/cgi-bin as a directory Create a file public_html/cgi-bin/footer  with this as the contents: #!/usr/bin/env bash echo "Content-Type: text/html" echo "" cat "$PATH_TRANSLATED" cat <<EOF ... content you want to append goes here ... EOF Mark the file executable, e.g. chmod a+x public_html /cgi-bin/ footer If it doesn't already exist, create a new file public_html/.htaccess ...

HTTP Caching, POST, and Vary Headers

Um, yeah, so this should be obvious but was a "derp" moment for me. When you're generating content from a web service, you can specify a Cache-Control: public to indicate "this can be cached on the client, on the server, and by proxies", and Vary  header to indicate that different client headers (e.g. Accept) should yield different results (so the result of a prior PNG request doesn't get served up for a PDF request, etc). ASP.NET provides server side caching, and you may want to specify (in the ASPX page)  <%@ OutputCache VaryByParam="*" %>  so that the server caches different data for http://site/page.aspx?var=1 vs. http://site/page.aspx?var=2 But (here's the head-slapping bit): The ASP.NET VaryByParam directive has nothing to do with the HTTP Vary header, which controls varying by other HTTP headers. Even if you have a header of Vary: * it can't prevent client-side caching based on POSTed data, since that isn't incl...

Gymboree Starship

The prototype can be seen on Caspian's T-Shirt from Gymboree. _ ,'|`. / | \ / | \ /. / \ .\ /. / \ .\ /. | | .\ /| /_____|___|_____\ |\ || | | -= =- | | || .|| ,-'| | | |`-. ||. | `-'___| | | |___`-' | |________| | =---= | |________| | | | | | |___H___| | | [| | |] | |__|___|___|__| \ / \ / ...

C++ Optimization Trick

Maybe this is old hat, but when I was writing a software rasterizer several years ago I came up with a trick for getting optimized variations for different render states (textured, flat shaded, Gouraud shaded, wireframe, z-write, z-test, cull-ccw, etc) without hand-writing multiple permutations of the rasterizer as is recommended by LaMothe and others. It requires an optimizing C++ compiler that supports template functions. The trick is to pack as much state as possible into a single POD value like a 32-bit integer, write your function so that all of the if() tests for render state look at the integer for branching decisions, and call a template function that takes this value as a template parameter in a constant context like a switch statement. Here's the base function full of nasty branches: result_t func(int flags, const data_t& data) { if (flags & OPT_A) { // ... } if (flags & OPT_B) { if (flags & OPT_C) { // ... } else { // ... }...

I Feel... Uncertain

Image
Courtesy of Robert Knop , my favorite astrophysicist at Linden Lab: The equation describes a quantum superposition of two states with equal amplitudes. (graphic c/o  http://www.codecogs.com/ )

Indiana Jones and the Temple of Doo

Image
As seen on TV: Mola Ram: I would have gotten away with it, too, if it weren't for that crazy archaeologist and his stupid dog! (No, that isn't a slight at either of Indy's companions on this adventure.)  

Summer Movie Reviews

Speed Racer Saw it in IMAX. Harmless family fantasy fare. We went in expecting an eye-candy homage to the cartoon and weren't disappointed. I can't imagine ever watching it again, but it entertained us. The Chronicles of Narnia: Prince Caspian My bar: "Was it good enough that they'll make Voyage of the Dawn Treader ?" Apparently, yes - $96M so far. Yay. The actual plot of the book itself is rather short, and unlike LWW or VDT focuses on atmosphere, character development, and parable. (In the lovely form of "If your friends didn't have the faith to jump off a bridge, why should that stop you?") It can be summed up as "the Pevensies appear in Narnia, note that it has aged a thousand years, meet a dwarf who provides details in flashback, and trump across the world being teased by Aslan. The boys arrive in time to rescue Caspian from some nasties in a cave, then defeat his uncle in single combat, while Aslan and the girls wake up the pagan...