Blog

The Game of Life and emergence

I have had a side interest in emergent behaviour ever since reading about various forms in nature, so when a co-worker sent me a link to Conway’s Game of Life, I was immediately intrigued.

Long story short, I just had to implement it (albeit a simple version) in JavaScript. The result is available on my website and I suggest you give it a try; a good pattern to start out with is the F-pentomino.

The reason I find emergence so interesting is that it provides a possible framework or explanation for the complexity and order seen in our universe, based on a fairly simple or rudimentary set of rules.

Continued

Shuffle sort and other fallacies of randomization

Quick, how do you write code that shuffles a collection of objects? In the real world, it’s fairly easy to see how a deck of cards is shuffled – but how would you do that in code? Obviously, you would have to use some sort of random number generator, but beyond that it’s not straightforward. Furthermore, how do you ensure that the shuffling is fair; that is, all permutations appear with equal probability?

The astute among you will know that one way is by implementing the Fisher-Yates shuffle algorithm. But, let’s investigate what happens when other, seemingly adequate solutions, are used instead.

Continued

The Flyweight Pattern: (Mis|ab)used at times.

In my brief career in software development thus far, I have seen a lot of “WTF” code, that is, code that deserves to be posted to The Daily WTF. Some of this code was admittedly developed by myself and upon reviewing it a few months after it was written, I secretly wondered what I’d been thinking.

This isn’t going to be an indictment of bad programming; in fact, I think it’s good if you can look back at your old code and see where it could be improved. Such a process suggests that you are continually self-improving, a skill crucial in software development. Besides, all of us have made a mistake or two at times when we were stressed, tired or just plain not thinking straight.

However, there’s one mistake that I’ve seen that I think warrants bringing to light, and that is the misuse of the Flyweight pattern.

Continued

Goodbye, old friend…

I’ve had the same pair of prescription glasses since about 2004, having changed the lens more than once. I just got so used to them that whenever the opportunity arose to replace them, I couldn’t find a pair that felt or looked right. So, I just continued with the same old dependable pair.

They’ve fallen off of my face more than once, have tumbled many times to the hardwood floor from my nightstand while I fumbled for them in the dark, been lost in my bed covers and rolled onto during numerous occasions, and of course I’ve fallen asleep with them on more times than I can remember. Despite all of this, they not only held together, but retained much of the original lustre and remain in excellent condition.

Only one of the earpieces is starting to look worn, the nose pads are looking a little old and one of the lens screws had to be replaced when it fell out and got lost, but other than that, they’re as good as new. This was the first “thin” pair of glasses I had ever worn and I initially had some reservations about durability, so I’m more than pleased with how well they’ve held up. (I think the frames are made up of some titanium, but I can’t remember)

But this past weekend, I decided it was time to finally replace them.

We’ve had a good run, old friend, but I’m afraid it’s time to part ways.

Continued

Boston reflection and updates

It’s been two months since the 2011 Boston Marathon, which was my first attempt at this historic race. As some of you may know, it had been one of the focal points of my life for the past several months, ever since I qualified by 13 seconds back in September of 2010.

I took a new approach to training and really dedicated myself to it. There were many mid-week 4 AM mornings, followed by 1.5-2 hour runs in the dark, snow/rain and wind. I arrived at the starting line being as prepared for any race as I’d ever been.

Continued

Excess packaging

I recently ordered some extra Sanyo eneloop batteries when they were on sale at Dell. They’re great rechargeables, but I don’t know why most packages always come with a charger – I now have three of them from previous purchases.

However, when I received the package from Dell, I was surprised at the size. It came in a huge 18″x13″ bubble envelope: Continued

Java, Weak References and WeakHashMap

Most any Java Developer will be familiar with the concepts of references, as in pass-by-reference vs. pass-by-value. (Pointers, now that’s another thing…)

When calling methods, primitive data types are passed by value, while objects and arrays are passed by reference. This means when you call a method with an object as a parameter, you are merely providing that method a way to access/manipulate the same object via a reference; no copy is made. Contrast that with primitives: When calling a method that requires them, a copy of that value is put on the call stack before invoking the method.

In that way, references are somewhat like pointers, though they obviously cannot be manipulated by pointer arithmetic. But what about weak references? What are they, and how do they contrast with strong references?

Continued

Folding changesets with the Mercurial Queues extension

Mercurial is my distributed revision control system of choice, a trait I picked up at my previous job. I haven’t had the opportunity to deal with Git for any period of time, so I can’t comment on the various “Why X is better than Yarguments out there.

Most of you using Mercurial/Hg (or revision control in general) will be familiar with the concept of merging, where the changes in a source branch are merged into a target branch, creating a new revision or changeset on the target branch. But what about the times when you would like to combine two or more changesets/revisions into a single one that has the combined/overall changes of all of them? In that case, the Mercurial Queues extension provides for the concept of folding, which accomplishes just that.

Continued

What I’ve been up to

I’ve had a serious lapse in updating this blog with useful information, and for that I apologize. I would have liked to continue to provide helpful guides and other tutorials, but I continually found excuses to be lazy. Writing these guides is as helpful for readers as it is for me, so it’s something that I need to engage in more often if I am to continue with personal development.

With that in mind, I thought it’d be useful to provide an update on what I’ve been up to for the past few months, to keep things in perspective.

Continued

Qualified for the Boston Marathon!

On September 26th, I ran the Toronto Waterfront Marathon, thus completing the GTA marathon three-pack within one year. (GoodLife Toronto Marathon, Mississauga Marathon and the Toronto Waterfront Marathon are the three major GTA marathons) More significantly however, I qualified for Boston, getting my ticket to the event for 2011! My time of 3:10:46 qualified me by 13 seconds, and it was an epic battle for every one of those seconds. For these reasons, I felt this marathon experience to be the best of the five marathons I’ve run so far.

Continued

View all entries by month or by category