random thoughts about mozilla hacking and the computing world

Are You a Git Junkie?

Yup! You can still contribute to Mozilla even if you prefer git over mercurial. Here are the repositories for various mozilla projects.

Memoize it, the Python way!

I am currently reading Python Algorithms by Magnus Hetland Lie. It’s an awesome book about coding algorithms in python. You should check it out. One of the things that I thought it was really interesting is the use of decorators when memoizing in python.

In case you don’t know, memoization is the use of caches to retrieve previously computed values to reduce the time complexity of algorithms.

For example, this is the code for to compute the nth fibonacci number:

def fib(n):
    if n == 1: return 1
    return fib(n-1) + fib(n-2)

The running time for this piece of code is exponential. The memoized version of the function goes like this:

f = [-1]*n
def pre_fib(n):
    f[0] = 1
    f[1] = 1
def fib(n):
    if f[n] != -1: return f[n]
    return f[n-1] + f[n-2]

This version of the fibonacci function is polynomial. The key lies in the use of the array to retrieve previously computed values instead of computing it again.

Decorate Your Python

In Python, we can transform functions using decorators. It is a design pattern that allows the programmer to add behavior to existing objects. To decorate our fibonacci function, we need to first define what behavior we want to add to the function. This is how we define the decorator:

from functools import wraps

def memo(func):
    cache = {}
    def wrap(*args):
        if args not in cache:
            cache[args] = func(*args)
        return cache[args]
    return wrap

This piece of code simply wraps the function that we want to memoize and calls it if the value we are looking for is not in the cache. If it is in the cache, it simply returns the value from the cache. Here comes the beauty of using decorators to memoize the fibonacci function. IMO, it’s really elegant. See it for yourself:

def fib(n):
    if n<2: return 1
    return fib(n-1) + fib(n-2)

That’s it! It’s really easy. Now simply call the fib function to see it in action!

The Best Developer Job Advertisement Ever?

I stumbled upon this while working on my networking assignment. I made a http connection to my blog and this is what I saw in the http response headers:

X-hacker: If you're reading this, you should vist and apply to join the fun, mention this header.

Cool huh.

Python, The Lazy Mathematician’s Langauge

I was supposed to compute a exponentiation modulo 10 table for my networking homework. The question went like this:

Write a Exponentiation Modulo 10 table for 0 to 9. That is x = 0 to 9, y = 0 to 9 and the table values are x^y mod 10.

After computing the first few values, I got tired and fired up my python shell to get the computer to compute for me. This was my code:

>>> for x in range(10):
... print [x**y % 10 for y in range(10)]

This is the output:

