Canvey Island’s Flood Warning Sirens to be Scrapped

May 1st, 2012

I grew up on Canvey Island. I left it nearly 25 years ago but visit my parents there when I can. I like to read the Echo‘s headlines email and was sad to see this one: Island’s flood sirens to be scrapped for good. This is an example of the siren subject of the article:

The sirens were used until recently for flood warnings, but by the sounds of this article, could originally have been air raid sirens. I’m sure there was once one near the end of Florence Road on Canvey Island, but StreetView doesn’t confirm it, so perhaps my memory’s faulty. The siren in the YouTube video was still there when the StreetView car last went past though. As much as the sirens are a part of the Island’s heritage, and – to my mind – a much more realistic warning system than a text message (have the people who make these decisions ever spent any time on Canvey Island and used a mobile phone indoors there?), I really don’t understand the rationale for scrapping them as the Echo presents it.

According to the article, two companies with local presence are prepared to stump up the running costs of the sirens. If that’s true then the suggestion that there’s some saving to be made by choosing the modern system (‘outdated’ – the other justification – seems so fecklessly heartless) appears to be unfounded. I sent emails to Oikos, Calor to ask for more information and English Heritage to see if there’s any way to protect these quiet guardians and little pieces of Canvey’s history. If I find out anything of value, I’ll post it here.

Some older articles on the same subject:
Who is to blame for flood siren removal?
Hundreds will not get vital flood warning

I see a comment on the Echo’s article to the effect that the last flood’s death toll was due to the type of construction prevalent at the time:

Plus, let’s not forget the 1953 floods killed so many due to Canvey being covered in lightly built bungalows. These days the majority of people live in substantially built houses, the highest flood water in ’53 would barely reach the ground floor ceiling of modern properties.

See this article from floodsite.net with a lovely photograph of some new Canvey development (scroll to the bottom of the page).  Floodsite also have a marvellous video on their website that seems to have been made soon after the flood. I can’t see a copy of that video anywhere else on the WWW and floodsite don’t state its provenance, so I’m going to copy it here, just in case:

I wish more people would do this: someone here interviews their granddad to capture his memories of the event. Excellent job!

LEGO Mindstorms NXT Alpha Rex building instructions / plan

January 22nd, 2012

LEGO Mindstorms NXT 2.0 Alpha Rex

I bought the LEGO Mindstorms NXT 2.0 recently and was a bit disappointed to find that it didn’t come with printed instructions to build Alpha Rex – the robot on the box art. I searched for the instructions all over the web but couldn’t find them. The building instructions are available from within the Mindstorms software as a kind of Flash animation (I think). I don’t use MS software (all PCs Ubuntu at the moment), but recently acquired a ‘WorkAtHome’ licence for an ill-conceived project at work that depends on Excel. I looked through the installed files to see if there was any content in an accessible format but again found nothing useful.

The file below is one screenshot per page of the LEGO Mindstorms software running on a Win7 guest on VirtualBox on Ubuntu. I used Shutter from http://shutter-project.org/ (install Shutter from your Ubuntu repository with this APT link) to take the pain out of capturing the first 73 screenshots. You can define a snapshot area with Shutter and ‘refresh’ the screenshot with Ctrl-F5 after clicking ‘Next’ in the Mindstorms software. Shutter creates a new file with the next screenshot in the series.

My brain was blank when the time came to convert the set of images into a PDF, so I used gvim to convert the ‘ls | cat’ list of file names into a LaTeX file and XeTeX to produce the PDF. Here’s a sample of the head of the AlphaRex.tex file:

\documentclass{article}
\usepackage[a4paper,landscape,top=0cm,bottom=0cm,left=0cm,right=0cm]{geometry}
\usepackage{graphicx}
\begin{document}
  \noindent
  \includegraphics[width=\textwidth]{Selection_002.png}
  \includegraphics[width=\textwidth]{Selection_003.png}
  \includegraphics[width=\textwidth]{Selection_004.png}

