Posts

Showing posts from December, 2013

Printing Markdown files on GitHub

GitHub displays Markdown files so nicely, it’s a shame there is no print view where all the toolbars etc. are hidden. Note that printing doesn’t necessarily mean that paper is involved. For example, on Mac OS X, you can print to PDF files. This blog post explains three ways of printing Markdown files that are hosted on GitHub: Markdown tools: such as kramdown can be used to turn Markdown files into HTML files that can be printed. Safari’s Reader mode [1] : With many pages, Safari displays a “Reader” button in the address bar. Clicking it usually removes all clutter around content. You can print a page in Reader mode. Disadvantage of this solution (especially compared to the next one): You lose most of the syntax highlighting of source code. Bookmarklet [2] : Create a bookmark with the following URL, click it and everything around the content is removed. javascript:var content = document. querySelector('article'); var body = document.quer

JavaScript gains support for SIMD

Recently , a new JavaScript feature has landed for the next Firefox Nightly: an API for SIMD (Single Instruction, Multiple Data). This blog post explains how the API works and how it fits into the JavaScript landscape. What is SIMD? SIMD is the ability of a CPU to apply an operand to vectors of values, instead of single values. For example, a CPU may be able to add two vectors v and w by adding their components, hence applying the single instruction addition to multiple data: v + w = 〈v 1 , …, v n 〉+ 〈w 1 , …, w n 〉 = 〈v 1 +w 1 , …, v n +w n 〉 SIMD brings speed-ups to many kinds of number crunching (3D computations, image processing, singal processing, etc.). John McCutchan (Google) and Peter Jensen (Intel) have proposed a JavaScript API for SIMD. That API initially grew out of the SIMD support in Dart, because Dart SIMD code needed to be compiled to JavaScript. At the moment, the API provides two data types: float32x4 (C type: __m128): four 32 bit floating point n

ECMAScript 6: the new array methods find() and findIndex()

Update 2014-05-08. Newer version of this post: “ ECMAScript 6’s new array methods ” Two new Array methods (proposed by Rick Waldron) are in the latest ECMAScript 6 specification draft: Array.prototype.find() Array.prototype.findIndex() This blog post describes them. Array.prototype.find(predicate, thisValue?) The signature of the callback predicate() is predicate(element, index, array) find() iterates over the array (while skipping holes) and calls predicate for each element. If predicate returns true , find() stops iterating and returns the current element (1). If the callback never returns true , find() returns undefined (2). This method could be implemented as follows. Array.prototype.find = function (predicate, thisValue) { var arr = Object(this); if (typeof predicate !== 'function') { throw new TypeError(); } for(var i=0; i < arr.length; i++) { if (i in arr) { // skip holes

ParallelJS: data parallelism for JavaScript

Updates: [2015-01-05] ParallelJS has failed . It apparently wasn’t powerful enough. Its experimental implementation will be removed from SpiderMonkey (Firefox’s JavaScript engine). [2013-12-28] A low-level JavaScript API for SIMD is another avenue for parallelization (within a single processer core). JavaScript is still a very sequential language. That is slowly changing. This blog post describes ParallelJS , an effort to bring data parallelism to JavaScript. Background Concurrency versus parallelism Parallelism: more than one task is executed at the same time. That means that the tasks run on different processors or processor cores. Concurrency: more than one task makes progress at the same time. Often, tasks depend on each other. Concurrent tasks may run in parallel, but they can also be run via time slicing (virtual parallelism, if you will). These terms are not always used precisely, but the context usually makes it clear what is meant. Kinds of

Using strict mode in the Node.js REPL

If you want to use strict mode [1] in the Node.js REPL , you have two options. Option 1. Start the REPL as usual, wrap your code in an IIFE [2] : > (function () { 'use strict'; 'abc'.length = 1 }()); TypeError: Cannot assign to read only property 'length' (Assigning to a read-only property fails silently in sloppy mode.) Option 2. Use the Node.js command line option --use_strict : node --use_strict Afterwards, everything you write in the REPL is interpreted in strict mode: > 'abc'.length = 1 TypeError: Cannot assign to read only property 'length' References: JavaScript’s strict mode: a summary JavaScript variable scoping and its pitfalls

Man In The Mirror

Image
The Conversion of St. Paul, 1767 by Nicolas-Bernard Lepicie I’ve spent the last few months on self-imposed sabbatical to read and write about St. Paul, a guy, as it turns out, I didn’t like very much.   After reading a biography of Charles Manson last summer, I found more connections between Charlie and Paul than I did between other apostle-saints and Paul.   In fact, Paul fits the profile of exactly what he was:   a cult leader.   By force of will and personality, he cajoled, bullied, commanded, and guilted others into following his lead.   When they didn’t do what he wanted, his rage was legendary. The part of the research I became obsessed with was the way Paul changed his life.   There are two stories about his “conversion”:   one where he is knocked to the ground by a flash of light and a voice demanding to know why he is persecuting the followers of Jesus; and two, a quieter, more internal change from persecutor to early Church leader.   Whatever story one believes, it is a sta

Why are there so many array-like objects in the DOM?

Tweet by Leon Arnott: #TIL the reason the DOM has so many "array-like objects" that aren't functional arrays… is because in Javascript 1.0, there were no arrays. Explanation: ECMAScript 1 does have arrays, but it corresponds to JavaScript 1.3. JavaScript version numbers apply to the JavaScript engines implemented by Netscape/Mozilla. The cross-engine way of referring to the capabilities of the language are thus ECMAScript versions. Arrays were indeed added after JavaScript 1, as this page shows, which lists the additions for version 1.1. More information on array-like objects and arrays: JavaScript quirk 8: array-like objects Arrays in JavaScript