How to get Java class name from static code

July 15th, 2009

I thought of one way to do this, but checked Google first to see if there was an easier, more obvious way. Real Gagnon has a method at his site which is similar to the way I thought I could do it, but no less obscure or easy!

Here’s my code, in case it comes in handy for you:

System.out.println(Thread.currentThread()
    .getStackTrace()[1].getClassName());

The first (zeroth!) thread in the stack trace is ‘java.lang.Thread’.

It’s a pity Sun didn’t use the reserved word ‘class’ as the static counterpart to ‘this’. That way it should have been possible to get the name as “class.getName()”, which would have been neat. I’m sure there must be a good reason. Is there?

Farrah Fawcett will always be an Angel

June 26th, 2009
Farrah Fawcett

Farrah Fawcett

Farrah Fawcett also died today. I struggle with words around bereavement, not having any off-the-shelf ideas about what happens when people die. To me, a person – their personality – is something made up of all my experiences and memories of the person. When they die, they don’t really go anywhere – their personality is as vivid in my mind the day after they die as it is the day before they die. As time passes, all that remains in my mind is my favourite memories of the person. When all that remains is my dearest memories of the person, then they’re really ‘in a state of grace’.

My dearest wish for my own after-life is that a few people should occasionally remember me, and the memory bring them a little happiness. That’s my heaven.

LA Times reports Michael Jackson dead, HEAD missing

June 26th, 2009
Michael Jackson - from Wikipedia

Michael Jackson - from Wikipedia

I was manually adding some reports of Michael Jackson’s death to the crawl queue at spider.my this morning, when I noticed that one of the machines doing indexing had choked on a page. It wasn’t long ago that I added some code to detect <meta> elements in pages being used to specify the character set for the page. The regular expression that I’d come up with to extract the  content-type from the http-equiv header field just seemed to be looping, using 100% CPU.

I wrote some code that was a little more pedestrian, that I hoped would be more robust. It failed to find the content-type that I could see in the page source, but at least it didn’t hang! It took me a little while to work out that it was caused by the page having no <head> element. I’m relatively new to developing for the Web, so it’s sometimes surprising it all works so well, when you see the quality of the data!

LA Times missing HEAD element

LA Times missing HEAD element

Just for completeness, here’s the cached copy of the LA Times page from spider.my’s page cache. Have a look at the page source. The LA Times page begins about 6 lines down with an HTML element. See? No HEAD.

Teresa Kok’s list of porn sites

June 17th, 2009
The Malaysian Insider

The Malaysian Insider

Well, pardon me for keyword whoring, but I just had to write something about the article in The Malaysian Insider: No porn please, we are civil servants about the Prime Minister’s reply to a written question from Teresa Kok. It’s no good, while I’m painting bullseyes on this article with keywords, I have to express my gratitude to TMI for specifying that the question was written, and not oral. I now include the word ‘sex’ for no other reason than to equip this article with a full set of the Internet’s most enduring popular keywords. Now… if only I could think of a reason to include 5318008.

TMI gives a few examples of sites that are allegedly banned from civil servants’ browsers. Out of professional interest, I checked the domains – all subdomains in blogspot.com – and discovered that they’re blocked for me too! Not only are they blocked, but they’re blocked by Streamyx and not reliably by DiGi. Here’s a dig on Streamyx:

Site blocked by Streamyx

Site blocked by Streamyx

And here’s the same dig on DiGi:

Site not blocked by DiGi

Site not blocked by DiGi

The method Streamyx is using to block the sites is DNS Poisoning: their name servers return an IP address which is the special address 127.0.0.1 which means ‘your own computer’ (localhost). When you attempt to load a page from this domain with your browser, your browser ends up sending the request to your own computer, which of course refuses to reply.

It’s quite an effective technique in this case, as very many websites are hosted by google on a single IP address, so you can’t access the site just by using the IP address: you’ll get a google search page. Of course, you could still load the page by ‘innoculating’ your local nameserver, if you have one, or by adding the domain to your local ‘hosts’ file. Most operating systems provide a way of statically matching names to IP addresses. Alternatively, if you’re a HTTP hand-crafting wizard, I’m sure you could construct a HTTP request yourself, I’m sure there’s probably a Firefox plugin that would help you.

