Ninja Me!

In the last couple of days, the internet world (and more specifically the Twitter world) has been all up-in-arms about the upcoming demise of the tr.im URL shortening service (later followed by the backpedaling of the news).

You probably already know the type of service. It takes a really, really, really long URL like http://example.com/catalog/category/widgets?productid=12345&view=7&commentid=8675309&areyoureally=readingthis&mode=88 and shortens it down to something easy to hand off to someone, like http://tr.im/12345. More importantly, it shortens it to something that takes up fewer characters of Twitter’s 140 limit. They are great, they are convenient, they are a dime-a-dozen, and there is not much way to monetize them — hence the demise of tr.im (before the reversed their decision.) Additionally, those sorts of services eat up bandwidth as bots and scrapers try to walk each and every URL. It’s a money-pit. Bit.ly manages to stay afloat, from what I understand, by doing data-mining on the links and selling the aggregate information to interested parties. Tinyurl, I have no idea — possibly advertising on the page to manually create links?

Something that shook out from all the news was a little aside from John Gruber of Daring Fireball: “And people ask me why I wrote my own URL shortener for DF’s Twitter account.” He wrote a URL shortener? It’s probably not that hard; just a table or two in SQL and some PHP to wrap it. I should do that. Just because. Actually, I should see if there are any good open-source projects that already do this. After examining a few projects, I rather liked yourls.

(As a sidebar, if I was searching for a good Open Source project a year or two ago, the first place I would have looked was SourceForge. These days, it’s Google Code. The former used to be the end-all-be-all of Open Source project hosting, but just no longer feels relevant to me any more. Google Code feels like the new hotness.)

A domain registration and about 10 minutes of customizing later, I arrived at a fully working nja.me. Another 30 minutes of stock art searching and more customization, I arrived at its present form. (Pro tip: refresh the page to see both design styles; yes, I have the 1996-era web design philosophy nailed!) And no, it’s not open to the public. A current shortcoming of yourls is that username and passwords are hard-coded in a PHP file. It’s great for a single-user or a small number of users, but does not really scale to maintaining large numbers of users. Perhaps I’ll modify that and submit a patch. I probably won’t, though.

I then proceeded to reverse-engineer the undocumented API so that I could automatically generate short URLs from a PHP function. The final step was to integrate everything with the WordPress twitter-tools extension I use for posting to Twitter. There is a module there that is hard-coded for bit.ly. I had to write a similar module for nja.me that uses my yourls API (and hacked it in there using a less elegant modification, but only had to change two lines).

The net result is that the Twitter notification no longer goes through bit.ly, but through nja.me. In fact, you may have followed that nja.me shortened URL to this very post from Twitter or Facebook.

Posted in: Code

One thought on “Ninja Me!”

Leave a Reply

Your email address will not be published. Required fields are marked *