And here’s the PDF – use either evince or Adobe Reader to open it.

AlphaRex.pdf (8.4MB)

Alpha Rex arms (8.9MB)

Alpha Rex head (1.4MB)

Alpha Rex colour sensor (459kB)

I expect there’s a copyright issue of some kind with providing this content. Hello! This is not my work. I copied the images from LEGO’s software which I obtained by buying the NXT 2.0 8547 set. Please do not attempt to send me money even if you believe I have helped you. I don’t want to be extradited to a country with psychotically oppressive copyright laws, communal prison showers and obese oversexed convicts. I am too old and too lightly built. And I haven’t finished building Alpha Rex. I will happily remove the PDF if someone can provide me with an URL for LEGO’s version of the Alpha Rex instructions. I’m a lifelong LEGO user and frankly a bit miffed that the only way I can access the media I thought I’d bought is by acquiring a MS product.

OT: It was much quicker to create that PDF than it was to work out where to change my Apache/PHP config so that WordPress didn’t give me the ‘Maximum upload file size: 2MB’ (or 8MB) problem. The pages I found on the Web about this issue related mostly to people using WordPress on shared hosts: I use a comfortingly reliable Xen VPS from XenSmart. I eventually found an Apache-specific config file here: /etc/php5/apache2/php.ini – simply increase the limit in upload_max_filesize and post_max_size somewhat larger. I see a lot of suggestions to have matching limits or even upload_max_filesize larger than post_max_size. That strikes me as odd, given RFC2388. Am I missing something?

Update 23rd January 2012: should have put a bit more effort into looking. The build instructions for the box art models have been screen-capped (I guess) and posted on DropBox – see this forum post:

http://www.eurobricks.com/forum/index.php?showtopic=54141&view=findpost&p=1153643

That archive also contains the program files for the NXT.

Religion-free state education in the UK

September 6th, 2011

We recently returned to the UK with two young children from a financially cavalier extended ‘babymoon’ in Malaysia. Part of the impetus to move back again was my reluctance to put my children through the Malaysian state education system which emphasises racist division and religious practice, though possibly not in that order and with the caveat that they may not be two discrete issues.

Late to the UK school admissions process, we used our local Schools Admissions department’s School Transfer scheme to state 3 preferences for schools for our school-aged child. The online mapping service was very useful – we could easily see where were the nearby schools and follow the provided links to Ofsted reports and to the schools’ own websites where they existed.

What was quickly apparent was that very many local infant schools were church-linked. I don’t want a church-linked education for my children, just an education. Our number one preference (we chose 3 schools which were not explicitly church-linked) offered our daughter a place, and we were delighted with the school when the head teacher gave us a tour around it. The school is in a ‘federation’ with another infant school which is church linked and has the same name as the one our daughter will attend but with “Church of England” in its title.

This morning I read an article on the BBC website about State schools ‘not providing group worship’ and wondered why this should be news in a modern world. This quote stood out:

The Department for Education states that all maintained schools in England must provide a daily act of collective worship which must reflect the traditions of this country, which it says are, in the main, broadly Christian

Anxious to verify this obligation, I searched and found the same thing on the Department of Education’s website. So it appears to me that I don’t have a choice to send my child to a non-church school: all schools are obliged to ‘provide a daily act of collective worship’.

I am shocked to discover this is the case in the UK, which I have always – perhaps occasionally in the face of evidence to the contrary – protested was a secular democracy. It seems to me (if the statistics presented in the BBC’s article are to be believed) that I am likely not alone in preferring my children receive an education that does not by default include religious indoctrination.

I’m not quite sure what to do with this new information, and thought I’d put a message in a bottle to see where it might wash up. Did you know about this obligation on schools? What do you think about a ‘right to withdraw’? Does it seem to you that children should instead have a right to a basic education which is free from religious indoctrination?