Of course, you’d have to be fairly desperate to track down the civil service’s official porn sites. It’s certainly not high on my list of priorities. It should be obvious to most people that if (as TMI’s report suggests) the list has only 38 sites on it, the sites are just a drop in the ocean. The reason I’m writing about it is that TMI suggests that the sites are blocked for civil servants. This is an under-statement. I am not a civil servant, and yet the sites are also blocked for me. I don’t want to see them, but then, I don’t want my Internet Service Provider secretly selecting what I can and cannot access on the Internet.

This should be effective - from Lady Mariah's blog

This should be effective - from Lady Mariah's blog

Attention TM! You can block all the porn sites that are not to your taste, and I really don’t mind. I don’t trust you to make the right choices though, so I would be greatly reassured if you were to publish your blacklist, or at least the fact that you are operating one. Since that would be tantamount to providing an Official Malaysian Porn Site Directory, how about poisoning your DNS with the address of one of your servers that has a single page informing your customers of your blacklisting policy, without naming sites? You could even tell them their IP address had been logged. You could even show them an animated picture of the PM shaking his head and wagging his finger – they would never look for porn again!

The TMI also mentions a site that’s blocked for being ‘seditious’. Google has removed the site from its blogspot service, but you can see the site’s content on The Wayback Machine – I hope they’ll keep the archive available as a public service. I do wish the Malaysian Government hadn’t played the ‘sedition’ card: the site was unarguably intended to incite violent crime. The site’s content was very different from other cases currently labelled as ‘seditious’, but they are not at all comparable, in my opinion.

Internet on Canvey Island. How hard can it be?

June 16th, 2009
Canvey Island postcard from www.canveyisland.org.uk

Canvey Island postcard from www.canveyisland.org.uk

I’m an eternal optimist. I went to the UK a few weeks ago for a party with some old friends in Lancaster, but stayed first with my parents on Canvey Island. Canvey Island has its detractors, but I grew up there and have very fond memories of it. I always make sure I get a couple of long walks in around the sea wall when I go back there. It’s not picturesque, but it is interesting to see the remains of the ancient sea wall poking out from beneath the modern one, and I never tire of seeing the sea so high on one side and the houses so low on the other!

I like to travel light – I would never carry a laptop with me (article on Dell Mini 9 coming soon!) unless I was actually en route to do a job with it. There’s a ten year old Compaq Deskpro 6300 in my parents’ attic from when I did my PhD. I thought I’d arrive there, buy any missing parts I needed (I knew there was no screen, for instance), install a copy of Ubuntu, and connect via dialup with my old US Robotics modem, or try out a USB 3G adapter.

I bought a cheap wide-screen (and later regretted not having a scroll button on my old mouse!) LCD monitor from the Tesco in Pitsea, and went to the local library for a copy of an up-to-date linux. There was an old Slackware install already on the hard disk, but I couldn’t get a PPP session established with any of the dial-up numbers a friend gave me. The old Slackware install didn’t seem to be complete, so I set off for a walk around the Island to find an Ubuntu install CD. Was I being naive? I didn’t think so at the time!

My first stop was the Library. I have very fond memories of Canvey Island library. As a teenager I spend very many evenings and weekends there. It had an enormous SciFi section back then, and had the best opening hours of any library of any town or city I have lived in in the last 20 years. It was open late into the evening 6 days a week and open on Sundays too. Now it seems to have a lot more space inside, but I was pleased to see a wall filled with PCs. When I asked the very nice librarian if they had any boks about Linux that included a CD, it seemed like I was speaking a foreign language. I remember first finding Linux in a book with a CD inside in a library. I’m sure I first installed MkLinux on a PowerMac from a library book.

