2012-12-31

Surprise is data

One of the best ways to leverage subconscious data about myself, my experiences, assumptions and otherwise, is to notice and write down what I get surprised about – especially when traveling, or in changing circumstances in any other capacity. I am fairly certain this idea comes from one of Paul Graham's essays (though I couldn't find which – if you know, do say, and I'll link it; it's a great read).

I was visiting family in Sweden over Christmas, and what surprised me the most during those ten days, was how wonderfully quiet it is in over there. In a way this is old news to me, as the reverse was by far the biggest surprise about moving to the US three years ago – everything everywhere pollutes the audio spectrum with ambient noise. It is not just the traffic, but air-conditioning, refrigerators, dish-washers, washing machines, dryers, computers, and all the senseless amounts of intentional noise that trains make, music playing everywhere in places of commerce, and so on. Being surrounded by it for so long, I have apparently become so steeped in the noise that my body equates it with an omni-present tax on human well-being. As quality of life goes, I much prefer paying Sweden's tax rate over this sensory tax.

It's a difference in engineering culture: in Sweden, low (or ideally no) noise emissions is an important and expected fitness criterion, for everything – and has been for at least two decades, probably more. Noise levels are one of the data points listed (in dB(A)), when buying a new fridge or dish-washer, the governmental institution Arbetsmiljöverket (loosely translated "the work agency") offers a free iPhone / Android app for measuring ambient noise, and both in the large (architecture, work place environment, city planning, et cetera) and small (tools, implements), fighting noise is not just a matter of engineering pride or regulations, but also pretty much taken for granted.

In the US, it often feels like the noise aspect is a built-in proof that something is working properly, rather than the opposite. In the eighties, you could learn to hear that your C64 basic program was operating correctly via resonance frequencies from the CPU that leaked out through the loudspeaker (due to improperly grounded circuits, I presume), and any car mechanic worth their salt can tell a lot about a car by the sounds it makes.

I am surprised so little has changed here since those days.

2012-11-25

View rendered source bookmarklet

I haven't made a bookmarklet from scratch in a long while, but after looking at this codepen I wrote a while ago to demonstrate copying one javascript document into another, it occurred to me that it could easily become a modern "view rendered source" bookmarklet, that might even work on iOS devices and the like, where a view source feature is sorely missing.

Here is the result: view rendered source

On clicking it, you get a "view source" iframe with the source of the current document, in whichever state it was when you clicked the button, and when you click (or tap) that it goes away again.

I have yet to try it on an iDevice myself, but I have high hopes. To my surprise, manually entered bookmarklets like this one refuse to run in a modern Safari, though smaller ones that load their js payload over the wire instead seem to work, so I might make a gist of the code too, if that is what it takes.

Enjoy!

2012-10-18

Absolute url from a relative url and base_url

Today I needed a javascript url resolver to get absolute urls for urls mentioned in css files - resolved against the url of the stylesheet, not the current page. Fortunately, your browser already implements this natively, it's just not exposed in DOM APIs, so it needs a little DOM cleverness to coax out the functionality:

You can play around with it a little here, to see that your browser supports it, too. You should even be able to use a relative URL as the base_url parameter, which should get resolved against the page url -- which here is the jsfiddle url shown, as that demo is running in an embedded iframe, rather than on this blog itself:

It of course won't work in node.js, but hopefully it'll be useful to something you or others are doing, too. Use as you like; it's all public domain / MIT licensed goodness, whichever you fancy.