Archive for the ‘IT Stuff’ Category

ABC’s foray into Video podcasts

Saturday, August 19th, 2006

I’m a big fan of The Chaser teams’ productions on ABC (the Australian national broadcaster), such as CNNN (sic), The Election Chaser, and most recently The Chaser’s War on Everything. For unfathomable reasons, the show gets scheduled at around 9:45pm on a Friday night, so I was pretty happy to hear that it was available via Video Podcast.

While being a big fan of standard, audio-only podcasts, I hadn’t played with Video Podcasts before. So, I updated my iTunes to the latest version, navigated to the relevant feed and clicked “subscribe”. My PC started downloading the latest episode (around 75 Mb) and shortly after, I was watching it. Better still, my PC will automatically keep an eye on the feed, and pull down the new episodes as they occur. If only I had a video iPod…ahh well, watching it on the PC monitor was fine :)

My initial reaction to all this (apart from “Yippee!”) was surprise – its not like a broadcaster to give away this stuff for free, right? Well, on reflection it makes sense. As the national broadcaster, ABC isn’t out to make cash from its products – its out to provide its material to the Australian public. Traditionally thats been done over the airwaves, but why not over the Internet?

I hope the ABC has worked out a process of integrating these download figures into their ratings numbers. And I’d be very curious to see the figures of how many people are downloading the podcast of this show – perhaps it wont be too long before this will be the new standard of broadcasting :)

Java Sudoku Solver in 6 lines

Monday, July 24th, 2006

After playing around with writing Sudoku Solvers in the past, I was interested to see this page which details a number of tiny sudoku solvers in a variety of languages such as Perl, Ruby, etc.

They have a few basic rules – no line over 80 bytes, etc, etc. And the examples take their input as a string of 81 digits, which represents the 9 rows of 9 digits, with “0″ being a blank square.

As I apparently have way too much time on my hands ;) , I got up the motivation to convert one of these examples into Java. The results?

  • The end program is around twice as many lines as the Perl original, and
  • Yup – you can make Java programs as unreadable as anything else out there! ;)

There may well be shorter possibilities out there – I didn’t put in a great deal of effort past converting the Perl original. But, for the record:

import java.util.*;public class S{static char[] A;static void R(){int i,j;for(i=
0;i<81;i++){if(A[i]!='0')continue;HashMap h=new HashMap();for(j=0;j<81;j++){h.
put(j/9==i/9||j%9==i%9||(j/27==i/27)&&((j%9/3)==(i%9/3))?""+A[j]:"0","1");}for(j
=1;j<=9;j++){if(h.get(""+j)==null){A[i]=(char)('0'+j);R();}}A[i]='0';return;}for
(i=0;i<81;i++){System.out.print(A[i]);}System.out.println();System.exit(0);}
public static void main(String[] a){A=a[0].toCharArray();R();}}

Assuming you have an appropriate classpath, you can run it with a line like:

java S 006070800000000000078601520030405010400000002090302060052103690000000000003020100

This code was converted from the excellent Perl example at:

http://www.ecclestoad.co.uk/blog/2005/06/02/sudoku_solver_in_three_lines_explained.html

Nice article on game console power consumption

Monday, June 19th, 2006

Following on from my posting on my new centameter power usage monitor, I came across this interesting article at www.dxgaming.com.

They did some testing of the power consumption of common consoles and made the discovery that the latest consoles use between 5 and 10 times more power in standby than their predecessors – so, an XBox uses 0.4W in standby, but the new XBox360 uses 2W. The Playstation and Playstation 2 is a near identical story. They have an interesting discussion about why these figures may make you switch off your Playstation 2 when not in use, but not your XBox360 – worth the read.

Recent outage resolved

Monday, June 12th, 2006

Apologies for the recent outage folks. I’ve been travelling in Europe this last month, and my ADSL modem decided to get confused 1 week into the trip. Proof that Murphy’s Law is alive and well!

On my return, a quick off/on of the ADSL modem, and everything is back online.

So, we now return you to your irregularly scheduled blog… :)

I’ve joined the Google Analytics fan club

Wednesday, April 5th, 2006

After having my name on the waiting list for Google Analytics for a good 3 or 4 months, I got an email this morning inviting me to sign up. And 15 minutes later I was up and running!

Plenty has been written about Google Analytics, much of it in a breathless “Wow!” sort of tone. And, I’m afraid I’m yet another one! The thing that gets me is the sheer depth of information. I’ve just spent the last 15 minutes discovering that (in the first few hours of stats collection) that:

  • Most of my audience has a screen resolution of 1280×1024
  • About a third of my audience is using dialup
  • All of my audience has Java enabled (well, this is a rather small sample at this stage ;) )