I see no other reasonable way of interpreting “a daily act of [broadly Christian] collective worship” other than as religious indoctrination. I see news about ‘free schools’ starting which must be about to provide a daily act of non-Christian collective worship and I fear that the UK is starting down a path which can only lead to deeper divisions and greater social tension. Social cohesion is something our children can learn at school, even (or perhaps particularly) if it isn’t explicitly taught as a discrete concept.

I would be interested in the opinions of other parents.

Look Ma, no files! Portable object persistence

August 19th, 2011

Originally posted at JavaProgrammingForums.com

Where can I store my application data?

I see a lot of people starting threads because they’re struggling to persist (often) a little bit of data from one run of their Java application to the next. The offered solutions are often some kind of jiggery-pokery involving java.io.File. Not only is File handling a cross-platform morass (our favourite OSes can’t even agree on path separators, let alone filesystem roots and GoodPlacesToPutApplicationData™), but every so often another limited-resource computing device appears, some of them without a natural filesystem at all.

So if we can’t store data in files, where can we store data? Enter the Java Preferences API in the java.util.prefs package. Preferences is a platform neutral way to store a small amount of simple data. It offers support to store Strings and built-in data types and retrieve them without having to worry how they are persisted. You simply obtain a Preferences instance, store your value-to-be-persisted on a key, exit your app and sleep easy. The next time you start your app, you obtain the Preferences instance and invoke get([key you used previously], [default if nothing’s there]). Ideal – for simple use.

Preferences was designed to be simple and lightweight, so it doesn’t include any support for storing Java Objects. Worse, it imposes severe constraints on the size of values that can be stored. My Java 6 API docs say that a String store by a Preferences instance can be up to 8,192 characters long (Preferences.MAX_VALUE_LENGTH). And only built-in datatypes and Strings may be stored! So if we can accept the constraints of the Preferences class, how would we use it to store arbitrary objects? Here’s my first stab at it.

An Object to String bridge

We’re going to store Objects as Strings. Java offers Serialization as a means of storing and retrieving objects to and from streams, so that’s what we’re going to do – serialize an Object to a stream. What kind of stream? A stream that creates a valid String object. Then we’re going to store that String in a Preferences instance. When we later retrieve the String from the Preferences instance, we have to go back across the bridge – deserialize the String – back into our original Object-that-was-stored.

We know we can create Strings from byte arrays, and we know we can get a byte array from a String, so it seems like we should be able to use ByteArrayInputStream and ByteArrayOutputStream to bridge between byte arrays and streams. So far so good: Serialization does Object-to-Stream and the ByteArray{In|Out}putStreams will do Stream-to-byte-array. The problem with this first bridge should be evident from the API docs for the String(byte[]) constructor:

Constructs a new String by decoding the specified array of bytes using the platform’s default charset. …
The behavior of this constructor when the given bytes are not valid in the default charset is unspecified.

That’s clearly not good. ObjectOutputStream creates a stream of bytes that is a valid object, not a valid String in any Charset. So to bridge this gap we need another pair of Streams to bridge the gap between streams of valid Object bytes and streams of valid String bytes. FilterInputStream and FilterOutputStream are a pair of handy Streams for just this purpose.

What I chose to do (I can post the code if anyone is interested) was to extend Filter{In|Out}putStream to accept a stream of arbitrary bytes on one side and output a ‘hex’ representation of those bytes on the other side. Every byte that is written to my HexOutputStream (the class I extend from FilterOutputStream) by ObjectOutputStream is converted to a 2-character hex representation, which is in turn written to the ByteArrayOutputStream as 2 bytes. OK, so I’m obviously doubling the size of the stored object, but I can absolutely guarantee that a string of bytes which are ‘0’ to ‘9’ and ‘a’ to ‘f’ are valid String objects in any Charset.

So far so good – my Object to String bridge is now

mySeriliazableObject -> ObjectOutputStream -> HexOutputStream -> ByteArrayOutputStream -> new String(byte[])

and my String to Object bridge is

String.getBytes() -> ByteArrayInputStream -> HexInputStream -> ObjectInputStream -> mySerializableObject