[1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
[1, 2, 4, 8, 6, 2, 4, 8, 6, 2]
[1, 3, 9, 7, 1, 3, 9, 7, 1, 3]
[1, 4, 6, 4, 6, 4, 6, 4, 6, 4]
[1, 5, 5, 5, 5, 5, 5, 5, 5, 5]
[1, 6, 6, 6, 6, 6, 6, 6, 6, 6]
[1, 7, 9, 3, 1, 7, 9, 3, 1, 7]
[1, 8, 4, 2, 6, 8, 4, 2, 6, 8]
[1, 9, 1, 9, 1, 9, 1, 9, 1, 9]

Not bad huh. I am pretty impressed that python can do it in just two lines of code.

I Wanna Flip Bits, Not Burgers!

After talking to mentors throughout this week, I finally have two proposals for my GSoC application. I will be applying for SageMath and Thunderbird.

The Matlab Alternative

I’m really excited about contributing to Sage. It’s a open source alternative to popular proprietary products such as Matlab and Mathematica. What’s really cool about it is that it’s in my favorite language, python! I will be working on improving the SageNB usability. See my a draft of my proposal here.

Automate, automate, automate

As for Thunderbird, I am going to work on their automated email ISP configuration manager. Specifically, I’m gonna work on the database. They call it the ISPDB. It’s a database that the ISP configuration manager queries for server configurations of email domains. The user simply have to supply their email address and the manager will query for the configuration (server address, port, protocol, etc) of the email domain. Currently, there’s no way for users to submit configurations to ISPDB directly, so that’s what I’m going to implement for this summer. Another feature that I’m gonna implement is to allow users to edit (or propose changes) to the configurations.

Things are kinda hazy now but I think things will get clearer soon as I talk to the mentors. Hope my proposals get approved. 😉

Update: The url for the svn code repo is at


Google’s summer of code is finally here and Mozilla will be taking part as one of the participating organization. More information about how to take part are on the GSoC page and Mozilla’s SoC page. I have also found some tips on how not to apply for SoC. Found it really helpful. Meanwhile, you should start talking to the developers from the participating organizations to brainstorm ideas for your SoC project.

If you’re unsure about why you join GSoC, check out nushacker’s blog post. Working on side projects like GSoC adds lots of value to your resume.

How to use IRC?

I have realized that very few of us are familiar with this “ancient” chat client so I thought maybe I should come out with a guide on how to use it.

Download a IRC client

There are lot’s of IRC chat clients available. Here’s a list of them.

  • Chatzilla – A Firefox Add-on (Recommended)
  • Instantbird – Open source chat client powered by Mozilla
  • Adium – A OS x chat client
  • IRSSI – A CLI based IRC client. It’s my favorite IRC client

I would recommend you to use chatzilla. It doesn’t really require any other programs except Firefox itself.

Connecting to a chat server

My guide will be based on Chatzilla and Irssi. On chatzilla, simply click on the list of the servers on the welcome page as shown below.

For Irssi, (I will assume that you have already installed it by whatever package manager that you have)  use this command to connect to a chat server.

$ irssi -c

Joining a channel

Once connected, issue /join #[channel name] to join a channel. e.g /join #maildev Joins the #maildev Thunderbird channel. Once you are there you can start chatting just like how you would use any other chat clients.

Common IRC Commands

IRC commands come in the form of a / prefix. These are some of the common commands that I use.

  • /join #maildev – Joins the #maildev channel
  • /msg jyeo
  • – PMs a particular user

  • /who #nus – Lists the users in the #nus channel
  • /leave #maildev – Leaves the #maildev channel
  • /whois jyeo – Shows information about a user
  • /ping jyeo – Gives round trip information between you and the user

Other Resources

There are lots of guides for using irssi and Chatzilla. There is also a page full of commonly used irc commands. Like I always say, Google is your best friend.

Why You Should Be Fixing Bugs For Open Source Projects

Last year, I gave a short talk about why people should be fixing bugs for open source projects. I was asked by Prof. Damith to talk about it during the last lecture of his CS2103 class. I have decided to upload the slides and reiterate my points here because I have noticed that it has always been a trend for the CP3108 students to shy away from fixing bugs and choose to create an extension instead. So, I have three simple reasons why you should be fixing bugs.

You get to work on real software

In your typical software engineering class, you work alone or in teams on a project and you apply software engineering techniques that you have learned in class on the project. The project might be forgotten and ignored once the class ends. However, when you work on open source projects, you work on real working software. Software that is already in used by millions of people. What does that mean? It means that code/documentation that you contribute will be used by millions of people. A new feature implemented by you might change thousands of lives. To quote Steve Jobs, you get “to put a ding in the universe.” See the patches that I have contributed.

Impress People Around You

You get to impress friends when they use the open source projects that you work on. Let say a friend is using Thunderbird and finds that it lacks a feature or is encountering a bug. You can say to him “Have no fear, just give me some time and I will fix that in the next release.” Most importantly, contributions to open source are always a plus in employers’ eyes. You will definitely stand out when you say you have worked on a software that the employer is using.

You learn A LOT!

When I am fixing bugs, I learn a lot from the whole process of contributing code. I’ve learned numerous technologies that I have never heard of (XPCOM, XUL), coding standards to make code readable, software testing techniques and many many more.


There are many more reasons why you should be fixing bugs. The main reason why I am still doing so even when the class has ended is because I like doing it. Most importantly enjoy what you are doing.

Huh? Javascript? Xul? What are they?

As you are fixing bugs on mozilla projects, you would encounter these two languages, namely javascript and XUL. Many might not be familiar with them so here are some guides and resources to help you when you are fixing such bugs.

Javascript Resources

First up, javascript != java. Do not confuse them. They are entirely different languages. When I am fixing javascript bugs, the first place I will go is Mozilla Developer Network. Since you are working on the mozilla platform, it would definitely make sense to go to mozilla’s javascript standard. Other browser may implement it differently so I will generally discourage people to look for javascript guides/docs elsewhere. (Please do not go to W3Schools. See w3fools.) If you really wanna learn javascript from scratch, you might wanna check out codeacademy. You might also wanna look at Mozilla’s own re-introduction to javascript.

Printing Output in Javascript

There are some techniques we use when we debug code. Firstly, it is pure eyeballing. If you are gonna eyeball the code, do use MXR to do it. The syntax highlighting helps. Although I know there are some good developers who tend to only use their eyes to debug code, IMO this is a terrible way to debug code. Another technique we should use is the usage of print statements. In javascript, we do it by using alert()statements. It generates a pop-up with whatever you pass in as argument. Another way to do it is by dump() messages. This function outputs to the terminal. See MDN’s write up about it.

Enter Venkman. The javascript debugger

Venkman became my best friend when I am dealing with javascript code. It is kinda like the javascript’s gdb. You can see the values of variables, set breakpoints and step through code. It is extremely useful. It is basically an add-on for firefox and thunderbird. Download it here.

XUL Resources

Basically, XUL is XML. XUL files are where you define the layout of the program. Kinda like how HTML does it. Yes, both of them are really similar. Since XUL is a mozilla technology, I would recommend you to go to MDN for help. They have a XUL school and a XUL reference documentation.

A DOM Inspector Calls

You might have heard of firebug or the Chrome browser’s html inspector. The DOM inspector works the same way like them but it is used to inspect both html and XUL. If you are working on layout bugs, you can’t live with it.


When you are working on bugs in open source projects, always remember to RTFM (Read The Friendly Manual). Do get used to the MDN docs when you are working on these two languages. If you are still in doubt, don’t be afraid to ask! You may approach me (:jyeo), the tutors in CP3108 or any of the developers in Have fun squashing those bugs!

How to look for suitable mozilla bugs to work on

During the 2nd week of our CP3108B class, I gave some tips on how to look for suitable bugs. I didn’t have a chance to address everyone so I’ve decided to document all of the pointers down in this post just in case any of you need to refer to them.

Look for good first bugs and [mentor= bugs

Bugzilla uses these terms to label easy bugs. If you do not know how to search for these terms, refer to my previous blog post. The search links are there.

Make sure no one else is working on it

I would recommend you to work on bugs that labeled unassigned. Assigned bugs usually have someone already working on it. You wouldn’t want to redo someone’s work right? Also, sometimes contributors forget to assign the bugs to themselves although they have submitted a patch to it. Make sure you don’t see this in the attachment box:

Also, make sure the attachment type is not a patch file type. A typical patch should look like this.

Try to understand the bug

Most bugs are reproducible. If it is not, the bug may not be a bug at all. Reproduce the bug and see where the problem lies. You might need to download the latest Firefox or Thunderbird to test the bug. Do note that these builds are not the release builds. They contain the latest patches that are pushed into the code repository. Do not confuse them with the widely available release build.

If you are still in doubt about what the bug is all about although it is labeled as a good first bug, you should contact the mentor through irc.

I’ve found my potential bug, what’s next?

You should put yourself in the CC to find keep yourself in the loop regarding any recent comments or progress of the bug.

Lastly, get yourself a copy of the source and compile it from source. The instructions are here. I would recommend you to do this on a *NIX machine, either on a mac OSx or Linux. The required software are easy to download and install and the compilation process is faster on it.


When I was fixing my own bugs, I spent a lot of my time going around looking for answers and asking question questions on IRC. There are a lot of well documented sources on the net and helpful people on IRC. Just don’t be afraid to ask! Enjoy!