Tuesday, August 26, 2014

Online books

The other day, while googling for a quote from George R. R. Martin's "A Song of Ice and Fire", I came across this site that simply hosts all the books in the series released up to date. While I'm quite certain that this violates copyright law, it sure is convenient, even though I own a paper copy of those books.
The site is hosted in Phoenix, Arizona. I wonder how long it will stay up until taken down.
It's a little known fact that Firefox's Spidermonkey has switched to a new RegExp engine recently. They abandoned YARR, which they took from WebKit's JSC a few years ago, and replaced it with the high-performance Irregexp from Chrome's V8. Porting it to Spidermonkey certainly was a tremendous job. As a result, their benchmark score on Octane/regexp improved a lot. (Orange for Firefox/Spidermonkey, green for Chrome/V8)

But for some reason, it's still pretty far away from V8's score in that particular benchmark. Let's speculate on why this is the case.

Debugging promises in Chrome

With the upcoming Chrome 36, Javascript Promises as specified in the upcoming revision of the ES6 standard are going to be activated by default as part of V8. Right now, you can already try it in the Dev or Canary release channels.
While a very useful addition to the language, especially with regard to asynchronous programming, Promises are peculiar when it comes to debugging: it swallows exceptions by default.

AKG k701 in anime

The other day I saw some nice wallpapers. Apparently, anime girls and headphones really go well together, as far as wallpapers are concerned. So I got a bit into researching. It turns out that some headphones that show up in animes are actually real products. Like AKG's k701, for example shown in K-ON.

That's actually a nice pair of headphones, from the looks of it. So I looked it up on Amazon. It's been on the market since 2008, and seems to be generally well-received. For around 200 Euros it's not too expensive.

However, I somehow doubt that most people, including Mio here, would use it to casually listen to music. The k701 is designed as studio headphones with open back, meaning it leaks sound to the environment. The advantage is of course a better sound. Another thing is that the k701 works best with the appropriate amplifier. Buying it to plug it into a portable music player of any kind is just a bad investment.

I guess the k701 is put there mainly because of its distinctive design. Nevertheless, it seems that I wasn't the only one whose attention was caught by those headphones.

Mongolian Vowel Separator

In ECMA-262 5.1, white space characters are defined in chapter 7.2 as following characters
\u0009 \u000B \u000C \u0020 \u00A0 \uFEFF
... and Other category "Zs", as defined for Unicode.
Well, that's simple, right? The Unicode database is available for download and easy parsing. Let's do this

HTC One

So a few days ago, I smashed my Nexus 5's display. The glass cover cracked, but everything else is still fine. According to iFixit however, repairing the screen is not as easy as just replacing the glass cover. The touch screen below is fused with it, and the cheapest replacement from Hongkong will cost 80 EUR. It's twice as much if I send it to a repair workshop.
For for the mean time (and also because of this nice excuse), I'm in the market for a new Android phone. Some requirements
  • It cannot be another Nexus 5. I'm confident that I will eventually fix the smashed phone by replacing the display. What am I supposed to do with two Nexus 5s?
  • The display has to be larger than 4.5 inch and at least 720x1280. I simply cannot go back to the days of low-res displays.
  • There must be a way to install stock Android of at least 4.3.
  • The processor should be somewhat above average.
  • I don't have 600 EUR to spend.
  • Battery life is sort of important.

Finding De Bruijn sequence to calculate Math.clz32.

As specified in the latest Javascript ES6 draft, Math.clz32 (formerly Number.prototype.clz) calculates the number of leading zeros to an 32-bit integer, and returns 32 for 0.
The simple implementation for this is therefore:
function clz_simple(x) {
  for (var i = 0; i < 33; i++) {
    if (x & 0x80000000) return i;
    x <<= 1;
  }
  return 32;
}
In the worst case, the loop is executed 33 times. A smarter implementation would use binary search.

Quake 3 in Javascript

This is pretty impressive. Even more impressive is the technology behind it.

Apparently, Quake 3 strictly separates game engine from game content. The latter are packaged as platform-independent bytecode and run in a virtual machine. That is, either interpreted, or, for more common platforms, compiled to machine code. The advantages are, among others, platform independence and sandboxing potentially unsafe game content.


The Javascript port includes a Javascript backend for that virtual machine: the bytecode is translated to Javascript, and the resulting Javascript source string is fed into eval, and run by the Javascript virtual machine inside the browser.

The performance is not bad, considering that we have a double-nested virtualization. The game runs very smoothly on my Chromebook Pixel.

Chromium blog post

Something from work:
V8 compiles optimized code in the background.

with scope, const and var.

Consider the following functions:

function foo() {
  var o = { a: 1 };
  with (o) {
    var a = 2;
  }
  return(o.a);


function bar() {
  var o = { a: 1 };
  with (o) {
    const a = 2;
  }
  return(o.a);
}

Eagle-eyed readers will have noticed that the only difference between the functions foo and bar is the variable declaration inside the with scope.

foo() returns 2.
bar() returns 1.