In addition, of course, there’s the more “standard” stuff – where in the world your clicks are coming from (although this is down to the State level, which is rare for us Aussies – plenty of tools give you US state info, but not Australian), which pages are most popular, etc.

Up till this point, I’ve been using AWStats in a static configuration – stats are generated in the form of static pages once per day. A great tool that gives me a lot of good summary information, but it just can’t touch the depth of Google Analytics stuff. That said, I’ll still be keeping it. AWStats runs on my PC, so I can always access it, even if I lose Net access. And, being static pages, its blindingly fast.

(Google Analytics is no slouch, by-the-by. I think we’ve all come to expect good performance from Google, be it search, mail, whatever, so this is probably no surprise. But there are noticeable pauses from time to time – only 2-3 seconds or so – as you navigate around)

Anyway, it looks like I can say goodbye to another 30 minutes of my life each day. So many graphs, so little time! :)

Javadoc-driven development

Friday, March 17th, 2006

Its the new development methodology thats taking the developer-world by storm…. ;)

Well, not really.

Just a cute phrase that occurred to me today when chatting to a colleague. We’d just spent 15 minutes discussing the desired behaviour of a system I was working on. Usual stuff – at first blush it seems straightforward, but plenty of edge cases, historical behaviour requirements, and other nastiness.

So we got it figured out, and its 11:45. Lunch booked at 12:00. No way am I even getting 10% of the code done in that time. But its just enough time to do the Javadoc.

So, 15 minutes later, my code has the 2 method signatures I need and around 40 lines of Javadoc describing the code’s behaviour, exceptions, and assertions. And after lunch, I was able to get straight into coding, all details of my discussion safely preserved.

And as an added bonus, when it comes time to rework it, I (or the next guy) will have some great doco to get started.

Not rocket science. Certainly not worthy of its own buzzword-esque title (although it does roll off the tongue :) ). And probably something everybody should be doing anyway as part of their actual methodology. But its a neat little anecdote worth telling!

How did I miss this? java.util.Collections

Monday, March 13th, 2006

Well, they say you learn something new everyday. And given the size of the Java API, thats not too hard to believe ;)

After doing serious Java programming for at a least a few years, and having dabbled for a few years more (all the way back to the 1.0 days!), I’m pretty happy with my breadth of Java knowledge. Until a co-worker today mentioned using Collections.shuffle() to randomize a list.

“Pffffft”, says I, “Surely you jest”, says I. “No such thing.”

Well, there is. java.util.Collections (not Collection, note – theres an “s” on the end!). A nice, chunky class, full of juicy, static methods just waiting to save you from having to re-invent the wheel when it comes to operating on Collections. There’s the obvious stuff – shuffle() and sort() to randomize and sort, for instance. And small, but useful stuff – min() and max(), swap(). And some real useful stuff, like synchronizedList() (which returns a thread safe version of your list).

Many’s the time I’ve done my own “max()” routine. Each time, I trawled through the Collection interface looking for one and was mildly surprised it didn’t exist. And I never thought to look any further afield. I’m guessing that there may be one or two Java guys out there who are in the same boat (How many library classes are there now in Java?). Seeing as my co-worker doesn’t have his own blog…yet (come on H! Get your act together! ;) ), I’m doing this posting for the other people like me!

Of course, I’ve always got the excuse for my ignorance that its a relatively recent addition. I mean, its only been around since Java 1.2….. *grin*

Will Wright’s “Spore”

Thursday, March 2nd, 2006

Came across this link on digg for a 30 minute video demonstration of the upcoming game “Spore”.

Wow!

I gather the game is the brainchild of Will Wright (of “The Sims” fame). The demo blew me away – it is sooooo open-ended. I won’t try to do it justice here – for one thing the scope seems huge, and for another, this was just a demo, so the finished product could be wildly different. In short though, you guide a species’ evolution to a certain stage, then switch to a kind of SimCity/RTS type game to build up their civilisation, then switch to a kind of “God” mode where you can fly to other planets and do it all again.

Reading over that last paragraph, it doesn’t really do justice to what the demo showed. For instance, you seem to have complete flexibility in designing your creatures – the computer figures out how they move/eat/etc based on their body architecture. And the creations of different players are made available (asynchronously) to your own universe – while exploring the universe, you might encounter a planet that has been copied from some other player.

