Blog de Humpty

Express your heart's desire

Recent Posts


Email Notifications


Cool Sites


January 2010 - Posts

Bizarro World

This country is crazy. Just read how Obama is going to start being concerned about the middle class again. Did it really take the loss of Edward Kennedy's seat to a Republican to bring about this sudden change of heart? Obama, did you think your actions concerning the middle class were sufficient while you were busying yourself supporting Bush's bank bailouts and trying to sell us out to health insurance companies? I appreciate your newfound concern Mr. President, I really do, but your previous actions demonstrate the kind of policies you'd prefer to pursue.

The thing that gets me the most about this whole mess is how much money there seems to be available for fighting wars, but when it comes to helping Americans suddenly the country's tapped out. Domestic programs get cut while the war in Afghanistan gets tens of thousands of new troops. Seriously, how crazy is a country that so enthusiastically supports war on foreign soil but cares so little about its own.

"These become the elite. Through these, the attempt begins to create a condition whereby the remainder of the planetary entities are enslaved by their free will."

The people I can't get are those that support decisions like the Supreme Court's to allow corporations to spend unlimited amount of money on political campaigns, because of free speech. The beneficiaries of this money I can understand being excited, they're greedy. But the people who won't get any direct benefit from this, the people who are far more likely to be harmed by this ruling, I don't get their support. Screaming and shouting about defense of free speech, really? The same corporations that admitted to lying about the addictiveness of smoking, the links to cancer, these are the corporations you want to empower to be able to spend money on political candidates? Am I living in bizarro world! You want to support a foreign owned company spending money on a candidate that'll support laws favoring their country to the detriment of the U.S.? Free speech, really?

This whole left vs. right, liberal vs. conservative fight isn't getting this country anywhere productive. While we fight it out over abortion, gun laws, or any myriad of social issues our pocketbooks get lighter and lighter while prices get higher and higher. Bank fees become more numerous and punitive. But hey, let's argue about something else instead.

Posted: Mon, Jan 25 2010 11:00 PM by Humpty
Filed under:
Geeky programming stuff

So I'm still working on LastTab 3. Yeah I know I mentioned this in late 2008, but a sudden impromptu job search last year shifted my energies elsewhere. In any case I'm back to it. I'm actually not going to talk about LastTab specifically but a few cool things I discovered this weekend I want to share.

Consolas programming font

So I installed Visual Studio 2010 beta 2 and discovered it looks pretty sweet. Specifically it was that damn font that took my breath away! A quick trip to Tools -> Options -> Environment -> Fonts and Colors revealed the name: Consolas.

Consolas font

Apparently this thing has been around for a few years now but I'm just now learning about it. According to Wikipedia it's available as of Windows Vista / 7 or Office 2007, it's also a download from Microsoft if you use Visual Studio 2005+. I have ClearType enabled on my system and apparently you need this or it looks like crap. Not only that I've heard it looks its best on Vista or 7, not XP. But if you do have all of that this font looks good! Not even that but I also got back more editing space. Using Courier New I could only fit 159 characters of text x 48 lines, now I can fit 182 x 51.

JavaScript Closures

The other thing that got me jazzed enough to write is my ever increasing use of closures while writing LastTab. I've been using object notation to write the code ever since its inception, way back in 2004. In case you're not familiar with it it's simply this:

