Posts

Showing posts from April, 2014

The interoperability of Web Component polyfills

At the moment, there are two polyfills for the upcoming Web Components standard (roughly, for widgets): Polymer by Google X-Tag by Mozilla Fortunately, the three ways of writing a Web Component (via the Polymer polyfill, via the X-Tag polyfill or by using the APIs directly) are interoperable. Quoting “ Custom Element Interoperability ” by the Polymer team: We’re happy to say that, yes, custom elements of any variety (be they Polymer, X-Tag or vanilla) can all happily coexist. The blog post explains how that works and provides an example that you can download from GitHub. Third Web Component polyfill: @b_lionel told me about Bosonic , which is partially based on Polymer and also interoperable .

Academic Versus Journalistic--A Throwdown

Image
tcs.cam.ac.uk Lately, I seem to be coming up against a number of academics who hate the faintest whiff of journalism. “Journalists are overly emotional,” one sniffed, nose resolutely in the air.   “The writing is too sensational and of dubious merit.” “There is no careful reasoning in journalism,” another added.   “There’s not even a recognizable logic to it.   It’s all sensational idiocy written by lemmings.   They follow one another right over the cliff.” It is the same disdain reserved for Wikipedia (Garbage, I tell you!) and Google searches (A plagiarist’s only friend!). A quick search of much maligned Google yielded the following, courtesy of The Hong Kong Polytechnic University English Language Centre : “Academic writing style:   writes to appeal to logical reasoning; ideas logically organized; longer structured paragraphs; longer sentences; sentences always grammatically correct; rhetorical questions are rarely used; abbreviated words are rarely used; informal words and phrase

Handling required parameters in ECMAScript 6

In ECMAScript 5, you have a few options for ensuring that a required parameter has been provided, all of which are somewhat brittle and inelegant: function foo(mustBeProvided) { if (arguments.length < 1) throw new Error(...) if (! (0 in arguments)) ... if (mustBeProvided === undefined) ... } In ECMAScript 6, you can (ab)use default parameter values to achieve more concise code (credit: idea by Allen Wirfs-Brock): /** * Gets called if a parameter is missing and the expression * specifying the default value is evaluated. */ function throwIfMissing() { throw new Error('Missing parameter'); } function foo(mustBeProvided = throwIfMissing()) { return mustBeProvided; } Interaction: > foo() Error: Missing parameter > foo(123) 123 Related reading: Keyword parameters in JavaScript and ECMAScript.next

What is the true nature of lions and hyenas?

Image
Kevin Richardson is a South African zookeeper who has been accepted into several clans of spotted hyenas and prides of lions. His years-long relationship with these animals illustrates a different side of them: they can be affectionate and cuddly. Given how many atrocities humans commit to get their food, you have to wonder what one should consider the “true nature” of lions and hyenas. More information: A 15 minute documentary with Kevin Richardson shows him cuddling lions and hyenas. He also tells stories about their personalities and mentions interesting facts such as hyenas being matriarchal. Lions may be extinct within 20 years. At Richardson’s website you can volunteer and donate to help protect them and other African wildlife. Richardson has founded a wildlife sanctuary whose goal it is to “minimize the number of large carnivores being kept in captivity and to highlight the direct link between the cub petting industry and the ‘canned’ hunting industry, by educating

No Strangers To Tragedy

Image
Courtesy CBS News Two recent stories continue to haunt me, as I’m sure they haunt the rest of the nation. At a Pennsylvania high school , young Alex Hribal, age 16, greeted his fellow students one morning last week by stabbing 21 of them with a set of kitchen knives.   He also attacked a school security officer.   Four of his victims remain in critical condition. Tomorrow, the school will reopen so parents and students can do a walk-through.   The school plant has been cleaned and sanitized of the blood and gore, but the fear, I’m afraid, will be much harder to clean away.   Classes begin on Wednesday, but it is safe to say no one in the community will be the same again. Hribal did not stand out as a troubled teen before the rampage.   Mental illness does not necessarily broadcast its presence to the world before bullets fly or steel flashes, bloodstained and corroded, in a school hallway.   There are sleepers out there, psychologists warn us.   Some of them sleep in our homes with u

The maximum call stack size

Are you curious how many recursive calls you can make on your JavaScript engine? How many recursive calls? The following function lets you find out (inspired by a gist by Ben Alman). function computeMaxCallStackSize() { try { return 1 + computeMaxCallStackSize(); } catch (e) { // Call stack overflow return 1; } } Three results: Node.js: 11034 Firefox: 50994 Chrome: 10402 What does this number mean? Mr. Aleph pointed out to me that on V8, the number of recursive calls you can make depends on two quantities: the size of the stack and the size of the stack frame (holding parameters and local variables). You can verify the latter by adding local variables to computeMaxCallStackSize() – it’ll return a lower number. Tail call optimization in ECMAScript 6 ECMAScript 6 will have tail call optimization : If a function call is the last action in a function, it is handled via a “jump”, not via a “subroutine call”. T

In search of the perfect technology for slides

I many cases, if you are presenting in front of an audience, you will create slides, visual material of some kind. I’m a very visual person myself and learn much better if I can read in addition to listen. Slides are also helpful when you lose attention for a few seconds. There are a variety of software technologies out there for helping you with creating slides. Following are ones that I find intriguing: PDF: somewhat surprisingly, I still find PDF the best format for slides (I would have expected it to be HTML by now). Why? You get a single, easily portable and printable file that scales well to various screen sizes and resolutions. Furthermore, all modern web browsers have excellent PDF support, which means that you don’t even have to “leave the web” if you want to check out a PDF file. Lastly, Speakerdeck is a convenient way of putting PDF slides online. As examples, you can check out my slides . LaTeX: works remarkably well for slides, via the built-in Beamer packag

Making checkbox labels clickable via <label>

The <label> element has been around for a while, but I still don’t see enough websites use it. In lets you make labels of checkboxes and radio buttons clickable. Without <label> , you need to click directly on a checkbox in order to toggle it: Some option <input type="checkbox"> Some option If you use <label> , the text after the checkbox becomes clickable: Some option <label><input type="checkbox"> Some option</label> For styling via CSS, you may sometimes need another, more verbose, variant of this element: You can link a label to its control by referring to the control’s ID via the label’s attribute for (thanks to Evgeny Gorbachev for mentioning this use case for this attribute). Some option <style> input:checked + label { color: green; } </style> <input id="check1" type="checkbox"> <label for="check1">Some option</label> <label> works the same for rad