Archive for January, 2010

Jan 31 2010

Crappy shortbread recipe disaster!

Published by Dougal under Books, Food

We’ve had so much success with recipes in the last few years that it’s sometimes easy to forget that some recipes are useless through and through. If you’re not very familiar with the general idea then it’s easy to get dragged far from the path by a instructions that are confusing or just downright wrong.

That’s what happened to me last week when I tried Scrummy Chocolate Swirl Shortbread from the Green & Blacks Chocolate Recipes book. I couldn’t really remember what the process for shortbread was so I just followed the instructions and ended up with something useless quite demoralising. I later checked Delia and James Martin’s respective recipes for shortbread and confirmed that the recipe in the Chocolate book is utter bobbins. Compare:

  • Cream sugar into butter, then add flour.
  • Mix dry ingredients then rub in butter.

The first one gets you a stiff dough, the second ones gets you breadcrumbs. And at that point there’s not much you can really do to pull it back — it’s not easy to decrumb crumbs.

I’ve just tried again, ignoring the mixing process they suggested in favour of Delia Smith’s instructions, and they seem much better. They’re cooling at the moment. Now I get to revisit the original recipe and mark it up for future occasions. I’m not sure if I should write proper instructions, or just score the whole thing out with “Wrong! Consult Delia!”. That would be more satisfying.

2 responses so far

Jan 29 2010

Dilution of trust: homeopathy for sale at Boots

Published by Dougal under Bad Science, Health

Tomorrow (that is, 30 January 2010) there are going to be a number of demonstrations/protests outside branches of Boots, under the general name of the 10:23 campaign. At 10:23, a bunch of not-very-brave people will be “overdosing” on homeopathic pills. I think the plan is that each person takes a bottle full. This will, of course, have no downsides whatsoever because there is nothing in it.

The point in this case is not to point out the stupidity of homeopathy to the people in the street, though it will no doubt do that. It’s to make the point that Boots sell these things — have whole aisles devoted to these little white pills — even though they admit there is no evidence for their effectiveness. There are even Boots-branded homeopathic pills on the shelves! And at the same time they sell you something useless, they want you to know that their pharmacists are trustworthy enough to dispense medicines with active ingredients, and give advice about these medicines.

I leave you with James “the Amazing!” Randi, to explain the absurd details of homeopathy in his wonderful way:

No responses yet

Jan 26 2010

Toe surgery

Published by Dougal under Life

About a fortnight ago now I went into a chiropody clinic for some medical attention on my big toe. I’ve had a bothersome ingrown toenail for quite some time and eventually found a doctor who pointed me in the right direction for treatment. Thank you Dr Reiff-Musgrove.

I received a couple of injections to numb the area and then they went at my foot with little bolt-cutters. It was fascinating to watch (though not if you’re a bit squeamish) — cutting down into the nail to the nail bed and then using a poky-stick to fill the resulting wound with phenol to inhibit nail regrowth. With luck I should have a mostly-normal nail when it all heals, but without risk of the same thing recurring.

For a few days I had a huge cartoonish bandage wrapped round my big toe which meant wearing a sandal on that foot. This is a very cold way to dress in winter. More recently the toe has been redressed with neater coverings which allow me to wear shoes again. I’m still trying to wear shoes as little as possible though to reduce pressure on the affected area. Which ultimately means that I wear the dreaded socks-with-sandals übernerd combination at home in the evening. (You can ignore this image and continue to think of me in a velvet smoking jacket and slippers if that makes the nightmares go away.)

So far I’ve been delighted by the sudden loss of background pain, which I’ve been growing accustomed to for several years now. The site of the operation still looks pretty horrible but it’s not painful. I can walk again to some degree, though I think it will be some time before I can don a pair of walking boots and go into the hills. I had intended to document the healing process with the camera but as the toe spends most of its time in bandages that’s proven quite difficult.

