Archive for the ‘Computer Things’ Category

Groovy stuff

Saturday, October 18th, 2008

So we’ve been busy at work for the last six weeks building a new version of our software that will run as a web application. I can’t link to anything about it yet because it’s not finished, but we’re already having fun trying out new stuff.

One of the biggest new things that we’re using is Grails. Grails is a neat web application framework that builds on the well-known enterprise Java stuff like Spring and Hibernate. It also uses the Groovy language.

Obviously jumping into something like this is a huge change. It has meant that we have had to redesign the whole system so that it fits the framework and we’ve had to change the way that some stuff works. It’s not often that you get the opportunity to completely start from scratch to build a new version of software.

One of the reasons why we were able to justify doing this is that Grails is such a brilliant environment for rapidly developing applications. For example, we have been able to pretty much build a system that functions and could be useful within just a few weeks. Obviously there’s still an awful lot of polish needed before it can be put in front of paying customers, but with Grails we’re able to get to that point much more quickly.

Also, from an engineering point of view, Grails is a lot neater to work with. It uses the model-view-controller paradigm from the off and pretty much forces you into sticking with it. This is good engineering practice, particularly as we are able to much more explicitly segregate application logic and view rendering and the domain model.

Another important advantage for us is that we can reuse a significant proportion of our existing code that was written in Java. Groovy code compiles to the same Java bytecode and runs in a normal Java virtual machine. This makes integration of Java and Groovy code a doddle.

Groovy has a huge pile of features that can improve developer productivity. For example, it introduces untyped variables, closures and lists/maps as explicit syntactic entities. It is also totally object oriented - all the primitive types are now used as their class equivalents. It looks a bit strange to be calling a method on a number, but this is now quite useful. Groovy makes querying the database a trivial activity - dynamic finder methods make it quick to write simple queries or you can use a Hibernate query language (HQL) builder to construct an HQL query if you want more complexity.

Untyped variables are useful in some areas. It makes it useful to just define a variable without caring what type it has. Of course, you can still have everything fully typed if you want - static type analysis at compile time really is a good thing and can’t be ignored completely!

We haven’t yet found uses for all the features of Groovy and Grails - stuff like metaprogramming looks like it may be useful but is not yet necessary for anything that we do. Obviously learning a new language and framework means that after a short time you have to go back and refactor some stuff now that you’ve worked out the proper way of doing things, but even so, we have seen a huge gain in productivity.

The downsides? Well, it clearly new to us, so we’ve had to learn it. And this is on-the-job learning too! Some of the documentation is out of date or not quite up to scratch - this is noticeable as Grails is only recently maturing as a quality framework and stuff has changed a lot up to around a year ago. Grails has stabilised nicely though and we are seeing a continual improvement in the quality and availability of the documentation.

One risk that we considered was that Grails and Groovy were relatively new technologies. It’s clearly a risk that stuff might change or that they go out of favour.

All in all, Grails and Groovy appeared at just the right time that we could get started with them. They have proved a godsend to us and may possibly be the enabling technology that allows our business to succeed.

XOR Defeated!

Tuesday, July 1st, 2008

XOR was a game released just over 20 years ago by Astral Software. I remember playing it on the Acorn Electron and not really getting very far! Suffice to say, I never completed it back then.

The game featured chickens, fish, bombs, teleports, masks and shields. The idea was to solve some rather fiendish puzzles to collect all the masks on each of 15 levels and then find the exit door.

I was quite pleased to discover that an XOR remake was created a few years ago by Ovine. This features the exact same15 levels as in the old 8-bit version.

Well, after a few weeks on-and-off, I have just managed to complete all 15 levels!

It is quite satisfying to have completed something that you started 20 years ago and has been nagging ever since!

There’s an interesting page about the history of XOR here.

Let me try Microsoft Visual Studio!

Wednesday, June 27th, 2007

OK, at work yesterday I thought I’d quickly try out Microsoft’s Visual Studio 2005. I may have to somehow interface an ActiveX component so that we can control it from Java (using JNI: urgh), so I thought I’d start by trialling Microsoft’s development tools. I tried Visual Studio some years ago but found it to be a bit of a behemoth even then.

First challenge was to get the 90-day trial downloaded. At 2.7GB, it’s quite a hefty download. Luckily at work this only took about 20 minutes - just enough time to pop to the shop to get a muffin and make a cup of tea! Then the trouble starts. The download is a DVD image - a .img file to be precise. At this point you are on your own. Microsoft do not give you any instructions on how to open the file beyond the fact that I needed to download it. So I have to install a CD/DVD image reader program to get this to work.

