Remote control of XBMC, but not too much

Yesterday and today I have scripted a small web interface for remote control of XBMC using its HTTP API. (BTW, That API could really use a redesign!)

It’s actually just a page showing a screen shot and the name of the file that is currently playing, together with some commands to remote control XBMC.

Available commands are pause/resume, stop, play another file, and shutdown.

I also implemented support for showing notifications on the XBMC screen, which gave me an idea:

The Google Calendar can e-mail reminders for appointments. If XBMC is running, the reminder could be shown as a notification on the XBMC monitor.

I was just about to start implementing this calendar-reminder-in-XBMC when I reminded myself that there are many other small and big projects that would be more valuable for me. But instead of throwing this idea right down the trashcan I decided to blog about it first. Done!

Now I’ll spend some valuable time with my son!

Today’s thoughts about programming languages

Maybe some of you have heard me ranting about this already?

  • I’m not productive enough in C++ and I feel too limited by Java
  • A large chunk of Java frameworks seem to serve no other purpose than to workaround limitations in Java
  • I believe (and hope!) that Java will cease to be the default language in the non-Microsoft world, and that other JVM-based languages such as Scala, Groovy and JRuby will become more important
  • How can I convince a client to allow Scala, Groovy or JRuby in a project?
  • I should really get some C# experience!
  • It seems like I almost always resolve to PHP when I need to get something done quickly… which reminds me of an upcoming blog post about a recent fight with SoapServer and SimpleXML to implement WSSE UsernameToken authentication.

TaskFreak hacking part 2: date format

My TaskFreak hacking goes on. In Sweden we often use ISO 8601 format for dates (year-month-day), but TaskFreak does not offer this out of the box.

Most date formatting comes from the DATE FORMATS section in include/config.php but even after changing these date formats I still don’t get all dates displayed as I would like.

For example, the text box for the date when editing an item is using the TZN_DATE_FRM constant defined in include/classes/tzn_generic.php. There’s a pretty naïve comment in the source code, saying that there is a “US format” for dates and a “rest of the world” format. Fortunately (for the US), the rest of the world is not united in opposition.

To get the date format I wanted I changed the constant definition like this:


Hire me for my mind!

Ward Cunningham tweeted a link to an ad for an Agile Ruby Developer at AboutUs, Inc. Out of curiosity I took a look and it sounds like a fantastic opportunity for someone!

What I liked most about the job ad was the last part:

We’re hiring you for your mind. Please showcase it by answering some of the following questions in your cover letter:

  • What is a recent programming insight you discovered and what was intriguing about it?
  • Why do you want to work with us? (be specific!)
  • What Open Source communities/projects are you a part of and why do you like them?
  • Tell us about a time you brought initiative to your team and made a positive change.
  • What modern programmer do you admire and why?
  • How do you learn and keep up with the field of computing?

These questions really appeal to me!

Good at programming, bad at communicating

I can’t remember how I originally found the link (was it in someone’s tweet?) but I managed to find it again in order to share it here. The message may seem silly in retrospect, but I think it was enlightening. The article is called Sometimes, The Better You Program, The Worse You Communicate. The author writes that:

[…] good programming practices are directly opposed to good communication practices.

In bullet form:

  1. D.R.Y. Does Not Apply.
  2. Humans don’t mean what they say.
  3. Compilers don’t need to see an example.
  4. Programs love definitions; Humans get flummoxed.

From now on I will try to repeat myself more often, act on what people mean and not what they say, give more examples and avoid definitions. Except when programming!

Permute an array in PHP

I wrote this function recently when I could not find it in the PHP function list. Please provide any optimizations you discover!

function permute($array)
  $results = array();

  if (count($array) == 1)
    $results[] = $array;
    for ($i = 0; $i < count($array); $i++)
      $first = array_shift($array);
      $subresults = permute($array);
      array_push($array, $first);
      foreach ($subresults as $subresult)
        $results[] = array_merge(array($first), $subresult);
  return $results;

assert(permute(array()) == array());
assert(permute(array(1)) == array(array(1)));
assert(permute(array(1,2)) == array(array(1,2),array(2,1)) ||
       permute(array(1,2)) == array(array(2,1),array(1,2)));
assert(count(permute(array(1,2,3)) == 6));
assert(count(permute(array(1,2,3,4)) == 24));

Amount of type checks in Java

Martin Fowler writes about DynamicTypeCheck:

Recently some of our developers ran into the accusation that with a dynamic language like ruby you use so many dynamic type checks that you end up effectively writing your own type system. So they thought, since we’ve written a lot of real ruby code – how often do we make dynamic type checks?

We define a dynamic type check as the use of the methods is_a?, kind_of?, and instance_of?.

This made me think about the use of instanceof in Java. A pretty non-scientific investigation of an Open Source Java application (Vuze) showed:

Lines of code: 740257 (find . -name '*.java' | xargs cat |wc -l)

Number of instanceof: 1926 (find . -name '*.java' | xargs cat| grep -c ' instanceof ')

LOC/Number of instanceof: 384

So, there is actually more instanceof in this Java project than there are dynamic type checks in the anonymous Ruby projects used for the statistics presented by Martin Fowler. I certainly hope it wasn’t a Java developer that accused dynamic languages to use lots of dynamic type checks!