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...

What Slashdotting looked like

Image
FYI, here's what being Slashdotted did to my calormen.com site traffic:

My Other Project

Image
Inspired by the Steampunk Keyboard Mod page and a long term crush on Amanda Pays (Theora on Max Headroom , who had an actual typewriter for her keyboard), I put this together:   It looks better in person than it does in the pictures, actually. Ask friends or co-workers of the cheap keyboard that "came with the computer" that's probably in the closet gathering dust. This one's a Dell USB. Use a Dremel rotary tool to chop the edges off the keys - basically draw a box on the top of each key until the "skirt" falls off   Order all the keys you need on eBay - search on " typewriter keys royal ". Note that you'll need 3 complete sets (all of two, a few from one more). Pay attention to whether you want round or rectangular keys for the "special"keys. Expect to pay about $1 per key. If you can, get the logo! To make the non-standard key-caps (Carriage return, Function keys, "1"... none of those were around ...

Foundation's End

I'm not alone in holding Asimov's Foundation series in high regard. In 1965 it won the Hugo Award for "Best All-Time Series" and I can't think of another science fiction series that would be a serious contender. Dune comes closest, but is still outmatched. That's not to say that they are the epitome of SF, but they are deeply special. Originally written in the 1940s as a serial and later published as a trilogy ( Foundation; Foundation and Empire; Second Foundation ), Asimov returned to the series in the 1980s with two sequels ( Foundation's Edge; Foundation and Earth ) and two prequels ( Prelude to Foundation; Forward the Foundation ). He also linked in his Robot series ( The Caves of Steel; The Naked Sun; The Robots of Dawn ) and more loosely the Galactic Empire series ( The Currents of Space; The Stars Like Dust; Pebble in the Sky ) as well as numerous short stories. Robots and Empire was explicitly written as a bridge novel. Additional novels wer...

Second Life on an Apple II

Image
... or, "How Josh spends his time when the family is on vacation without him." It's a client/server app for the Apple II and Windows that streams the Windows desktop down to the Apple. So far the communication is one way, so you can't even call it a graphical terminal. Yet. Second Life login screen My pirate ship Billabong My avatar at the International Space Flight Museum The Windows server and Apple client (with the USB->RS232 Serial connector in the middle)

Moo Cards

Image
We're getting a fresh batch of business cards at work c/o Moo Cards and this time can use custom screenshots. Here are some I snapped today which will be on the back of my cards: Yes, that's how good Second Life graphics are these days. I really am that shiny. :)

St. Patrick's Day

Image
I decorated my av in a seasonal fashion: I showed up for a meeting green, and someone didn't "get it". So I had to make the hat.

Paper Satellites

In the Oakley Centre library was a book describing early (so, 1960's) communication satellites. They were simple geometric solids (tetrahedron, cube, octahedron, etc) covered with solar cells, and the book had plans for making paper models (cut, fold, glue). Googling isn't turning anything up. Anyone out there able to find it?

ONERR RESUME and such

I added ONERR GOTO linenum / RESUME / POKE 216,0 support to my Applesoft Interpreter . It turned out to be pretty simple. ONERR sets a handler address. On an exception, check if it's cachable (i.e. the program caused it, it's not the interpreter reporting a bug). If so, store the current execution point and jump to the handler. If the handler calls RESUME, restore the previous execution point. The only wrinkle is that IF...THEN... is considered a single statement, so the IF part needs to be resumed and I was cheating an treating the bit after THEN as a separate statement. I don't twiddle the stack at all, so I'm not positive the behavior there is consistent with a real Apple. This is not a feature I used when I programmed in BASIC. I didn't have very good examples to learn from. Also, initial experiments with RESUME made me wonder "WTF?". For example, consider this: 5 ONERR GOTO 10000 10 INPUT "Open file?";F$ : REM prompt user for file name ...

Catching Up

Nothing big to report, but for posterity I should probably say something... At the end of January, my grandmother (June Fahey) passed away. I'd expected this for a long time... and basically dreaded phone calls from my parents for several years, anticipating the news. On February 8th we flew to Disneyland for the weekend, courtesy of a co-worker who has a small plane. Lovely flight down and back. Caspian enjoyed the Indiana Jones ride (finally tall enough!) but freaked out a bit in line the second time when the spiked roof started to descend. Ah well - we made it through. Will post pictures at some point. Caspian is taking ice skating lessons on Saturday afternoon, and having a great time. He's quite enthusiastic about it. Occasionally, he even listens to his instructor. He's still taking ballet on Mondays, but his yoga mat and clothes got left on a cable car, so Su took him to the dance store... and they came home with tap shoes. He's very excited about them. We...

Why 3D?

I happened to read co-worker Jeffrey Ventrella's page http://www.ventrella.com/Ideas/YawPitchRoll/yaw_pitch_roll.html and the "Why 3" part reminded me... Since (most) humans are trichromats, we've settled on a 3-dimensional color space: RGB for emissive and CMY for reflective, although in school you learn the approximation "blue, red, yellow" as the "primary colors". Our color monitors use RGB (subpixel, phosphor) triads which roughly correspond to the light frequencies that (most) human eyes are sensitive to. Graphics programming is often an attempt to make sure the right R, G and B values are used for each pixel to approximate reality. We also generate other color spaces (HSL, HSB) when convenient, each with three parameters. This might indicate that colors are inherently 3D, as is space. Of course, it's all just hacks upon hacks. Light can come in any frequency, from (infra)red through (ultra)violet, and is typically a mix of many fre...

Best TV Show Ever: Jim Henson's The Storyteller

Go buy a copy of The Storyteller on DVD if you don't have one and watch it (again). Then go and buy a copy of the book .

Caspian and Ariel

Caspian is deeply, madly in love with Ariel (from The Little Mermaid ). This isn’t precisely recent. Prior to our last trip to Disneyland he’d written a letter to Ariel (with a drawing of his robot bunny), and on said trip he delivered it to her she sits and talks with children at her grotto (not the restaurant, but a dedicated spot near the Matterhorn at the boundary between Fantasyland and Tomorrowland). It is, however, much more pronounced lately, perhaps more so after receiving a Little Mermaid fleece blanket in the mail (a cereal box offer ). He’s requested to watch the movie several times of late, and has the movie soundtrack on his MP3 player and listens to it often. He is also, apparently, an R.E.M. fan. He asked me to put that on today, and then had to specify “No, I want Out of Time .” But I digress. This has led to some interesting conversations. He wants Ariel to come live with us, perhaps “stay in our bathtub.” On more than one occasion he’s whispered to us, so...

Applesoft Interpreter Update

I blogged about it previously , but one side project I have going on is an Applesoft interpreter in Javascript .  I've been adding updates to the page as I went, and it's getting pretty complete at this point. Worth calling out: It has DOS emulation (basically, you can use ye olde PRINT CHR$(4) trick to open and read text files) Joystick and Paddle support (using on-screen controls) Low resolution graphics (40x48) PEEK/POKE emulation for the keyboard and display strobes, so you can do asynchronous input, e.g. games Tested on Internet Explorer, Firefox, and Safari (Windows) There are two samples - DEMOS (which is a collection of test samples) and TRADER (which was the point of the whole exercise) Check it out!