I look forward to doing all the usual feet related activities — like buying shoes that fit, ceilidhing without pain and wearing sandals without fear of frightening small children.

2 responses so far

Jan 18 2010

Hm, I think not.

Published by Dougal under Humour, Programming

Taken from the man page for strncmp:

       The following sections are informative.
 
EXAMPLES
       None.
 
APPLICATION USAGE
       None.
 
RATIONALE
       None.
 
FUTURE DIRECTIONS
       None.

I hope that was a joke.

One response so far

Jan 05 2010

Filesystems and data recovery (an explanation of sorts)

Published by Dougal under Computing

I posted a short guide yesterday to recovering photographs from corrupted memory cards. There were a few interesting technical points in that post that I glossed over for the sake of the explanation, but discussion on Facebook has prompted me to try filling in those gaps. Let’s have a look.

File systems

How is stuff written to and read from a disk, and why would it suddenly stop working?

Reading and writing disks

Picture a disk as a big sheet of grid paper. Each little square in the grid can hold a single letter, and that little square has a location, like the grid reference. We can read and write a single letter at a time by knowing its grid reference. Most things which are written on the paper will take up many little squares, because most useful information is more than one letter long — words, sentences, paragraphs and so on are stored as long sequences of individual letters. This doesn’t really pose a problem because our sheet of paper is easily big enough to hold all the sentences we could ever write. It is also possible to store many different sequences of text on one sheet of paper, so that books sit alongside essays alongside love letters alongside formal complaints. The only problem this does leave us with is organising and retrieving the information, since a gridded sheet where each box contains a single letter will start to look more like a wordsearch after a while.

If we have been sensible we will write our texts onto the great sheet of paper in a consistent manner, such as left-to-right, and starting a new row one line down whenever we fill up the previous row. The system of organisation we use is arbitrary — we could just as easily use right-to-left, write vertically or move up a row instead of down at the end of each line. It doesn’t really matter as long as we are consistent. (This should be obvious from the history of written language!) We can then identify the beginning of a piece of text by knowing the grid reference of the first letter; and we can retrieve the whole text if we know how long the text is, since it was written in a consistent direction. If we do this we should easily be able to organise all the information we have by keeping track of the starting location and length of all the sequences of letters we write.

The disk, like the gridded paper, is full of little slots where data can be stored; and each slot has a location called its “address”. Data can be stored on disk in long sequences of adjacent slots. To get the sense of the original data we only need to know the starting address and to read the correct number of entries from that point onwards. All we need to extract a file from disk is two numbers — the address and the length. From this we can reconstruct the original data.

Now we have many long essays and books and letters stored on the hypothetical sheet of paper, and these long sequences of text can be reached via the much shorter pairs of numbers we mentioned, representing address and length. But where are these numbers kept? The one location that doesn’t require any intelligence to find on a grid of paper is the start, which we shall call address 0 (zero). How can we use this to our advantage? We could write a list, starting at address 0, which contains the pairs of numbers needed to find all the other sequences of letters! It will never be possible to “lose” the sequence at the top corner of the sheet of paper so we will always be able to access this contents listing for the rest of the page.

But think again: if the sheet of paper is covered in many sequences of letters, it’s very conceivable that one of those sequences will contain map references or temperatures or other lists of numbers that could be mistaken for the pairs of numbers which we use to find the texts themselves. If a sequence of pairs of numbers starts at address 0 how do we know when it has ended and a different sequence of numbers has started? We know the numbered pairs start at 0 but we don’t know how long they continue after that. The solution is to enter the length of the first sequence at address zero itself. It then becomes possible to start at the top of the page and read off a list of starting locations for every piece of information on that page, without fear of accidentally reading data which isn’t relevant.

The organisation of real disks and memory cards is done along these lines, and the system of addresses and references which comprise the implementations are called a file system.

