mozregression update

A good while ago I made a regression range finder for Firefox nightlies. It was a Python script intended to make it easier for people to manually find the regression ranges of bugs on the nightlies. The other day, someone actually used it! So I decided to revisit it and fix it up and make it easier to install. There’s more info about it here, but here’s a quick summary:

install with setuptools or pip if you know how to do that, otherwise checkout out the OS-specific installation instructions

run on the command line:

mozregression --good=2010-03-19 --bad=2010-09-12

Several nightlies will be downloaded and automatically run for you, asking you to check for the existence of the bug in each one, ending up with something like:

Last good nightly: 2010-09-08 First bad nightly: 2010-09-09


if you have questions, ask harth on #qa at

Jetpack: Showing Search Terms in Awesomebar

Note: this is not about searching from the awesomebar.

download addon·code on github

The awesomebar is one of my favorite things about Firefox. Especially compared to alternatives in other browsers – the awesomebar remains the fastest way for me to find where I want to go. Sometimes a site’s url and title aren’t enough to jog my memory however. At some point I wished Firefox would do full-text indexing for me. Then I realized that Google was already doing that, and there might be a way to hijack that power – by remembering what search terms you used to find the site and displaying that in the awesomebar. You can’t really get better than search terms, they put the value a site gives in your own words. Of course, you might find the site valuable for other things after viewing it, then you have no real choice but to manually tag it (or do you?).

I made a quick extension with Jetpack to do just that, implemented in the simplest possible way. It parses the referrer for ‘q=’, and appends that to the page’s user-set title (which is matched on in the awesomebar). It can be very helpful, but it was less helpful than I thought. It would be more helpful if the referrer persisted across link navigation, the referrer didn’t terminate after #, and more sites used ‘q’ to hold the query, but it was an interesting experiment, and I’d love to see more experiments in Firefox inferring tags for webpages.

Jetpack impressions

I enjoyed using the new Jetpack SDK, I’m a big fan. It took more than a couple minutes to get started but the docs were excellent and I love the CommonJS. I had to bust out the Cc but that’s just because the Places API isn’t quite ready yet. I only had to write 42 lines of code. I can confidently say I won’t be making a ‘regular’ addon again.

Javascript Neural Networks

There are tons of neural network implementations out there, but not many in JavaScript. This is pretty surprising given that JavaScript is awesome and neural networks could really benefit from being in the browser. One partial implementation was used to do some sweet Captcha OCR, and my last post was about using them to determine whether to display black or white text over a given background color.

I ended up creating brain, the missing JavaScript neural network library. I tried to make it easy to use. To use it you don’t have to know what a hidden layer is (but you can specify hidden layers if you want), you can also specify input (and expected output, for training) as hashes instead of arrays – good for sparse or labelled input, and you can pass trained networks around in JSON, which is useful with Worker threads.

If you want to find out more using neural networks from a programmatic perspective, this is a good introduction that just popped up.

Black or White Text? WCAG vs. Neural Networks

The other day I ran into a problem that some developers of color tools probably run into, which is: given a color, do you display white or black text over it? An algorithm based on the WCAG luminosity contrast ratio measure works great on most colors, but can be spotty. After looking at the WCAG formula, it seemed this problem was a good candidate for neural networks.

A couple weeks ago I finally sat down to try out the idea, and made a page where you can train your own neural network when to use black vs. white text (bonus: Worker thread example). After training it on a dozen or so colors, it matches the WCAG algorithm in most cases and does better in others. It’s kind of crazy that you can just throw data at this network and it will learn it. Not every problem can be solved by a neural network, but it’s cool to see it work when the problem fits. Might try out some other classifiers next.

I ended up making a simple JavaScript neural network implementation, you can check out the code on github.

Playing Around With js ctypes on Linux

I’m pretty elated about the ctypes module introduced in Firefox 3.6. ctypes.jsm is a module that lets chrome code call functions from shared libraries. This is a big win for a lot of extension developers. The baseline is that you no longer have to create an XPCOM component to call C++ code from javascript.

I had wanted to speed up some calculation-heavy js I was using in my extension by writing it in C++. Writing a C++ XPCOM component would be a painful process, so I decided to ditch the effort…then I found out about ctypes!

Ctypes can help with calling Win API functions and such, and there are some examples of this on the ctypes.jsm wiki page for this. My use case however was loading my own shared library, so I decided to put together a short end-to-end tutorial on how to call your own C code from your extension.

First we write a little C function and put it in add.c:

int add(int a, int b) {
  return a + b;

To get a shared library from this code, compile with these commands:

gcc -fPIC -c add.c
gcc -shared -o add.o

Now you have a file called, which we can load from ctypes. Say you put in your addon’s content directory, then your javascript might look something like this:


function add(a, b) {
  var file = getFile("chrome://myext/content/");
  var lib =; 

  var addc = lib.declare("add",
                           ctypes.int32_t, // return type
                           ctypes.int32_t, // arg1 type
                           ctypes.int32_t // arg2 type
  return addc(a, b);

function getFile(chromeURL) {
  // convert the chrome URL into a file URL
  var cr = Components.classes[';1']
  var io = Components.classes[';1']
  var uri = io.newURI(decodeURI(chromeURL), 'UTF-8', null);
  var fileURL = cr.convertChromeURL(uri);
  // get the nsILocalFile for the file
 return  fileURL.QueryInterface(Components.interfaces.nsIFileURL).file;

Now try calling your add function from js. The getFile function isn’t that pretty, hopefully in the future there will be a way to open a library from a chrome url. Also, you can’t use ctypes from Worker threads, so that is very sad.