I searched the IT shelves (not very many!) at the library and found nothing about Linux at all. I asked the librarian if I could download a copy of Linux and burn a CD, but they replied that they did not provide the means to burn CDs. I asked for computer shops on the Island, and they told me I could try Selectronic or Canvey PC. The Island is not a big place, and my dad never stopped waxing lyrical about the benefits of Shanks’ Pony (academic, we were always too skint to afford a car), so I set off on foot to find Linux.

There’s a Sainsbury’s in the Knightswick Centre just across the road from the Library. It was one or two other supermarkets before that, and when I was at St Joseph’s over 30 years ago (I’m so effin old!), the area was just a huge waste ground. I think I remember some sort of covered market there from when I was very young, but by the time I was at school, it was just a great place to climb Elder trees, make dens in the Ivy that hung between them, and throw stones at the remnants of old windows in the ruined buildings there. Happy days!

I had a look through the computer mags in Sainsbury’s for a Linux CD, but no such luck. There was a big Martin’s newsagent in the shopping centre, but that seems long-gone. Selectronic is not much further up the road, but it seems to be a photo-printing shop with a few extra bits and bobs (including a Nokia 6500 Classic for ten quid cheaper than I paid in Tesco at Pitsea a few days earlier, I noticed). They said “no, nothing like that” and directed me to Canvey PC.

Canvey PC

Canvey PC

I couldn’t find Canvey PC at first. I must have walked past it 4 or 5 times before I noticed the sign by a door by the side of another business. Upstairs is a modern-looking shop and workshop, and the man working there reached into a cupboard and gave me an Ubuntu install CD. It was a real ‘Hallelujah moment’ until I got home and realised how old a version it was! Still, I was impressed just to find someone who knew what I was asking for, much less had a copy available! Well done, CPC.

The old PC at my parents’ house seemed to work great with that Ubuntu installed, though it was 6.06 (Dapper Drake), so the Vodafone USB TopUp And Go USB 3G adapter that I bought at the Vodafone shop  in Basildon wasn’t recognised by it (Ubuntu 6.06 was released in 2006), and I still couldn’t get online with the dialup numbers my friend gave me. I was glad to find that you can use the ‘screen’ utility to get a terminal session on the modem, just in case those dialup numbers offered BBS-style help menus, but no such luck. Does that kind of thing even exist any more?

By this point, I was kicking myself for not bringing an Ubuntu install CD with me. A friend of mine who lives some distance away from the Island dropped off an up-to-date Xubuntu install CD at my parents’ house which failed to read in my old 4X (so slow!) CD drive. I asked the same friend to pop round again with the CD image on a USB flash drive, and took it to Selectronic, who burned it onto another CD for me (the old Compaq wouldn’t boot from a USB drive) and charged me a reasonable price for something they presumably don’t do every day.

Xubuntu

Xubuntu

Finally, I had Xubuntu 9.04 (Jaunty Jackalope) on my old PC, and it recognised the Vodafone USB 3G stick straight away and connected to the Internet. The old PC is a 300MHz Pentiuim with 192MB RAM, so the user experience isn’t lightning fast – but it works! Running more than 1 or 2 applications at once causes the machine to thrash the hard disk too, but I edited some images from my phone using the GIMP and everything in Firefox seemed to work just fine. Flash videos were too slow to watch – only 1 frame every few seconds on some videos. I didn’t try watching any proper videos, but when Jess and I were first married, we used to watch DVDs rented from the local late shop on that machine. Mplayer did drop some frames, but not annoyingly so.

I guess the moral of this story is that if you’re going somewhere expecting free open source software to be growing on the trees, you’re as big a twit as I am! Next time, I’m going to carry the CD with me. A bootable USB stick might be a good compromise between use and reliability, but if you’re presented with an old nail of a PC, you’ll be needing someone to burn that image on your USB onto a CD for you. A photo printing shop seems like the place to ask. The bootable USB I made later requires that Ubuntu’s files are stored on a FAT partition, so if you want the option to burn a CD-ROM too, you’ll need a USB flash drive that’s big enough for both uses: something over 1.5GB (or two USB flash drives!).