(Bonus question: Imagine that one of the sequences of text buried somewhere in our piece of paper was a list of location/length pairs just like the one at address zero. The location/length of this secondary list would be mentioned by the primary one, but the pairs of numbers it contain would not be mentioned. What use would this be? Can you think of a common instance of this sublist in computer file systems?)

Disk corruption and file recovery

In order to reuse a disk people often “format” it, making a clean slate. The formatting process generally doesn’t affect the data on disk, only the contents listings which help to make sense of it. We can format our grid of paper by altering the contents listing which we store as the first sequence. It’s not difficult — all we have to do is change the number at address zero, the one that represents the length of the contents listing, to a zero. From now on, reading that sheet of paper will immediately show that this sheet contains no data!

Quick and reliable access to the text written on the vast hypothetical sheet of paper hinges on the reliability of the contents listing at the top of the page. It allows us to make sense of the lines and lines of individual letters that follow. If this gets corrupted or erased in any way, our sheet of paper is turned from a useful store into a tedious wordsearch. And as you can see with the formatting example, it takes only a tiny change to render the file listing “wrong”.

So, if through chance or misadventure your disk becomes unreadable in this way, you will not be able to read the data straight off. But it’s all still there, somewhere. The process of file recovery is one of trawling through the disk looking for interesting sequences of text, like a word search. Thankfully many files such as images or videos are organised like a file system in miniature — they contain useful header and file length info which aids identification. For example, JPEG images, which is how digital cameras commonly store their images, start all their files with a particular number. File recovery programs can trawl through the disk looking for known sequences such as this and attempting to pull useful data from the mess. In many cases it works very well.

6 responses so far

Jan 03 2010

Photo file recovery (with Linux tools)

Published by Dougal under Computing

Well, I’ve just done my good deed for the day by pulling some photographs off a corrupted memory card. Helen’s camera stopped talking to its SD card on Boxing Day and the photos from Christmas Day were assumed lost. The solution was quite painless:

  1. Copy the contents of the memory card to a file for safekeeping. The file ends up taking up as much space as the original disk does but it’s generally much nicer to take one copy and use it rather than risk further degradation if you’re worried that the memory card itself is dying.

    $ dd if=/dev/sdd of=memcard.img

    The card reader was named /dev/sdd from the viewpoint of my machine but this will no doubt depend on what kind of reader and how many devices you use. Adjust for your own circumstances. Typing dmesg into a terminal just after you’ve inserted the card in the reader will probably give you usable info — this is what I saw, in case it helps:

    [177907.297698] sd 5:0:0:1: Attached scsi generic sg4 type 0
    [177907.321601] sd 5:0:0:1: [sdd] Attached SCSI removable disk
    [177922.175874] sd 5:0:0:1: [sdd] 3994624 512-byte logical blocks: (2.04 GB/1.90 GiB)
    [177922.177838] sd 5:0:0:1: [sdd] Assuming drive cache: write through
    [177922.183593] sd 5:0:0:1: [sdd] Assuming drive cache: write through
    [177922.183608]  sdd: unknown partition table

    You can see it found the disk, named it sdd but couldn’t read any partition data from it. This is just as we expected because it got corrupted somehow.

  2. Install file recovery tools. This installs a disk recovery program and something that will trawl through disks looking for lost files. It looks like a direct port of a DOS/Windows app because the help commmand lists all CLI flags as being prefixed with a / instead of --. But it still works well.

    $ sudo aptitude install testdisk

  3. Run the newly installed photorec from the above suite. Any found files will be put into a newly-created directory called recovered. If this dir already exists it’ll create a new one with a numbered suffix rather than reusing it. I don’t know why.

    $ sudo photorec -d recovered memcard.img

    We were only expecting a few dozen photographs because the card had been emptied just before Christmas. In the end it pulled over 300 JPEGs and a video from the memory card — a nifty tool if you accidentally reformat a disk!

The Christmas photos were saved and Helen will no doubt be posting them soon. Stay tuned.

3 responses so far