Tweete : a New Mobile Twitter Client

After months of complaining about the lack of features on the official mobile twitter client, and the download overhead of slandr, I decided to write my own mobile twitter client. One that focuses on most needed functionality without the huge download overhead. I call it Tweete.

I’m still working on Tweete, but at the moment I have a beta release running that you are welcome to try out which you can find here: m.tweete.net. I’ve tried to keep the pages fairly light, at the moment each page is around 5k, which is roughly the same as the official mobile twitter client, but Tweete has extra features. Slandr on the other hand is around 25k per page load (last time I checked). My mobile handset browser (WM6 IE) doesn’t support gzipping content, so I’ve tried to make pages as light as possible without gzipping.

To use Tweete, simply login with your twitter login details and away you go; no need to create an account or maintain another password.

Currently the following features are implemented in Tweete:

  • Send updates
  • User & friends timeline (with pagination)
  • View replies
  • View direct messages & send direct messages
  • Pagination for direct messages & replies
  • Mirrored Twitter URL structure
  • User profiles
  • Follow & Unfollow users
  • API Limit handling

The following features are planned:

  • Delete tweets & direct messages

And the following may or may not be implemented:

  • Customize css colours from twitter account settings

If anyone has any suggestions, feel free to contact me with them (or leave a ticket at the Tweete Trac page) and I’ll see what I can do :)

For those of you who are interested in implementation details; I used the Kohana PHP Framework. Kohana is designed from ground up as a lightweight secure php framework for rapid application development. I have had a look at a number of frameworks for php, and in my opinion, is the most easy and logical to use.

natsort() pain in PHP

While writing some software for work which works out distances between geographic locations, I discovered some nastiness with the natsort() function in php.

This function implements a sort algorithm that orders alphanumeric strings in the way a human being would while maintaining key/value associations. This is described as a “natural ordering”.

So, given this definition of natsort, I’ll now outline a working example and then an example of the problem I encountered.
Lets say we have a list of values in an array that need to be sorted descending whilst maintaining key/value pairs. E.g:

$a = array(4 => 9.1, 3 => 4.2, 10 => 4.5);
natsort($a);

As you would expect, the resulting array looks a little something like this.

print_r($a);
Array
(
[3] => 4.2
[10] => 4.5
[4] => 9.1
)

But what happens when the values in the array we are trying to sort are a little more complex:

$a = array(4 => 9.11705244995,3 => 4.23956628237,10 => 4.5361796771);
natsort($a);

The resulting array isn’t what we expect though.

print_r($a);
Array
(
[10] => 4.5361796771
[3] => 4.23956628237
[4] => 9.11705244995
)

As you can see, the sort order is incorrect. As you have probably picked up, the 4.5xxx number’s decimal places are 1 less than the other two numbers. As soon as you change 4.5361796771 to 4.53617967711 and run natsort() over it, it returns the correct order.

Conclusion: Don’t use natsort() when sorting floats of different precision as it will return incorrect values! Use something like asort() if you want to maintain key/value pairs, or sort() if you don’t care about the key ordering.