Binary Search for Javascript Arrays
If you need to search through a large array, or you search arrays frequently in your Javascript code, or if you do both, chances are a binary search will give you better performance than a linear search (read: for loop). One caveat, however, is that binary search algorithms only work on sorted arrays. Here is a binary search function I sometimes use in my code:
Auto-Linking URLs with PHP
A week or so ago I was working on a bug in the auto-linking code for Laconica, the software that powers Indenti.ca. Squashing that particular bug wasn’t too hard, but I wanted to take the functionality a step further (closer to the calibre of Gmail) and it turns out, writing robust auto-linking code is more difficult than it initially seems. So I played with it a little at a time here and there, testing as many edge cases as I could think of. The result is a function that’s more robust than most URL auto-linking code I’ve come across.
I still need to add support of internationalized TLDs and HTML. So, although it only works with plain text for now, I think it’s off to a good start. Check out the demo or download the source.
LongURL—Restoring Order to the Universe
It’s been two weeks since I conceptualized LongURL, and a productive two weeks at that! Last Monday I officially launched the service (which provides a handy REST API) with support for a dozen or so shortening services like TinyURL.com. Once I stepped away from the problem for a little while I realized there was a better way to go about solving it. Thankfully the way I designed the service didn’t make it very difficult to swap out that bit of business logic, so this week I rolled-out an update that adds support for all shortening services.
After getting feedback from some helpful beta testers (thanks Marjolein and Børge!) and making a few tweaks I was happy yesterday to release the LongURL Mobile Expander Greasemokey script and Firefox extension which use the LongURL API to expand shortened URLs on any web page. I haven’t had much feedback from others yet, but for me personally, the extension tremendously improves my user experience. Sorry guys, no more rickrolling me!
Making Campfire Work for Me (and More Like IRC)
One of the companies I work with has decided to use the 37signals line of products for internal project management and communication (which I think is great BTW). This means that I sit in a Campfire chat room for the working hours of my day, along with a handful of other developers. I started to run into a problem, though, when I didn’t need to be talking with others. It is difficult to tell when people are trying to talk to me. Campfire has, by default, two methods of notifying you of new messages: an unread messages counter (dock icon or browser tab), and optional sound ‘dings’. When I’m trying to work on something though that doesn’t involve chatting with others, all the while the chat room still active with other developers, it’s really distracting to hear constant ‘dings’ or have to repeatedly check new messages to see if they pertain to me.
The situation for me is similar to lurking on IRC channels. But IRC has been around much longer than Campfire, and IRC client developers are familiar with the problem. Thus, many IRC clients allow you to specify keywords, that, when present in other users messages trigger some form of notification, like a sound or Growl message. Well, this clearly is the feature I needed to solve my Campfire problem.
Negative Word Matching with Regular Expressions
Today on the #codeigniter IRC channel someone asked about how to match a string that didn’t start with a specific word using a regex. I quickly threw out that, off the top of my head, /^(word){0}/ should work. Well, surprisingly, it didn’t. Turns out negatively matching words with regular expressions is a little more difficult.
After a little research I came up with a working solution: /^(?!word).*/
This post by Jeff Atwood helped: Excluding matches with Regular Expressions


