Awesome Holiday boredom

88

I got: A, ABBR, ACRONYM, APPLET, AREA, B, BASE, BASEFONT, BIG, BLOCKQUOTE, BODY, BR, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, DD, DEL, DFN, DIR, DIV, DL, DT, EM, FIELDSET, FONT, FORM, FRAME, FRAMESET, H1, H2, H3, H4, H5, H6, HEAD, HR, HTML, I, IFRAME, INPUT, INS, ISINDEX, KBD, LABEL, LEGEND, LI, LINK, MAP, MENU, META, NOFRAMES, NOSCRIPT, OBJECT, OL, OPTGROUP, OPTION, P, PARAM, PRE, Q, S, SAMP, SCRIPT, SELECT, SMALL, SPAN, STRIKE, STRONG, STYLE, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TITLE, TR, TT, U, UL, and VAR

I forgot: ADDRESS, BDO, and IMG. Yes, IMG.

To be fair, this was probably the 8th try. It helps to group them into forms, block/inline, quoting, embedding/linking, framing, lists, data/code display, etc.

Anti-forward ammunition

Gently inform a loved one that forwarding hoaxes and chain letters is a waste of everyone’s time.

I just got this. Get it to everyone fast as possible!

>> Important! Pass it on....
>>
>>> THIS IS NOT A JOKE! I confirmed it on Snope!!!! Please forward this 
>>> to everyone you know! In order to reach us mroe quickly the 
>>> government chose to release this message in e-mail form and you are 
>>> lucky to get it! The major news sources will not air this story until 
>>> tomorrow.
>>> Rick
>>>

>>>> * * *
>>>>
>>>> Washington, D.C. - The President has just declared a state of 
>>>> emergency due to the proliferation of a dangerous new strain of 
>>>> e-mail virus. Now believed to have been created by Iranian 
>>>> terrorists, the Scientific Advisory Panel concluded that the virus 
>>>> is now included in every hoax and chain letter circulated on the 
>>>> Internet. The content of these messages are believed to cause 
>>>> temporary hypnosis, placing the reader in a zombie-like state, in 
>>>> order to coerce the victim to redistribute the message without 
>>>> investigating its veracity or utility. Victims in quarantine were 
>>>> observed infecting dozens more colleagues and family members, in 
>>>> each case exposing the private e-mail addresses of all past victims. 
>>>> Due to the virus's logarithmic growth, estimators have estimated 
>>>> loss of time alone in the billions of American-hours.
>>>>
>>>> Research found that with each new victim the message grew in length. 
>>>> The President stated the many right brackets and exclamation points 
>>>> in the messages add to their "hypnoticness" and urged Americans to 
>>>> look out for these signs and delete the dangerous messages 
>>>> immediately. Also released was the Internet address of a new 
>>>> government site informing the public of five new US laws enacted by 
>>>> Congress yesterday regarding future handling of e-mail:
>>>>
>>>> http://www.netmanners.com/5-rules-for-forwarding-email.html
>>>>
>>>> All Americans are urged to visit the above sight and be on the 
>>>> lookout for any suspicious messages.
>>>>
>>>> White House staff
>>>> Official US governement
>>>>
>>>> * * *
>>>
>>>
>>
>>
> 
>

That URL again is http://www.netmanners.com/5-rules-for-forwarding-email.html.

NPR music + Stephin Merritt

NPR just launched their new music site, which nicely gathers music stories and media from a lot of different NPR shows. My favorite feature: Their media player is Flash-based. It’s a little quirky in Opera, at least, but so much better than the works-some-of-the-time WMP plugin that Opera used, and don’t get me started on Real.

Stephin Merritt was invited to be the first (at least I can’t find any others) participant in All Songs Considered’s “Project Song“. They gave two days use of a studio and engineer and asked him to create a song based on a photograph and phrase. They have video of the process and song, which turned out pretty good. It’s loop-based like those on The House of Tomorrow, but with less noise and reverb (please bring back the noise and reverb). The song’s subject might make a good villian for Lemony Snicket.

Portal

Check out the trailer to Portal. It’s a first-person puzzler where your only ability is to create circular space/time portals between two locations. Your movement (and gravity!) does the rest. The trailer is also pretty funny.

This would’ve made Berzerk so much easier.

LoadVars implements HTTP caching

Searching for info about Flash’s caching mechanism turned up endless posts on how to prevent caching, but none mentioned how LoadVars.load() handled server-sent Cache-Control headers. So I tested this myself.

In the SWF, I loaded the same URL once every 5 seconds using setInterval() and LoadVars.

The URL ran a PHP script that sent content along with Last-Modified and ETag headers based on its own mtime, and the header Cache-Control: max-age=0, private, must-revalidate. This basically means “browsers may cache this item, but must always check the server for updates before using it.”

