John Stirling Stout's Blog

Raspberry Pi

Posted in Uncategorized by johnstirlingstout on May 10, 2012

My Raspberry Pi just arrived and is now working (we can’t watch TV, but until The Good Wife at 9.00pm I should be OK).

I first of all tried a slightly older image of Debian that I had downloaded on my laptop and it worked, but took a long time to boot up: when it did I didn’t have the password! So I downloaded the latest Debian ‘squeeze’ from raspberrypi.org, used the Win32DiskImager that the site recommends to write the image to the SD card and tried again (the MD5 hash that Win32DiskImager generated was not the one that it should have been by the way).

This time there’s a bit more information about one-time initialisation and some words of wisdom re waiting for portmap to stop. It rebooted, I put in the username and password (pi and raspberry) and got to the command line/shell.

I was expecting it to boot into the GUI, but a bit of looking at the Troubleshooting forum threw up a command I recognised: startx. I typed this in and we were running the GUI.

Scratch was my next stop. This is one of the two educational programming languages installed by default in this image (the other is Python). I much prefer BYOB so I went to the BYOB site for the latest BYOB.image and BYOB.changes files (the .image file is a memory snapshot of all the Squeak objects that together make the Scratch system, and the .changes file allows you to see the programming that went in to developing BYOB). These came down as a .zip file, which you can open using Xarchiver from the Other category on the Start menu.

I first of all tried extracting them directly to /usr/share/scratch but the standard pi login doesn’t have write access to this, so I extracted them to /home/pi/Scratch. I then ran a LXTerminal from the Accessories category on the Start menu, and from that used sudo (superuser do I assume) to run another copy of LXTerminal by typing:

sudo LXTerminal

I then changed directory to /usr/share/scratch with:

cd /usr/share/scratch

I wanted to keep the original Scratch.image and Scratch.ini files intact so I renamed them to ScratchOriginal.image and ScratchOriginal.ini using mv (a bit of a panic until I remembered that you rename files in Unix/Linux by moving them to the same directory with a different name):

mv Scatch.image ScratchOriginal.image

mv Scratch.ini ScratchOriginal.ini

I then moved the BYOB.image and .changes files to /usr/share/scratch with:

mv /home/pi/Scratch/BYOB.* .

then renamed them to Scratch.image and Scratch.changes with:

mv BYOB.image Scratch.image

mv BYOB.changes BYOB.changes

When I then ran Scratch from the Education category on the Start menu I got BYOB. Success!

John

Advertisements

Simon Singh’s libel case

Posted in Uncategorized by johnstirlingstout on June 6, 2009

This describes the bare bones of the BCA (British Chiropractic Association) case against Simon Singh.

Very much like the suppressed chapter (now available here) in Ben Goldacre‘s book on the medical treatment for AIDS popularised by Matthias Rath.

Posted in Uncategorized by johnstirlingstout on June 3, 2009

There’s a joke going the rounds about the way maths has ‘dumbed down’ over time, starting at

1. Teaching Maths In 1970

A logger sells a lorry load of timber for £1000.
His cost of production is 4/5 of the selling price.
What is his profit?

and going up to

5. Teaching Maths In 2008

A logger cuts down a beautiful forest because he is totally selfish and inconsiderate and cares nothing for the habitat of animals or the preservation of our woodlands.
He does this so he can make a profit of £200. What do you think of this way of making a living?
Topic for class participation after answering the question: How did the birds and squirrels feel as the logger cut down their homes? (There are no wrong answers.
If you are upset about the plight of the animals in question counselling will be available)

Unfortunately the version that seems to be going around at the moment has added a 6th for 2018, which consists of the Arabic translation of some, or all of the first part of the joke. It’s not clear what the intent is: a suggestion that the oil rich nations are able to buy up the UK? but what I find very worrying is that if you paste the Arabic into Google and do a search for it, the third link is for the British National Party (and I’m fairly certain I know what their intent is!)

Hans Rosling’s TED presentation

Posted in Uncategorized by johnstirlingstout on June 2, 2009

This is a presentation given by Hans Rosling about the changes in poverty, health, life span etc, particularly in the developing world compared to the rest, using interactive, animated graphics.

It was given at a TED conference where participants are invited to give the talk of their lives lasting 15 minutes.

The Try … Catch … Finally … End Try statement

Posted in Uncategorized by johnstirlingstout on June 2, 2009

The Try statement allows you to separate into blocks

  • one or more statements to be executed and that might have an error (these are placed in the Try block)
  • one or more statements to be executed if an error occurs in the Try block (these are placed in the Catch block or blocks)
    • one or more statements to be executed whether or not an error occurs in the Try block and whether or not these are caught (these are placed in the Finally block)

Here is an example, which uses a Try … Catch … End Try statement to try opening a file on a networked drive. If the network connection has failed when file is opened fails the file cannot be read from

        Try
            Dim theFile As New System.IO.StreamReader(“N:\Readme.txt”)
        Catch ex As Exception
            Console.WriteLine(“File not opened. Exception: ” + ex.Message)
        End Try

If the file doesn’t exist the .NET framework raises an exception: somewhat like raising an event: you don’t have to check for the error, just provide a handler for it. The details about the error are placed in an Exception object called ex and the code inside the Catch block can use this information, e.g., by displaying a message.

One problem with this is that an exception can be raised for a number of reasons, not just the File not found error. You can detect the presence or absence of a file with an If statement and using the My.Computer.FileSystem object like this:

        If My.Computer.FileSystem.FileExists(“V:\Readme.txt”) Then
            Try
                Dim theFile As New System.IO.StreamReader(“V:\Readme.txt”)
            Catch ex As Exception
                Console.WriteLine(“File not opened. Exception: ” + ex.Message)
            End Try
        Else
            Console.WriteLine(“File not opened. File or drive does not exist”)
        End If

It is always possible that the file exists when it is tested in the first line, but before the file is opened in the third line it is deleted, so using the Try statement after the initial check for existence is quite a good idea here.