Let’s have a demo.

A suitable problem

I’m not very good at remembering birthdays, particularly bad when it’s the birthday of my Significant Other. I could write a command-line application to keep a note of the birthday, but I’m a platform butterfly and I know I’m going to change my PC soon, but I can’t be sure whether I’ll be using an Android phone, an Ubuntu nettop, a LEGO NXT brick, an iPad or a Windo… no, let’s not go too far. I want this app to remember the special birthday, so I create a serializable class so that I can create birthday instances from the keyboard and store and retrieve them from some persistence backend. I don’t care what the persistence back-end is, so Serializable at least bridges my class to streams. Streams are good. I can write stuff into them, read stuff out of them, and I don’t care what’s at the other end.
Here’s Birthday.java:

package com.javaprogrammingforums.domyhomework;

import java.io.*;

import java.util.regex.*;

public class Birthday implements Serializable
{
  public final static long serialVersionUID = 42l;
  public final static Pattern PAT_BIRTHDAY = Pattern.compile("^([0-9]{1,2})[a-z]{0,} ([JFMASOND][a-z]{2,8})$");
  public enum Month
   {
    January(31), February(29), March(31), April(30), May(31), June(30), July(31), August(31), September(30), October(31), November(30), December(31);
    private final int MAX_DAYS;
    Month(int maxDays)
    { MAX_DAYS = maxDays; }
    public void validate(int day) throws IllegalArgumentException
    {
      if (day < 1 || day > MAX_DAYS)
        throw new IllegalArgumentException("Not a valid day in " + this + ": " + day);
    }
   };
  private final int day;
  private final Month month;
  public Birthday(int dayOfMonth, Month m) throws IllegalArgumentException
  {
    m.validate(dayOfMonth);
    day = dayOfMonth;
    month = m;
  }
  public static Birthday parse(String s) throws IllegalArgumentException, NullPointerException
  {
    if (s == null)
      throw new NullPointerException();
    Matcher mat = PAT_BIRTHDAY.matcher(s);
    if (!mat.matches())
      throw new IllegalArgumentException("Bad format for birthday: '" + s + "'");
    try
    {
      Month m = Enum.valueOf(Month.class, mat.group(2));
      return new Birthday(Integer.parseInt(mat.group(1)), m);
    }
    catch (Exception e)
    {
      throw new IllegalArgumentException("Bad month: '" + mat.group(2) + "'", e);
    }
  }
  public String toString()
  {
    return month + " " + day;
  }
}

Marvellous, a Birthday class that stores only a day-of-month and a month as an int and an Enum. Should be plenty good enough for a demo of Object-into-Preferences.

Now for the application. The application PreferencesSOBirthday starts up, tries to retrieve a Birthday from the Preferences back-end, displays it as a reminder if there’s one in there. If there isn’t a Birthday object in the Preferences instance, it asks you for one and stores it. Nowhere in the code will you find any mention of a File. For that matter, nowhere in the code will you find any explicit choice of persistence storage at all – all it does is to obtain a Preferences instance that’s suitable for the user/application, and stores the object. The next time you run the application – tadaa – the object is magically there!

package com.javaprogrammingforums.domyhomework;

import java.io.*;

import java.util.prefs.Preferences;

