ticktock – my first Facebook app

Just added the finishing touches to my Facebook application. Its called ticktock and basically displays a clock on your Facebook page.

But its no ordinary clock; it shows the local time AND Internet time. The Internet time is measured in units called tocks which are the same regardless of where in the world you are. So for instance 234tocks in Auckland is the same time as 234tocks in London.

Great if you need to set up an IM chat or meeting with someone on the other side of the world.

If you have a Facebook account then check out the ticktock application

Using JSON for Java and PHP interop

I’ve been playing with Markov chains for doing ‘random’ text generation. Had an interesting problem in that I needed the GUI code to run on a PHP based web server but I didn’t want to have the processing of the source files occur every time. I also had a nice Java program doing all the source text processing for me and I didn’t really feel like porting it over to PHP either.

What I needed was to store the data generated by the Java app in a format that I could use in my PHP pages.

I initially was going to serialise the data into a binary file or into XML but to be honest this seemed like just to much work and I’m (like most coders) a bit lazy.

Enter JSON, the JavaScript Object Notation. This is a format like XML that supports the light-weight encoding of data, however it also supports types and in fact is executable in Javascript to convert a JSON string directly into Javascript objects and arrays. This makes it very useful for things like AJAX applications.

JSON has wide platform support so both PHP and Java can encode objects and arrays into JSON and visa-versa. Even better to do so is very easy which appeals to my lazy coder nature :)

For instance to write out a popluated Java HashMap to file using JSON-lib is as simple as:

Map map = new HashMap();<br /> map.put( "name", "json" );<br /> map.put( "bool", Boolean.TRUE );<br /> map.put( "int", new Integer(1) );<br /> map.put( "arr", new String[]{"a","b"} );<br /> JSONObject jsonObject = JSONObject.fromObject( map );<br /> System.out.println( jsonObject );<br /> // prints: {"arr":["a","b"],"int":1,"name":"json","bool":true}

On the PHP side of things, there is a built in function (under 5.2.0) called _phpdecode() which is used as follows:

<?php<br /> $jsonString = '{"arr":["a","b"],"int":1,"name":"json","bool":true}';<br /> $decoded=json_decode($jsonString,true);<br /> var_dump($decoded);<br /> // prints: array(4) { ["arr"]=> array(2) { [0]=> string(1) "a" [1]=> string(1) "b" } ["int"]=> int(1) ["name"]=> string(4) "json" ["bool"]=> bool(true) }<br /> ?>

Nice and neat.

So my final solution is:

  • Java application processes the source text files and builds up the appropriate maps and data for the Markov chains
  • Using JSON-lib it generates strings for the data and saves them to files
  • My PHP page loads the files, does a json_decode() to get the Markov chain data loaded
  • The PHP then generates the text using the loaded Markov chain data

Just too easy :)

GMail and Google Maps on your phone !

Google’s mobile maps and GMail applicationsGoogle have a couple of J2ME applications for your phone that are really cool.

The first gives you access to your GMail account. It’s really easy to use. Just browse to http://www.gmail.com/app with your phone to download it.

The second gives you access to Google Maps. The travel directions are great (although it can be a little messy to type in addresses on your phone). In certain parts of the world it will even show the heavy traffic reports overlaid on the maps ! Point your phone at http://www.google.com/gmm to download it.

Remember to make sure you have some kind of data plan for your phone otherwise it will be very expensive to use these applications.

Workrave

Being plagued with an achy wrist of late. I suspect the cause is a new desk at work so my screen was not at the right height making me sit funny. So apart from resting my hand over the xmas break and getting my desk set up correctly I have also installed Workrave.

This application pops up frequent reminders to take breaks and pauses. It works very well and I reckon that everyone should have an application like this running on their computers. Maybe it should even be part of the standard operating system.

WinMorph and Wink

WinMorph is a great morphing application that supports images and video. It’s easy to use and it’s free !

Wink also by Debugmode is a great application for creating presentations and tutorials. It does screen captures and creates a Flash animation. You can add call outs to display instructions plus customise a a range of things.