In the end I tried five or six different things - Daemon Tools, Alcohol 52%, ISOBlaster, etc.. None of them worked. Well, I say none, but ISOBlaster at least let me see inside the image and did even give me the option to extract stuff from it - until it then requests that you pay some money for the privilege.

I phoned Microsoft and told them that it’s a stupid way to distribute their software if I don’t have any way to actually install it. Microsoft recommends ISOBlaster - but this isn’t free!

Anyway, in the end I just ordered the DVD. This was a tiresome process and involved registering with Microsoft Live ID (which wasn’t working) and entering our business address about a dozen times. Unfortunately I got stuck at this screen:

Where's the button?!

Java Oddity

Thursday, February 2nd, 2006

Java has a set of reserved words that you can’t give to a variable name (such as int, class, static, etc.). But you can call a class the same name as the name of another class, like this:

String Integer = "42";

Which got me thinking - what happens if I try to access class or instance variables if the name of the class is slightly ambiguous?

I knocked up some code to find out:

public class Foo {
    public static final int BAZ = 5;
}

public class Bar {
    public static final int BAZ = 10;
}

public class Baz {
    public static void main (String[] args) {
        Foo Bar = new Foo();
        Bar Foo = new Bar();
        System.out.println(”Foo.BAZ = ” + Foo.BAZ);
        System.out.println(”Bar.BAZ = ” + Bar.BAZ);
    }
}

What gets printed out? Does it even compile?

Turns out it does compile. A clue as to what gets printed out is given by a warning from the compiler that the static fields should be accessed in a static way. This is the output:

Foo.BAZ = 10
Bar.BAZ = 5

So it prints out the instance variable rather than accessing Foo.BAZ and Bar.BAZ in a static context. In other words, Foo.BAZ returns Bar.BAZ and Bar.BAZ returns Foo.BAZ. Confusing, huh?

Athlon 64 and Lost Ticks with Linux 2.6

Monday, January 16th, 2006

I have recently installed a new Athlon 64 X2 3800+ processor in my computer and given it a brand new installation of Ubuntu. The kernel that I am using is 2.6.12-10-amd64-k8-smp.

The first thing I noticed when I checked /proc/cpuinfo was that the frequency was half what it should be:

jms@kermit:~$ cat /proc/cpuinfo
processor : 0
vendor_id : AuthenticAMD
cpu family : 15
model : 35
model name : AMD Athlon(tm) 64 X2 Dual Core Processor 3800+
stepping : 2
cpu MHz : 1021.570
cache size : 512 KB

This is fine! Linux magically works out how to use frequency scaling, so the processor will run at 1GHz, 1.8GHz or 2GHz depending on how much work it’s doing. This also means that the system draws less power and runs cooler (the processor idles at about 4°C above the ambient room temperature and maxes out at about 50°C).

The next thing I noticed was some weird timing problems. Whenever the processor was busy, I would notice the clock whirring away! Also, typing became a problem as I got lots of repeated characters when I pressed a key, even if I adjusted the autorepeat delay. /var/log/messages revealed the problem:

Jan 16 00:16:37 localhost kernel: [ 1177.917288] warning: many lost ticks.
Jan 16 00:16:37 localhost kernel: [ 1177.917291] Your time source seems to be instable or some driver is hogging interupts
Jan 16 00:16:37 localhost kernel: [ 1177.917311] rip 0×2aaab610f9f3

I believe this is something to do with the kernel expecting a certain type of timing with x86_64 processors such as the Athlon 64. Luckily, other people seemed to be having the same problem and it has been flagged as a bug in the kernel (and even been patched), so later kernel releases might have this problem solved.

In the meantime, adding ‘notsc’ as a kernel option in my /boot/grub/menu.lst seems to fix the problem. I don’t plan on changing the kernel if I can at all avoid it right now!

Perils of Upgrading your Computer

Friday, January 13th, 2006

On Wednesday I took delivery of some new computer components - new CPU, motherboard, RAM and a couple of hard disks. I’ve built and rebuilt my own PCs dozens of times before, so this shouldn’t have been a problem. Of course, I’ve never had anything go wrong until now!

The first problem I encountered involved the new hard disks that I’d got (two 250GB Maxtor DiamondMax SATA drives). One worked fine but the other seems dodgy. Sometimes it would be recognised when I boot up and sometimes it wouldn’t. Of course, that might also be a problem with the SATA controller on the motherboard. Hopefully it’s not and I can just return the hard disk for exchange (otherwise I’ve got to dismantle the PC to get the motherboard out again and be without a computer for a while while it is replaced).