I really recommend setting aside the time to watch the video. Its been over 2 years since I bought a computer game, but I can’t wait for this thing to be released.!

(btw – there’s a good article on the Wikipedia on “Spore” which goes into a little more detail, for those that are interested)

Being too secure with a CGI script

Monday, February 27th, 2006

Oooops. I mean, it seemed like such a good idea, right?

While working on the new Asman IT Consulting website a couple of months ago, I wrote a new “Contact Us” CGI script. I often work in the IT Security space, so I always have the security angle high on my list of priorities. So, I did the usual things:

  • I made sure that it wasn’t too flexible. Case in point – While chasing down a spam problem for a client, I discovered they had used a well known “Contact Us” script that was widely available that let you set the “to” address, such as the website administrator, as a hidden field. It worked well, until the spammers realised they could override that in their POSTs and use your Contact Us page as a spam relay…!
  • I sanity checked all fields to make sure only legal characters were present. Not, by the way, the common mistake of checking for illegal characters. Seems so tempting, as there are far fewer illegal characters to check for….. right up until you discover that you overlooked a dangerous character!
  • I checked that the script was only accessed from my “search” web page. Anything else would suggest some automated tool randomly accessing it directly
  • And a host of other checks and practices for things like rate of sending, data size, logging improper use, etc, etc

So far, so good. A few tests showed things working fine. And 2 months later the number of malicious hacking attempts made through it numbered exactly 0.

Exactly as many legitimate “contact us” messages I’ve received, as it happens. ;)

A look through the logs showed the problem. And it was all because of that second-last point.

Turns out I’ve had a few people try to send me messages this month. But a number of the more tech-savvy users (and I’m flattered they’re among those accessing my site!) turn off the “Referrer” facility in their browsers. The “Referrer” field normally allows a site to see where visitors have come from. With this disabled, my “Contact Us” facility refused to process their message as it looked like they had bypassed the appropriate web page within the Asman IT Consulting site.

All fixed now, and my apologies to those who were rejected up till now! But an interesting example of the “Security” vs “Ease of Use” balancing act that comes up time and time again. There was nothing intrinsically wrong with my initial approach. And there is nothing intrinsically wrong with people choosing to configure their browsers in that fashion. Everyone needs to pick a security stance that suits their particular situation.

And, based on their experiences and changing needs, amend that stance as required.

Java coders have it easy – crashing constructors

Friday, February 10th, 2006

I came across this entry while scanning Java Blogs yesterday about how to handle exceptions within a constructor. The essence of the article is how do you handle the situation where you couldn’t instantiate your object?

So, if the user passes invalid parameters, do you throw an exception? And, slightly more subtly, if your constructor encounters an exception during object setup, how does it handle this?

Interesting article and well worth the read.

But it struck a bit of a chord with me – I recently bought a Nokia N70 phone, and have been cruising the net looking at how you can code for these things. The N70 is a Symbian phone, and while it has J2ME support, the hardcore stuff seems to be done in C++. Now, C++ is an … interesting language, but is not really known for its in-built protection against memory leaks, and when you’re running a program on a device with limited memory, where your app may well run for the order of days or months this suddenly becomes a big deal.

OK, so you just code, really, really carefully. ;)

Well, turns out that constructors are a special case in terms of memory leaks. Symbian doesn’t use standard C++ exceptions, but it does have an analagous concept called “leaving” grafted on. And not being a C++ guru, I couldn’t tell you what difference there is between normal C++ exceptions and the Symbian variety. In any case, the issue when writing Symbian programs appears to be this:

  1. Constructor called
  2. Constructor initialises an instance variable that points to some new object
  3. On the next line, the constructor encounters an error and leaves

So, we now have allocated memory for some new object (step 2 above), but the object that owns it no longer exists – it crashed during construction. And because the object never fully formed, the destructor wasn’t run on it and so couldn’t free up the memory. Ladies and gentlemen, we have memory leak…. :(

Turns out that Symbian programs have an accepted idiom on how to handle this stuff. Objects that can suffer this way have a static construction method (like the whole getInstance() idiom you see in Java). This static constructor creates the object using a constructor that only performs trivial operations that won’t crash, then once the object exists, calls an instance method on the new object that performs 2nd-phase construction. If things turn to jelly, there is at least a concrete object in existence, so the destructor will be called as normal.

Pretty neat. And pretty eye-opening as to the kind of issues you can be exposed to without garbage collection.

(Which is not to say that Java doesn’t have its own issues with memory leaks, but thats a whole other blog post… :) )