Blog

Sunset after a Spring shower

Just thought this was an amazing view from my balcony this past Sunday.

Belleville Sunset after Spring Shower (Vivid)

See more at my Zooomr Photostream

JavaScript functions: First-class objects

In JavaScript, functions are first-class objects, meaning that they can be created, manipulated and passed around in the same manner as other objects/variables in JavaScript. For example, a function can be created, stored in a variable or even be the return value of another function, as seen below:

function getPower(power)
{
  return function(x)
  {
    return Math.pow(x, power);
  }
}

var x3 = getPower(3);
window.alert(x3(3)); // Outputs 27.

In the rather stupid and contrived example above, we make a function getPower() that returns another function which raises the given value to the exponent supplied by calling getPower(). (This is a bad way to do things for numerous reasons, but is just shown for the sake of providing a simple example)

We then call getPower with a power of 3 and assign the returned function to the variable x3, and the output is as expected. Defining “inline” functions this way and manipulating them is closely associated with the concept of anonymous functions.

Continued

Using the Basic Constraints extension in X.509 v3 certificates for intermediate CAs

It’s not often that you’ll be creating your own X.509 certificates for a web server, since any certificates that you create (self-signed or signed by your own CA) will not be trusted by most browsers (IE, Firefox, etc.) since they were not signed by one of the many Certificate Authorities (CAs) that have been automatically trusted by the browser. If you do decide to use one of these certificates on your web server, you’ll have to navigate through a Byzantine series of screens to “confirm” that you trust the server’s certificate. (Though this is annoying, it may be ultimately beneficial in today’s era of phishing and other malicious behaviour.)

Continued

The misguided war against IE6

war-on-ie6

IE6 is universally reviled among web developers for its poor support of web standards, namely with CSS and even PNG transparency. Many hours of hair-pulling frustration have been wasted when developing web applications, trying to “get things working right” in IE6 after having already spent so much time making a site look good in most of the other browsers. IE7, while better, is still not that great.

So, you may be surprised to know that I think the “War against IE6” is misguided and perhaps a bit out of touch with reality. It’s not that I don’t believe in their message, but rather that I believe it’s somewhat impractical. The unfortunate reality is that support for IE6 will have to continue for some time.

Continued

JavaScript Event Delegation

JavaScript Event Delegation is a technique you may have heard of. It’s a different way of using event handlers that offers clear benefits and is becoming more popular amongst web developers. I’ll give a brief overview of event delegation in JavaScript, along with why you should consider it. Note that this tutorial will use the great jQuery library (v. 1.3.1) for most examples.

Delegation

Delegation is a fairly well-known design pattern. In short, it is a way for a method to produce its result simply by calling a method on another object, thus delegating responsibility to that object to provide the functionality needed by the method. For example, a Cashier object could store a delegate object called Calculator. Calling Cashier.addToTotal(value) would simply delegate to the contained object, calling Calculator.addToTotal(value).

How is delegation different than inheritance? With inheritance, the subclass inherits all of the functionality/behaviour of the parent class. You may not want or need this; in the preceding example, it would not make sense to have Cashier extend from Calculator simply because we wanted the addToTotal() behaviour/functionality. Delegation allows the behaviour advertised by a certain object/class to be provided by another.

Continued

Java Polymorphism and Overriding Methods

Most Java developers will be familiar with polymorphism – we’ve all seen the example of the Dog and Cat classes inheriting from some abstract Animal class and having their say() methods produce different results. But it’s still worthwhile to look at a few simple examples to reinforce the concepts.

Continued

iPod Touch

Turned on!

I finally bit the bullet and got an iPod Touch 16 GB, after months of telling myself I shouldn’t. And yes, I’m thoroughly enjoying my new toy. ๐Ÿ™‚ So why did I get an iPod Touch when I could have just got an iPhone for the same upfront cost? A few reasons:

  • I don’t use my cellphone a lot. In fact, I’m on a pay-as-you-go plan with Virgin Mobile since my cellphone is basically for emergency situations. I still don’t like cellphones all that much.
  • I don’t want to pay the exorbitant monthly fees that carriers in Canada charge to use the iPhone. Basically, the minimum monthly cost is $60, but this does not include the “System Access Fee” or essentials such as Caller ID, and adding those brings the total to over $80/month without taxes

I don’t want to turn this into a huge iPhone vs. iPod Touch debate, so let’s just say I don’t have the cash for an iPhone subscription at present. Anyway, here’s a few pictures from the unboxing. Enjoy!

Continued

Getting Xdebug to work with Apache/XAMPP to debug PHP

xdebug-logo

I’ve written about Eclipse and how useful it can be, with its extensible plugin-based system. It’s so useful that I use it everyday for almost any language – Java, PHP, JavaScript to name a few. It’s even great for things like CSS and XHTML.

PHP is currently my favourite “hobby” language and has been for some time. While I like PHP, one of the things that hasn’t been straightforward with it is setting up a proper debug session, where you can step through code. This contrasts heavily with a language like Java, which has always had strong developer tools. This has resulted in a mass of third-party tools aimed at facilitating PHP debugging. A while ago, a reader emailed me asking about this very topic, so I decided to put together how-to detailing my experience with the topic and how I went about learning it.

Continued

Getting Google Chrome to work with Hotmail

chrome

Like many, I’ve been using Chrome occasionally ever since it came out back in September.
I never really had any problems with any sites, and was impressed with how fast it left the “Beta” stage, considering Google’s affinity for the term. Continued

How I bought a car to complete my first marathon

2008 PEC Marathon Medal

The following is a somewhat long-winded first hand account of my first marathon, which I completed earlier this year, but took some time to write about.

It was a usual Friday afternoon, the time of the week that I usually canโ€™t wait for. However, this Friday I was feeling a little bloated and slow having come back from a lunch buffet where Iโ€™d overindulged.

To work off this lethargic feeling, I decided to visit the gym after work โ€“ something that I only do infrequently on Fridays, being keen on getting home as early as possible in anticipation of the weekend. Iโ€™m fortunate enough to have a workplace that has a gym onsite โ€“ but this also means any excuses Iโ€™d have for not going would only be made weaker.

Dragging myself to the gym, I started into my routine. In between reps and trying to catch my breath, I starting making some small talk with Brian, one of my coworkers, who was on the bench beside me.

โ€œI donโ€™t normally see you in here this time of day,โ€ I said.

โ€œI usually come in at lunch,โ€ he responded. โ€œBut a lunch meeting ran overtime today.โ€

โ€œAre you working out to prepare for hockey?โ€ I asked, referring to the recreational league that was starting in September.

โ€œNo,โ€ he replied, slowly. โ€œIโ€™m in here crossing-training for the marathon.โ€

That last word, marathon, set off a trigger in my mind.

Continued

View all entries by month or by category