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

Internet Explorer reporting Invalid Character errors when debugging with Visual Studio

The following is search-engine bait; I didn't get any hits when trying to track this down. I normally do my first pass of Web page testing using Chrome, but when I published the source to travellermap.com I was sent a report by a developer that when debugging with IE he was seeing errors. Exception was thrown at line 15, column 399 in http://www.google-analytics. com/ga.js 0x800a139e - JavaScript runtime error: aborted Exception was thrown at line 28, column 1602 in http://connect.facebook.net/ en_US/all.js#xfbml=1 0x800a03f6 0x800a03f6 - JavaScript runtime error: Invalid character Exception was thrown at line 13, column 1602 in http://static.ak.facebook.com/ connect/xd_arbiter.php? version=25 0x800a03f6 0x800a03f6 - JavaScript runtime error: Invalid character Exception was thrown at line 13, column 1602 in https://s-static.ak.facebook. com/connect/xd_arbiter.php? version=25 0x800a03f6 0x800a03f6 - JavaScript runtime error: Invalid character Exception was thrown at line 17

Salvaging Prometheus

So Ridley Scott's Prometheus  was pretty bad. The whole movie hinged on the so-called "scientist" characters behaving in unprofessional and antisocial ways. This is compounded by scientific and logical flaws presented in the film itself and revealed in interviews that show that the film-makers (Scott and the screenwriters) are laughably ignorant of science and professional behavior. Can the mess be salvaged? Here's how I reconcile it. Warning: Spoilers ahead. First off, discard the notion that the Engineers are billions of years old and responsible for life on Earth. No starfaring civilization will last that long. Fortunately, the only hints that this is the case are the rather abstract title montage, the statements of a demonstrably duplicitous android, claims by the characters themselves who are established as being poor scientists, and interviews with the filmmakers (see above). Secondly, knowing that the android David has a hidden agenda, discard any of his

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

Loading JavaScript modules via IFRAME

Another in the list of "I don't have a need for it now, but..." - this is also old hat on the Web but was new to me. I've been intrigued by the Modules proposal for ECMAScript "Harmony" . Since I like polyfills (so soothing...) I've been wondering what the subset is that could be implemented as a polyfill is, so that you can write code that runs in both ES5 and ES6 environments (i.e. the Web). I noodled around a bit with this many months ago and the key piece that was missing is sandboxed evaluation of the code, with unique "intrinsics" i.e. Object, Array, their prototypes, etc. The scenario is that you're running code like: Object.prototype.awesome = function() { return "foo"; }; But you load a third party module that one day decides to add: Object.prototype.awesome = function() { return "bar"; }; If partying on the Object prototype isn't part of the contract with the module (and it shouldn't be!

Resource "using" in JavaScript

Based on a discussion in v8-users I was playing with a nice style for lifetime-bounded resource uses in JavaScript. I don't actually have any practical need for it at the moment, but thought I'd share. Imagine you have some type Resource that is "expensive" - typically, it holds onto something that you want to get rid of as soon as you're done using it. An example might be a file descriptor or a memory buffer. In JavaScript or C# you generally rely on garbage collection to detect that you're done with something and release the resource, but in some circumstances you want to do so explicitly, so the Resource type exposes a method release() that you can call. Perhaps, behind the scenes, this is a host object and this will cause the native resources to be freed. The contract will usually be that using Resource past this point will raise exceptions, so it assumed you know what you're doing. The basic JavaScript usage would then be: var res = new Resource

Oh, that's what "ninched" means!

Way back when I mentioned " Temporal Ninching ", using "ninched" to refer to a mixed state checkbox. I just learned, thanks to Murray Sargent's blog , that NINCH is an acronym for " no input no change " I had the pleasure of working with Murray Sargent for a while when I was on the InfoPath , sorry, Microsoft Office® InfoPath™ team. At least at the time, InfoPath, Word and RichEdit were one big happy document-authoring family in the org chart. I confess that I don't remember the details, but we spent several hours discussing the finer points of text editing services.