var object = {
property1 : value,
property2 : value

It's used all over the Web to keep variables and functions nice and tidy so they don't interfere with other scripts. With LastTab 3 I'm rewriting everything and I have a good deal more objects than the 2.x series. Not just that but I'm emulating as best I can object orientation: classes, inheritance, polymorphism, private members. Closures have been instrumental to this. Not always specifically to enable OOP but closures make it much nicer. Below is some sample code to illustrate this:

let LastTab = function() {
/******************** Classes ********************/
function Delegate(thisObj, func) {
return function() { func.apply(thisObj, arguments); };

function List() {}

/******************** Class Definitions ********************/
List.prototype = {
get Enumerator() {
for(let i = 0; i < this.length; i++)
yield this[i];

Add : function(item) {
return item;

Clear : function() {
this.splice(0, this.length);

Contains : function(item) {
for(let i = 0; i < this.length; i++)
if(this[i] === item)
return true;
return false;

Find : function(predicate) {
for(let i = 0; i < this.length; i++)
return this[i];
return null;

FindIndex : function(predicate) {
for(let i = 0; i < this.length; i++)
return i;
return -1;

Insert : function(item, index) {
this.splice(index, 0, item);

Remove : function(item) {
let index = this.indexOf(item);
if(index >= 0)
return this.splice(index, 1)[0];
return null;

/********** Infrastructure **********/
__proto__ : new Array(),
constructor : List

return {
Delegate : Delegate,
List : List

I left out a lot of code but what I have is just for illustrative purposes anyway. In the code LastTab is a variable, using JavaScript 1.7's let statement, and I'm assigning it a function. Or so it seems until the very end when I execute said function and the return result is an object using object notation. It's a style that jQuery and other frameworks use.

What's the point you ask. Well the whole thing is a closure so all the code within that anonymous function is free to talk to all the other code in the function, even though users of that LastTab variable only see two properties on the object: Delegate and List. You can have private classes essentially. Another useful consequence of putting everything in a closure is that it then effectively works like a namespace. Instead of me having to write LastTab.List all over the place I can simply say List.


Namespaces segues into another interesting thing to share. Using closures to emulate namespaces is one of the nice benefits / side-effects of using them, but it's limited to just the code within it. If you find your codebase ballooning into the thousands of lines you'll undoubtedly want to put some of that code in other files to make it more manageable. That's where the with keyword can come into play to again simulate namespaces.

Now I first learned about JavaScript closures from Douglas Crockford and more so from this article. Douglas Crockford is a smart guy but one thing I was a little puzzled about was his branding the with keyword as evil. The crux of the argument is you don't really know if the variable you're using within a with block is attached to the object you specified in the with statement or not. Basically you can shoot yourself in the foot without knowing it. I will agree to that but used carefully the with statement is tremendously useful.


LastTab.Focusing = function() {
/******************** Classes ********************/
let Focuser = {};

/******************** Class Definitions ********************/
Focuser.__proto__ = {
Load : function() {
gBrowser.mTabContainer.addEventListener("TabClose", new Delegate(this, this.OnTabClose), false);
gBrowser.mTabContainer.addEventListener("click", new Delegate(this, this.OnTabBarClick), false);
gBrowser.mTabContainer.addEventListener("mousedown", new Delegate(this, this.OnTabBarMouseDown), false);

return {
Focuser : Focuser


In the above code you see the Delegate class that I defined within the LastTab object being used. You only know it's really LastTab.Delegate because you've seen the code above. But that is the point. If you're writing your own code or examining the object library of someone else's you know which objects are in particular namespaces. If you get it wrong you get an error.

With JavaScript getting it wrong often times won't throw an error, it'll simply create the object! Well not always, but it's easy to shoot yourself in the foot without realizing it. With Java and the .NET Framework everything is a class and every class is in a namespace. That means at a minimum to call a class method or property you have to write something.something in your code. If that something isn't really a part of that other something you'll get an error, even in JavaScript. If you follow a similar discipline in JavaScript you'll never run into the problems in using the with statement.

So up above in the code LastTab.Focusing is being used by me as a namespace declaration; and Focuser is a static class within that namespace. If LastTab doesn't already exist I'll get an error, even though the code is within a with block. Now if I left out the LastTab part then I would have created a property on the LastTab.Services object and ended up with LastTab.Services.Focusing, not what I wanted.

All in all I think the way I'm using closures is pretty neat and is making the code more maintainable. I'm using with() to simulate the using statement in C# and closures to approximate the namespace statement. Things will probably change as I continue developing, but felt like sharing all the same.

Posted: Sun, Jan 17 2010 11:08 PM by Humpty
Filed under: ,
Visualizing Harmonics

This was too neat not to share. It's a video demonstrating different harmonic nodes from salt vibrating on a table.

Posted: Mon, Jan 4 2010 8:33 PM by Humpty
Filed under: ,