public class PreferencesSOBirthday
{
  private final static String PREFS_KEY_BIRTHDAY = "significant.other.birthday";
  public static void main(String[] args) throws Exception
  {
    // may throw SecurityException - just die
    Preferences prefs = Preferences.userNodeForPackage(PreferencesSOBirthday.class);
    if (args.length > 0 && "reset".equalsIgnoreCase(args[0]))
    {
      System.out.println("Command line argument 'reset' found - data removed.");
      prefs.remove(PREFS_KEY_BIRTHDAY);
    }
    // fetch the string-encoded object
    String sSOBD = prefs.get(PREFS_KEY_BIRTHDAY, null);
    if (sSOBD != null)
      try
      {
        // check preferences string actually contains a Birthday
        getBirthday(sSOBD);
      }
      catch (Exception e)
      {
        System.out.println("Ouch, my brain hurts!");
        sSOBD = null;
        prefs.remove(PREFS_KEY_BIRTHDAY);
      }
    while (sSOBD == null)
    {
      System.out.print("OMG are you in trouble, I don't know your SO's birthday - enter it now: ");
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      String sBirthday = br.readLine();
      if (sBirthday == null)
      {
        System.out.println("OK, be like that then");
        System.exit(0);
      }
      try
      {
        Birthday b = Birthday.parse(sBirthday);
        sSOBD = toPreference(b);
        prefs.put(PREFS_KEY_BIRTHDAY, sSOBD);
      }
      catch (Exception e)
      {
        System.out.println(e);
        sSOBD = null;
      }
    }
    System.out.println("Be prepared - your Significant Other's birthday is " + getBirthday(sSOBD));
  }
  // String to Birthday bridge
  private static Birthday getBirthday(String s) throws NullPointerException, IOException, ClassNotFoundException
  {
    return (Birthday)new ObjectInputStream(new HexInputStream(new ByteArrayInputStream(s.getBytes()))).readObject();
  }
  // Birthday to String bridge
  private static String toPreference(Birthday b) throws IOException
  {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(new HexOutputStream(baos));
    oos.writeObject(b);
    oos.close();
    return new String(baos.toByteArray());
  }
}

I’ve tested this on Ubuntu and Windows XP. The code was compiled on Ubuntu and I copied the class files over to Windows XP and they worked exactly the same there. You’ll have to run the application once to be told there’s no data and enter a date – the application exits. Run it again, it always ‘remembers’ the date. Run it with a single command line argument of ‘reset’ and it’ll remove the object (OK, the encoded string value) from the Preferences instance. Here’s a command line to run the app:

java com.javaprogrammingforums.domyhomework.PreferencesSOBirthday

Remember to run the application at least twice, or you won’t see persistence ‘in action’. Here’s a command line to reset (remove) the stored data:

java com.javaprogrammingforums.domyhomework.PreferencesSOBirthday reset

Where next?

It shouldn’t be difficult to turn this trivial example into a general-purpose Object Persistance engine based on the Preferences API, but I would caution against it because of the arguments put forward by Sun in the first article linked above. Preferences really isn’t for arbitrary Object storage, it’s for storing simple configuration data. Still, if a solution such as the one above fits your requirements and you are disciplined enough to avoid the temptation to base a mega-project on it instead of using a proper persistence back-end, then I think it has some kilometrage.

Enjoy.

… time passes … realised you can’t actually execute this code at all without the HexStreams – d’oh! Here’s a jar file with all the classes ready to run: SOBirthday.jar

and the source:
SOBirthday.2011Aug19.16.36.src

Foreign Exchange data from Central Bank of Russia

July 29th, 2011
Bank of Russia

The Central Bank of the Russian Federation

I’ve been re-jigging and polishing up some of the leftover code from spider.my and am now fairly happy with the way Shipping-Quote.net keeps its currency exchange rates up to date. I wanted to add another rates source just to fill things out a bit, so it seemed like a good idea to add rates from Russia.

The Central Bank of the Russian Federation has a web-based daily foreign exchange resource with statistics going back many years. I couldn’t find a single non-interactive page or feed that would make it easy to update the rates at Shipping-Quote.net though, so emailed the address at the bottom of each page at CBR’s web. I got a prompt reply (I’m still surprised – and grateful – when websites do that) telling me that such a resource is available, but the page that explains how to obtain exchange rates from the Bank of the Russia is only available in Russian. That’s cool – Google translate works!

The new rates from Russia now support those vital exchange rate queries which even Google can’t answer, such as the value of 250 Turkmenistan New Manat in Cambodian Riel, or how much 1,000,000 IMF Special Drawing Rights are worth in Moldovan Leu, or how much 1,000 Bahamian Dollars are in Armenian Drams.