The second - and possibly more serious - problem involves the disk that I’d used to back everything up on. Unfortunately, there are a lot of errors when I try to ls:

jms@kermit:/mnt/hda3/jms30$ ls -l
ls: Desktop: Input/output error
ls: photos: Input/output error
ls: doc: Input/output error

Some stuff gets listed though. So I take a look at dmesg and see what it says. Not looking too good at all:

[25096.466561] ide0: reset: success
[25096.466868] hda: task_in_intr: status=0×59 { DriveReady SeekComplete DataRequest Error }
[25096.466873] hda: task_in_intr: error=0×04 { DriveStatusError }
[25096.466875] ide: failed opcode was: unknown
[25096.467016] end_request: I/O error, dev hda, sector 94277388
[25096.411425] EXT3-fs error (device hda3): ext3_get_inode_loc: unable to read inode block - inode=3325962, block=6651906

Looks like the disk is toast. So I am busily copying everything off the disk and will try some data recovery tools to see if anything is recoverable.

So the moral of the story is to make sure you have more than one backup of stuff that’s important, because the minute you have a problem with the original data (or delete it to make way for a new system in this case), you’re guaranteed to have a problem with the backup.

Daily Canterbury WeatherCam videos

Thursday, November 17th, 2005

I have had a webcam pointed out of my window in Canterbury for several months now. It’s always been my intention to automatically generate a daily animation of the images that people can download and watch. There were a number of challenges - first this would be done using Linux, second, the size of the file needed to be around 5MB to avoid filling up my website space too quickly. This entry describes how I did it - to see the results, take a look at a complete video of the 16th November 2005 or you can download and watch videos from the last seven days. (more…)

Migrating Linux root partitions

Monday, November 14th, 2005

Yesterday I finally decided to retire my 6-year-old 13GB drive and replace it with a slightly less old 60GB Hitachi drive. My system had been becoming increasingly unstable which I guessed was the hard disk overheating (or something) because it always seemed to crash during disk-intensive work. The Hitachi drive had a Windows partition and a load of my old files (which I have since copied over). I was also going to move my hard disks from the secondary IDE channel to the primary IDE channel which is faster. I thought the process would be easy, but as things conspired it was going to be slightly more than a walk in the park! (more…)

TV Card Followup

Monday, November 7th, 2005

Continued from here.

Well, after further problem-solving, it appears that the TV card that I have is faulty. I have tried tuning it in on Windows and even tried getting one of my friends to try it. However, it stubbornly refuses to find any channels whatsoever.

I have e-mailed the manufacturer (Hauppauge) and will see what their response is.

Linux and USB TV Cards

Monday, October 24th, 2005

Up until a few weeks ago I had a Hauppauge WinTV PVR-250 in the computer I use for recording TV. However, this PCI card was not particularly reliable, possibly because the motherboard that I have can’t supply enough power all the time to the PC card. The machine just froze periodically, usually while I was watching or recording TV!

Instead, I decided to get hold of a Hauppauge WinTV Nova-T USB2. A USB device would be perfect because it should in theory be possible to connect more than one to the computer (I think the USB2 bandwidth is enough for this) and record two channels at the same time. The Nova-T is also a DVB card that can pick up terrestrial Freeview broadcasts here in the UK.

However, getting this device to work on Linux is like trying to get blood out of the proverbial stone. First off I had to download and compile my own kernel. The kernel has to be pretty cutting-edge - 2.6.13 in this case. I recompiled the kernel many times trying to get the various modules needed all sorted out. However, I still had no luck - I’d plug the TV device in and it would work up until firmware_class tried to load the firmware for the device. Turns out there’s some sort of bug in the hotplug code that stops the firmware for the device from loading.

The solution to this problem (after many hours of Googling and hacking) was to manually load the modules using modprobe with the device plugged in. This must bypass the hotplug stuff. At this point, the light on the front of the device comes on and the relevant things appear in /dev/dvb/.

The next challenge (which I still have to work out) is how to get it to tune in to the various Freeview multiplexes. I know I can receive Freeview as I have a Philips Freeview box connected to the TV downstairs. The signal is fairly weak though and has to be boosted. The Nova-T is plugged in to the RF-through connection on the Philips box. Tuning in doesn’t seem to be as simple as with terrestrial analogue signals where it just scans all the available channel numbers. With the tools that I’ve found (scan, tzap, dvbtune, etc.) I seem to have to specify the frequency of the multiplex in MHz. Sadly I haven’t got it to tune into anything yet.

Sadly, the moral to the story is that getting something as bleeding-edge as USB DVB TV cards to work on Linux can be a real pain in the neck. The only upshot is that I can now recompile the kernel in my sleep!