Windows-izing the Home and End keys in OS X

It’s the small things that drive me batty.

After switching from Windows to OS X when purchasing a Macbook Pro back in October, I’ve had to learn my way around the little differences between the two operating systems. There hasn’t been much that caused me too much trouble. Most solutions were a google away and problem solved.

The one that’s given me the most grief (and was most noticeable once docking the Macbook to a full, non-laptop keyboard) is the difference in the behavior of Home and End keys. Being a touch-typist who sits at a computer for more hours than should be allowed, I found myself blindly hitting Home and End only to find the cursor do the complete wrong thing. This was a tough habit to break.

First I found this blog post with steps to fix the basic behavior within OS X. It even worked!

But, I find myself spending a lot of time in a web browser. Specifically Firefox (because I’ve grown so damned dependent on the del.icio.us integration). Sadly Firefox isn’t fixed by the general solution.

Thankfully, the same genius behind the link above also has a Firefox Add-on that solves the problem!

Without further ado, go get Keyfixer

Iterating over a PriorityQueue is NOT ordered

I stumbled across a little Java gotcha recently when trying to order a collection of Java objects.  For some reason I decided to use a PriorityQueue because I wanted to maintain duplicates, so TreeSet and TreeMap were ruled out.

Unfortunately, the PriorityQueue is only ordered when remove/peek/poll-ing objects from the collection. NOT when iterating over the collection. This fun fact is clearly identified in the PriorityQueue JavaDocs:

The Iterator provided in method iterator() is not guaranteed to traverse the elements of the priority queue in any particular order.

Unfortunately the JavaDocs aren’t very obvious even if you do happen to specifically access the iterator (and really isn’t obvious from a for-loop perspective).

While it makes perfect sense in retrospect (due to the internals of the underlying heap), it was only by chance that I caught my mistake and made the fix:

final PriorityQueue<MyObject> ordered = ...;
while (ordered.size() > 0) {
   final MyObject next = ordered.remove();
   ...
}