What would we be studying if our world was a software ?

Physics is just reverse-engineering the world

I once heard or read that somewhere and that make me smile.

Today I wondered if the same analogy could be applied to the other subjects we are teached in school.

If Physics is reverse-engineering, then Mathematics is using the World framework and developping new applications and unit testing with it.

Biology would be micro-debugging and desassambling it, maybe even re-compiling it.

History would be nothing more than writing and parsing the logs.

Geography would be mapping the whole network.

French (or English, or whatever your first language is) would be reading and learning the doc and man pages. And of course, foreign languages would mean learning new programming languages.

Sports would be the fun part, where you are playing you video games.

Did I forgot something ?

Debugging a Squirrel webmail

This is a quick blogpost, essentially as a reminder for myself :

A client of mine is using the Squirrel mail webmail. Once in a while, I have a call from him telling me that he can't access its account. The cause is always the same : there is way too much mails saved in his account and Squirrel mail choke on this, refusing to display the page.

The solution is simple, I just have to remove all the mails (except maybe the 100 or so last ones) and save them in a another directory, for archiving. The directory to save is /home/mailusers/c/contact/cur

But, thinking I was clever, instead of copying all the files to a new cur- save-2009 directory I thought it would be faster to rename the current directory to cur-save-2009 and create a new empty cur dir. Except that I forgot that I was loggued in as rootand the directory must have a user/group set as postfix...

That's it, I just had to not forgot to set the owner/group of the cur/ directory as postfix once cleared.

Database in UTF8 with Coldfusion

When setting up a Coldfusion application, do not forget to add to your datasource the following connection string :

characterEncoding=UTF8&characterSetResults=UTF8

It will ensure that your data is correctly saved and fetched using UTF8. This is the coldfusion equivalent of the more commonly known SET NAMES 'utf8';

Never use alert() for debugging

One thing I learned today is to never use alert() for debugging pruposes. When the javascript alert() function is called it blocks every other action until the OK button is pressed. It means that your javascript code that is immediatly after the alert() call is delayed until you press OK.

It also means that the thread your browser gave to the javascript engine is halted during all this time.

Imagine you are binding keyboard shortcuts on your website to specific actions. Like pressing Ctrl+S will submit the current form. Of course, Ctrl+S is already defined as a shortcut in the browser, so you will take care of preventing the default behavior in your custom function (using return false, e.preventDefault(), e.stopPropagation() or any method defined in your framework to do that)

The problem is that is you call alert() in your function, the Javascript thread will be halted before you can make the call to stop the propagation and thus, the browser will take control again and firing its default shortcut.

So my advice is that you should never use alert for debugging. Use the console.debug() method shipped in firebur or directly write to the DOM but do not use alert().

Writing a class in Javascript

I always have to refer to a manual or a webpage to remember the correct syntax for creating a new class in Javascript. Here it is :

myClass = function() {
    // Here I can define private variables and methods
    var myPrivateVar = "foo";
    var myPrivateMethod = function() {
    };
    // And now I will return an object, so it is the place
    // to put public variables and methods
    return {
        publicVariable: 'bar',
        publicMethod: function() {}
    };
}(); // Note that this function is executed and so the object is returned.