It worked! Once Flash got those headers, load() would then make “conditional” GET requests: Flash included If-None-Match and If-Modified-Since headers, allowing PHP to respond with 304 Not Modified, and Flash used its cached copy of the data.

Flash seems to use the browser as a proxy to handle these requests and manage the cache, because Flash in Safari 3 shared a limitation of that browser, namely not supporting ETags; Safari only sends back an If-Modified-Since header for conditional GETs.

Please no more Red Book CDs

The Red Book standard defined how audio was to be encoded on a CD, and it was great for 1980, but it, well, kinda sucks now.

1. The error correction is too minimal to withstand real-world abuse (cars, friends, etc.).
2. Tracking is pretty loose, and a lot of players have trouble seeking to the exact beginning of a track. And, of course, skipping is a drag.
3. Uncompressed PCM isn’t space efficient for audio.
4. Ripping is painfully slow if you want it done well, thanks to the first two.

A better (if not ideal) solution is obvious: compressed files on CD-ROM. The CD-ROM standard has a lot more error correction and tracking data built-in, and the space eaten by that that data is minimal compared to what can be saved through modern compression.

For the audiophiles, start with FLACs, then fill the remaining half of the disc with a few grades of mp3s, or license-free formats. Order the folders by increasing compression ratio so that, when you pop it in a player, you get the highest quality your player will support.

Average direction in SQL

Given a column of polar directions in degrees, this is a single SQL expression to compute their average, for use in a GROUP BY query. Some functions may be MySQL-specific.

IF(DEGREES(ATAN2(
        -AVG(SIN(RADIANS(direction_deg)))
        ,-AVG(COS(RADIANS(direction_deg))))
    ) < 180
    ,DEGREES(ATAN2(
        -AVG(SIN(RADIANS(direction_deg)))
        ,-AVG(COS(RADIANS(direction_deg))))
    ) + 180
    ,DEGREES(ATAN2(
        -AVG(SIN(RADIANS(direction_deg)))
        ,-AVG(COS(RADIANS(direction_deg))))
    ) - 180
)

Thought someone might like to run across this.

Actionscript pains

I have an Actionscript 3 book lined up to tackle at some point, but generally my interaction with Actionscript is having to modify someone else’s SWF, most commonly old code from the 1.0 days. When I open one of these source files it sometimes takes time to even figure out where the code is. When I do find it, it’s not obvious when this code executes and in what scope. The object model of a Flash movie may not be much more complex than the browser DOM, but they’re quite different. I think part of my problem is that the structure of a movie (and the IDE navigation) is still foreign to me. The programmer in me wants to dig in with a spec in hand, and that often works with the projects I have to work on, but it would probably benefit me greatly to spend some time doing the boring beginner Flash tutorials.

Thoughts on a Javascript “validator”

(X)HTML and CSS have their own validators, but we need one for Javascript as well. JSLint could be part of it, but what I’m imagining would flag the use of “native” objects/interfaces not defined by W3C or ECMA standards. E.g., document.layers or window.ActiveXObject.

The hard part in doing this is finding a full Javascript interpreter with W3C DOM interfaces, but without the proprietary features that browsers have to support to remain usable on the web. A couple ways come to mind:

1. Rhino

John Resig has just implemented “window” for the Javascript interpreter Rhino, which, supposedly, is already based strictly on the ECMAscript standards. The short term goal of his script was to give Rhino enough of a browser interface to pass jQuery’s test suite, but the code could be branched to implement all current W3C DOM recommendations (and none of the proprietary interfaces). A Java app would set up Rhino, run John’s script, then run your script and simply report any errors.

2. A stricter browser

Most modern browsers are pretty malleable as far as letting user code clobber native functions/objects; in fact it’s a real problem. But this is convenient if you want to, say, overwrite all the proprietary features with your own code! With a whitelist in hand, you could use for-in loops to sniff out non-standard functions/properties and either delete or overwrite them with functions of your choice.

The advantage of the browser solution is that you could still provide the non-standard features (so the script would continue to run) while logging them. Using closures you could, in theory, “wrap” each non-standard function so that each of its calls would also call your logging function before returning the expected value. A crude example:

// may fail spectacularly
var _parseInt = window.parseInt;
window.parseInt = function (str) {
    alert('parseInt was called.');
    return _parseInt(str);
};
parseInt('2');

In practice, you’ll be at the mercy of the browser to allow native functions to be stored in variables like this. Sometimes it works, sometimes not. As for properties, you may be able to similarly log their usage with Javascript’s relatively new getters and setters.

So any idea where to get such a whitelist?