Wednesday, 26 December 2012

Deleting Duplicate Files in Backups

rsync-backup (and other variants) can reduce backup size by referring to previous backups; although this can make the backup process slower and requires some fore-thought.

This script allows post-backup size reduction by detecting duplicate files in backups and making them share the same hardlink target, saving disk space.

We keep a placeholder link in MD5 folder. Each file whose MD5 file already exists in the MD5 folder is forced as a link to that MD5 file. Otherwise we link the file to create that MD5 file.

mkdir -p MD5
find . -path ./MD5 -prune -o -type f | xargs md5sum  | while read md5 file
do if test -f "MD5/$md5"
   then ln -f "MD5/$md5" "$file"
   else ln "$file" "MD5/$md5"
   echo "$md5 $file"

Because we keep an MD5 directory we don't need the md5 list to be sorted and we can re-run the script later on a smaller disk subset without needing to refer to the full MD5 list.

We can also easily examine the MD5 directory to see how many copies of a specific file exist and how much disk space is saved.

Any files in MD5 directory with only 1 link have been deleted from the normal file system tree and could also be deleted... but serve as a backup-backup!

Friday, 7 December 2012

Media Buttons on Mint 14 Nadia

Sadly keyboard multi-media control buttons still have no effect on Mint 14 when logged in using the Gnome2 fork Mate desktop.

Gladly, Matteo Italia has written a short python script to convert the DBUS events into MPRIS2 events.

Start the script on login and media keys work! Thanks Matteo

#!/usr/bin/env python

Created on 30.05.2012

@author: Matteo Italia <>

import dbus
import dbus.mainloop.glib
import gobject

app_name = 'mmkeys-mate2mpris2'

MediaKeysObjName = 'org.mate.SettingsDaemon'
MediaKeysObjectPath = '/org/mate/SettingsDaemon/MediaKeys'
MediaKeysInterface = 'org.mate.SettingsDaemon.MediaKeys'

MPRIS2Prefix = 'org.mpris.MediaPlayer2'

ActionMappings = {
        'Play': 'PlayPause',
        'Pause': 'Pause',
        'Stop': 'Stop',
        'Next': 'Next',
        'Previous': 'Previous'}

def onMediaKeyPress(app_name, action):
    sb = dbus.SessionBus()
    # Get the compatible players
    players = [n for n in sb.list_names() if n.startswith(MPRIS2Prefix + ".") ]

    # Send them the command
    for n in players:
        # TODO: it doesn't make sense to perform the action on *all* the players!
        # find a sensible criterion to choose the "best one"
        sb.get_object(n, '/org/mpris/MediaPlayer2').__getattr__(ActionMappings[action])()

if __name__ == '__main__':

    # DBUS boilerplate
    sb = dbus.SessionBus()

    # Get the media keys notificator object
    mediaKeysObj = sb.get_object(MediaKeysObjName, MediaKeysObjectPath)

    # Register to receive media keys notifications
    mediaKeysObj.GrabMediaPlayerKeys(app_name, 0, dbus_interface=MediaKeysInterface)
    mediaKeysObj.connect_to_signal('MediaPlayerKeyPressed', onMediaKeyPress)

    # Start the main loop
    mainLoop = gobject.MainLoop()

Thursday, 15 November 2012

Discontinuous Existence

I had to laugh when I read about the discontinuous state of variables with fluid-let (on account of re-usable continuations).

It related nicely to the discontinuous existence of the planet earth as revealed in the extended trilogy, that wholly remarkable book, the Hitchhikers Guide to the Galaxy.

You can read about the discontinuities introduced with fluid-let and continuations here: but you should remember those largely friendly letters on the front of the other book: Don't Panic

I quote the key phrases here:
The extent of a dynamic binding is defined to be the time period during which the variable contains the new value. Normally this time period begins when the body is entered and ends when it is exited; on a sequential machine it is normally a contiguous time period. However, because Scheme has first-class continuations, it is possible to leave the body and then reenter it, as many times as desired. In this situation, the extent becomes non-contiguous. 
When the body is exited by invoking a continuation, the new value is saved, and the variable is set to the old value. Then, if the body is reentered by invoking a continuation, the old value is saved, and the variable is set to the new value. In addition, side effects to the variable that occur both inside and outside of body are preserved, even if continuations are used to jump in and out of body repeatedly.
I'm going to have fun with fluid-let but I just wonder about the hackiness that went into implementing that, and is (I suspect) related to dynamic-unwind.

Monday, 24 September 2012

Latin1 to utf-8 without iconv

I recently helped someone convert latin1 text to utf-8 on a minimal system with no access to iconv.

A bash script had a latin1 field and needed to encode it to utf-8.

Fortunately, latin-1 only has 256 characters and only the top 128 are special, and (not that it makes any difference) most of those are the same.

The minimal system had busybox od command, so I decided to convert the variable to a numeric octal stream, like this:

$ read FIELD
Hello everybody I am the thing

Which can be converted to octal like this

$ echo "$FIELD" | od -b
0000000 110 145 154 154 157 040 145 166 145 162 171 142 157 144 171 040
0000020 111 040 141 155 040 164 150 145 040 164 150 151 156 147 012

and then strip to just the octal character values preceded by a space

echo "$FIELD" | od -b | sed -e 's/[^ ]*//;s/ *$//' 
 110 145 154 154 157 040 145 166 145 162 171 142 157 144 171 040
 111 040 141 155 040 164 150 145 040 164 150 151 156 147 012

and then join lines together

$ echo "$FIELD" | od -b | sed -e 's/[^ ]*//;s/ *$//' | tr -d $'\012'
 110 145 154 154 157 040 145 166 145 162 171 142 157 144 171 040 111 040 141 155 040 164 150 145 040 164 150 151 156 147 012

and then convert each space to $_lu_ which is a nice variable prefix

$ echo "$FIELD" | od -b | sed -e 's/[^ ]*//;s/ *$//' | tr -d $'\012' | sed -e 's/ /$_lu_/g'

Now if all those variables were defined to hold the utf-8 values, we could convert the field, like this:

$ FIELD=$(eval echo \"$(echo -n "$FIELD" | od -b | sed -e 's/[^ ]*//;s/ *$//' | tr -d $'\012' | sed -e 's/ /$_lu_/g' )\")

as a bash function:

latin1_to_utf8() {
  eval echo -n \"$( <<<"$1" od -b | sed -e 's/[^ ]*//;s/ *$//' | tr -d $'\012' | sed -e 's/ /$_lu_/g' )\"

Here is how we define those variables; this code must be run on a fully-featured box with access to iconv.

for i in `seq 1 255`
  echo "_lu_$(printf "%03o" $i)"=\$\'$( printf $( printf '\\x%x' $i ) | iconv -f latin1 -t utf-8 | od -b | sed -e 's/[^ ]*//;s/ *$//;s/ /\\/g' )\'
and the text it outputs


Will be pasted into the script that runs on the reduced environment

Friday, 7 September 2012

Recover deleted photos

In March 2007, some missionaries called around with a sad tale - they'd accidentally deleted all the photos on their memory card, could I get them back?

I quickly knocked up this short perl script to do it.

#! /usr/bin/perl
# Quick hack by Sam Liddicott: <>
# Try and look for jpeg images in a stacked file.
# Reads 512 blocks and when it finds one that starts with oxd8ff it starts a new file
# Invoke on a raw image of the card (maybe taken using rawread or rawrite) like this:
# perl < IMAGE

# or
# perl < /dev/sde

our $count=0;
our $file="/dev/null"; # use nul for dos/windows
our $buffer;

open STDOUT,'>',$file;

while (read(STDIN,$buffer,512)) {
  if ($buffer=~/^\377\330\377[^\333]/) {
    print STDERR "$file\n";
    open STDOUT,'>',$file;
  print STDOUT $buffer;

It did recover his photos.

Of course that \377\330\377 sequence was taken from /etc/magic - where else!?

Monday, 3 September 2012

The New Park

The New Park

(C) Sam Liddicott 2004

As we got near the park, my mother started to walk in the other direction, taking me with her.

This wasn't right; she had promised me that I could go to the park in the afternoon if I behaved in the morning, and I had behaved. I hadn't played with the scissors and cut the curtains, or got my shoes muddy when I played outside. I read my books quietly and put them away again, and I had eaten all my bread at lunchtime without complaining.

I had behaved, but just as we arrived at the park she started taking me somewhere else. I protested with a yell.

"Be quiet!" she said abruptly, which surprised me because my mother had been in a good mood when we set out. I was hoping we could stay longer at the park because it was sunny, and mum could sit on the bench and read her book.

"I want to go to the park, you said I could..." - it was worth a try, but she didn't seem to be in the mood. Why had she changed so suddenly?

I looked behind me towards the park as my mother dragged me along. There were some boys standing by the the red bus shelter in a group as they often did. I'd seen them before so I think they live nearby. One of them is called Harry. Maybe they were waiting to catch a bus to see their grandma, like we do with when dad has to stay at work late.

My mother dragged me on, still hurrying. I twisted my head as far as I could to see behind me. There was broken glass about the pavement. That was not unusual, sometimes the park had glass in it from broken bottles. I saw a broken window once. My big cousin Jamie kicked his leather football through it. He was not supposed to use his leather football in the garden. His dad had told him again and again.

Just as my mother dragged me round the corner I noticed that the side of bus shelter was broken. That must be where the glass had come from. It looked as if someone had spilt red paint on it.

“Where are we going, mum?” I asked.

“We're going to a different park today,” she said.

That was good news, and I began to walk a little faster. I wondered if the new park would have the same sort of swings as the old one; but best of all, on the way, I saw an ambulance. It had its lights flashing and it made the noise that makes the cars get out of the way, but they turned those off when it went round the corner.

The new park was bigger than the old one, but it was quite far away so we came home on the bus.
On the way home I asked my mother where she thought the ambulance went. She said she expected it had gone to help some people who had hurt themselves.

Mum said we can go to the new park again sometimes, but not every day.



(C) Sam Liddicott 2004

Of course, he'd heard of boats. Instead of a steering wheel they had two sticks – paddle things – that you waved around in the water to tell the boat which way to go. Sort of like a steering wheel cut in half with the two halves dipping in the water. Like steering wheel – but in the water. That didn't sound too hard, he'd used steering wheels before.

The water stank of ducks, rotting leaves, rank damp bread and the sort of things that gets left behind by ducks that eat too much rank damp bread thats been floating around in rotting leaves. And it was wet – raining that is. He had no hat and so tried to make do with putting his hands over his head and wriggling down further into the bushes by the boat house. Looking up in the dusk light, he noticed with resigned pessimism that he was right below the eaves, which, without guttering, were dripping a regular beat upon him. There had been a guttering. He looked at it beneath his feet, wondering if it would be of any use for anything.

There were no boats in the water. This escaped him for quite some time, and he cursed quietly as he realised. First, panic that he was in the wrong place; that maybe this wasn't the boat house on the lake by the south entrance as the map had shown.  Then he fetched the crumpled map out of his pocket and squinted at in in the halflight, parting the bushes for more light to be able to see clearly.  This was the place, and the boat house was marked on the map, and there was the island in the middle of the lake.  Boat house – what a funny name, he thought to himself. It was probably called a boat house because it was right by the place they kept the boats.

His legs were beginning to ache from too much crouching in the low bushes, and shuffling his feet only served to make him lose his balance and sit down in the mud.  He noticed (as he turned around) a litter bin close by. There was something moving in the bin, he could tell by the noise. Probably a rat. Then he remembered about rats in the water. It would be hard to tell if rats had weed in this water, it was so dirty anyway.

These hardships recalled his purpose to mind.  Soon he'd be on the island, a new home of his own with no-one, no-one, to bother him; and a big bonfire to dry him out, warm him up and cook his dinner. A tin of scotch broth! Later he'd trap rabbits and things, but that took time, of course. The idea of a fire was comforting. He felt in his pockets for his cigarette lighter - just a flame to wam his hands while he waited - but it was missing; his mother had been through his pockets again.

Then a clap of thunder broke out and the rain increased to a torrent. So much for “overcast” he thought as he trudged back home. At least the rain would wash the mud off his trousers.

Mi Charango

I wrote this in 2004 as part of my coursework

Mi Charango

© 2004 Sam Liddicott

Jorge awoke as the distant sound of the festival music leaked through his broken shutters to accompany the sunlight already spilling over the strings of the charango hanging by his bed. He did not look at it, it mocked him, but he picked it up with a care and tenderness that contradicted his countenance, and began to play.

In playing, he found no comfort. No familiar melodies could move his heart, he felt no joy from the lively dance tunes and became all the more melancholy with each love song. Finally, he found himself playing something unfamiliar, but though each phrase was new, his fingers drew from the strings a gentle melody whose notes fell with a comforting reassurance and familiarity that soothed his soul. He had heard it somewhere before.

A clatter of feet on the stairs erupted through the door of his room bringing him the greetings of a small crowd.

"And how is our maestro today?" – this was not a question.

"Today your music will honour us all."

"Why have you not called at my shop? I have brought for you a suit here that will show everyone from miles around what fine clothes we folk wear!"

"And when you are dressed you must call in to see me. I have a special table laid for you – outside; I will prepare for you a meal that will truly inspire your playing. And my sister, – she will serve you"

"And here is a fine hat for you. When people look at the man who plays the best I want them to see he knows where to go for an excellent hat!"

Jorge said nothing. The little crowd paused. The foremost looked at Jorge and dimly perceiving his mood decided that some encouragement was needed.

"Can't you see he is resting?", he chastised the small crowd, and pushed and hustled them down the stairs, but did not immediately descend himself:

"Don't be concerned, my friend," he entreated gently, “remember, even though you compete against the villages across the lake, you are surrounded by friends!”

Jorge just shrugged, and wearing his new suit, went to join his band of supporters for breakfast.

A special table had been placed in the street for all to see, and covered in a bright white cloth, which already his attendees had stained with wine. To keep the ascending sun from his head, Jorge put on his new hat, the action receiving rapturous acclaim from its giver.

The young lady serving the table paid particular attention to Jorge, though not to take his order, for a special dish was already being prepared in his honour.

Jorge looked at his supporters seated around the table, who, while waiting, contended to give the best account of the forthcoming victory. He wondered when they had first become friends.

His mind slipped back seven years ago:

He was hiding in the framework under the platform. The music from the performers did not drown out the cries of his tormentors as they sought him out, having already spent their money on the first day of the festival. Knowing that he would be found near the music their search was bringing them closer to his hiding place, and although the framework raised him from the ground and thus from casual inspection he knew he would be found before long.


“Shhh! He's thinking! Can't you see he's thinking?”

“I was only going to ask what it was he was playing when we came to rouse him!”

“Yes, Jorge, what were you playing this morning?”

“It's his surprise piece of course! He will play it today and win the competition and show those, those, ... across the lake that real music belongs here!”

“I only wanted to know its name?”

“Yes, Jorge, what was is its name?”

Jorge looked across the table. That tune he had been playing when they disturbed him certainly had the power captivate all who heard it. It was music worthy of a great master. And then he remembered.

It was music from a great master, from the man whose charango lay on the table beside him. Memories so unexpectedly freed raced back into to his mind:

With surprise, the face that showed itself beneath the platform belonged not to his tormentors, but to an old man. Recognizing the situation he immediately withdrew his head and began to scold the young boys for playing so noisily and sent them play away from the music.

The same face returned and begged him to come out, but Jorge refused, "I can hear the music better here", he said.

"You like music?" the old man asked.

Jorge nodded.

"Can you play?" enquired the man.

Jorge shook his head. "I could", he said, "if.. if..."

"Would you like to play this?", asked the face, holding down a charango.

Jorge opened his eyes and looked at the same charango, now in his hands. His fingers alternately strummed and plucked the strings as his mind recalled his first lessons.

"You have a great gift for music," said the man as Jorge, without being taught directly, began to select chords to play against the simple melodies taught him by this friendly stranger.

"If I had a son,” said the old man, “I would teach him the song of our family. But I am old and have no children. Shall I play it to you?"

Jorge, listened enthralled. He had not known such power in music. The melody and rhythm wrapped him in sunlight and danced him over the hills. In a moment he was bathed in the cool stream of the hillside, and in another moment he was soaring in the sky, his loneliness gone, giving way to the joy known only to songbirds.

"I shall play this tomorrow," said the old man, "I have no son, so I shall play for my countrymen, and so win the competition."

Jorge's breakfast was served carefully and ostentatiously by someone's beautiful sister but he didn't notice.

By the third day Jorge could play the piece "Mi Charango" with tolerable skill and his new friend and mentor proposed that he play this as a beginner solo musician before the final competition at the festival. He would lend his instrument to Jorge, and afterwards himself compete to take the seven year prize, and be the pride of his countrymen.

Jorge basked in the memory of the joy he had then felt, more vivid and more brief than life itself. He stepped out onto the platform.

“Jorge, what are you doing?”

“I told you, he's thinking. Let him think!”

He stepped out onto the platform. Beneath the crowd of hats, children running among the crowd, mothers looking after babies, men talking to each other and paying no attention to their wives or babies, children chattering and laughing. And laughing – at him!

“Jorge wants to play, look at him.“

“He doesn't even know how!”

Defiantly, Jorge raised his hand to play, but somehow – either he held it wrong, or started on the wrong strings – he played something that bore just enough similarity to “Mi Charango” to be recognizable.

The laughter increased. Men stopped talking, and women turned away from their children to watch the spectacle. Jorge made another attempt.

"Get off!" he hissed his father, "you have never played music in your life before!" and the crowd laughed even harder.

The old man stepped forward to offer encouragement, but blinded by his tears and fright Jorge pushed past him and ran down the steps and through the taunts of his enemies.

"Where have you been Jorge?" they cried, "We've been looking for you!"

"Give me that!", they said, pointing at the charango, "let us play!"

Running on, Jorge made his way through the village and into the corn where he lay, sobbing. After about an hour he began to play to himself. First "Mi Charango" as he had meant to play it, and then picking out the various melodies that came into his mind, as his mother had sung them years ago. He played on into the dusk, and it was only when the evening coolness turned to chill that he remembered competition and who the charango really belonged to.

With every step home Jorge felt a rod beat his back. Finding his father drunk and asleep he hid the charango under his bed. The next day nothing was said, and so for years he secretly practised the charango after his work, and when his father died he practised it openly.

Jorge looked at the charango in his hands. It wasn't his. It belonged to a man across the lake. An old man who had taught him to play.

Jorge sprang to his feet, and smiled at around the table.

“He's ready!”

“I knew he'd be all right!”

“You all worried for nothing!”

"When he wins, I shall win enough money to by a team of mules."

With the calmness and serenity of seven years Jorge waited by the platform until his turn, heedless of all questions and encouragement. His turn was to be the last performance before the festival broke up for another seven years. This time the crowd was hushed. His fame was known. He stepped towards the front of the platform, found what he sought, and began to play.

As he finished, no-one moved, all ears straining for the final imperceptible echoes from the hills. Jorge broke the silence. "I play for my new home" and ignoring the enquiring calls from the audience, he descended the steps, and passed by his newly generous friends and stopped to embrace a tired old man. That evening he returned across the lake to his new home, as son to a new mother and new father – the only friend he'd ever known.

The Handkerchiefs

I wrote this in 2004

The Handkerchiefs

© 2004 Sam Liddicott

Dear June,
                   you see, I know your name,
your handkerchief was spelt the same,
the one I kept, when in the park,
you dropped it on a summer walk.

  You haven't dropped one since, all year!
  The truth most likely is, I fear
  You quite forgot to buy some more
  To drop for me upon the floor

So please accept this gift from me
Some silken handkerchiefs times three
And should you now be quite sure who
To drop them for - I'm wearing blue

Jon, The Brainworker

Jon, The Brainworker

© 2004 Sam Liddicott

Jon opened one eye. On the opposite wall there were the shadows of the clutter on the window sill. The pile of plates cast a shadow like some kind of tree with the past weeks knives and forks looking like so many spindly branches as if more growth was too much effort for such a shadow as this. As the sunlight passed through a half full glass of dusty drink it cast a bright pattern on the wall with a shimmering beauty caused through the efforts of heavy traffic outside.

Jon noticed none of this. He saw nothing unexpected, nothing to require further examination of his surroundings. His eye closed.

He rolled over and briefly considered the chances of finding something clean to wear. A moments thought concluded that it would not be worth the effort of getting out of bed. It seemed to be late evening. If he spend long enough thinking, the laundrette would be closed – that was some consolation.

The shadows of the plates and drinks in the reddening light seemed to wake some recollection in his empty mind. Food! If the laundrette was closed, so was the shop. John stirred. If only he could see the clock at the other side of the room. He smirked when he remembered the sound it made when it hit the wall – when had that been?

He rolled out of bed onto his knees and struggled up. He gathered nearby clothes onto his bed-sheet and checked the pockets for enough change for a wash and dry. He would do without the powder if necessary, but not the dry. Nice, warm clothes, warm sheets to snuggle down in. He pulled the corners of the sheet into a bundle and shuffled down the steps.

The laundry and the shop had been closed for an hour, but on the way back an old lady gave him a pound.

Jon didn't put the sheet back on the bed, it didn't seem worth it.

Tuesday, 14 August 2012

No Father

No Father

I've been called father many times
  in family courts - by judges twice my age
but never daddy.

Nor I, my sons nor daughters know what's lost
  except a few; those I fear - they know to condemn me,
now they have a daddy.

But there is one; whose judgement
  sinks me down to hell, each time I dare recall:
he had a daddy-

and so my wretched heart,
  hardened well against my mothers tears and soft entreaties
my heart which never loved,

can never love nor soften now
  lest it should know and die, under that awful weight:
his mother's bitter tears.

The Chief of Judges knows I am no father
  having never made a home, nor yet a family
and one - not mine - I have destroyed.

© 2010 Sam Liddicott

I had wanted to write a modern lads version of Ella Wheeler Wilcox's The Coquette which considers the female perspective.

The poem is the looking back of a man on his life.

v1 references his early careless attitude - leaving a bite of care at the end

v2 tries to pretend that the victims of a stunted childhood can't know; so un-accused harm is no harm

v3 he has to stop pretending and be honest, which he is in v6 after his looking back in v4 and v5

In v4 "which never loved" acknowledges that all his relationships were selfish

 v5 in later life, finding a shortage of people ready to read more into his actions than he ever meant, and a shortage of people generally he began to prey on married women - and got stripped of his final illusion, that he brought any happiness to anyone at all. He can no longer imagine or pretend that fond memories of him are to be found anywhere - he knows now that in what he saw as a carefree life, he was the worm which consumes

v6 he knows his state. He sees that he has wasted all opportunity to be of worth or loved by others.

He cannot find his value without also knowing what he has destroyed and the pain is too much, so he cannot move on. His only hope is mercy which he never had but that can't be effective until he accepts his state, which he cannot.

Monday, 13 August 2012

The Witness

© 2012 Sam Liddicott

The assistant administrator was roaming the gardens looking for witnesses, so I thought I had better oblige. I was taken to an interview room that seemed to be serving as a sort of pre-filing room (though it may have been the other way around).

The assistant offered to fetch me a cup of tea and his secretary quickly returned with a warm milky concoction with too much sugar which must have been prepared for someone else earlier. There was a little lipstick around the rim so I suspected it had been used. I did not touch it.

Paying no attention, the assistant flipped open a pad and retrieved a silver ball point pen from his inside pocket. It was then that I realised he was only the assistant administrator. The administrator had a gold pen.

"I will take down your statement" he declared with as little interest as he could muster.


I gave my name



"I've never heard of you!" he said triumphantly (and little too confidently, I thought).

"I write fiction." I countered, which seemed to satisfy him. I mentioned politely that had never heard of him, but he did not give me his name.


"Flat 6, 24 Bolsanger Place, Prate"

"Surely you mean Bolsanger Square, Prest?" glared the assistant. Bolsanger Square was in a run down district which he perhaps felt was more suited to an author he had never heard of.

"If you prefer" I responded. I didn't want to make a big deal out of it.

I watched as the assistant administrator struggled with the spelling of Bolsanger. In a country with a complicated history, a few obscure names always remain to point the way for the historians.

"I could write it for you?" I offered.

The assistant handed me the pad. "Please press firmly" he directed, offering me his pen. He paused for a moment and thought the better of it, calling for the secretary to fetch me a pen. It took some moments to find one that worked. At last a working pen was found, although there was a little lipstick - as a sort of garnish around the thoughtful little tooth marks and the end. I tried not to notice.

"Try to remember to press firmly" urged the assistant, quite unnecessarily I thought. But I didn't want to cause trouble, so I went back re-writing the entire address "Flat 6, 24 Bolsanger Place, Prate" very firmly.

I returned the pad to the assistant. He noted my disagreement with his opinion of my address, but said nothing.

"What was the first thing you observed?" he demanded?

I thought for a moment. "When I was five," I said, "I recall a hanging decoration in my bedroom window. They were birds, I don't recall which."

"After the noise!" he cried in exasperation.

"There was no noise," I said, "we lived in the country you see, and although there was a horse that rather suffered from indigestion..."

The assistant sighed at me as if I were being troublesome on purpose. He began to exert his professional patience. I could see why he had been made an official.

"The noise which startled the gardener," he said, "on which you are here to make a statement - causing him to..."

I looked at him. Why hadn't he said so before?

"Yes, the noise," I said, "that noise. Causing the gardener to..." - I paused.

"To lose control of the automatic mower!" cried the assistant in an pained voice.  (I could see why he was only an assistant).

"Yes, yes!" I said (why hadn't he mentioned this before?) "Causing him to loose control of the mower!" Now I had something to go on. "Rising from the seat of the automatic mower..."

"Not while it was still moving?" queried the assistant.

"Oh yes," I replied, "it was still moving - he was startled, you see?"

The assistant nodded and started making notes. I paused and after he had caught up he looked at me expectantly.

"He stood up," I repeated, "and struck his head upon a tree branch as the mower passed beneath it"

"Go on" signalled the assistant.

"This knocked him from his seat"

"You said he was standing!" cautioned the assistant. I could see he would soon hold a gold pen in his pocket.

"Yes yes," I said, "he was standing, and knocked from the mower onto the ground." I could see the excitement in his eyes as he continued with his notes. "The mower continued its' direction," - here the assistant looked at me doubtfully - "because the gardeners shoe had caught between the pedal and the steering rod."

"The gardeners foot was no longer in the shoe." I added, seeing the look of worry on the assistants face.

"Of course." he said in a relived tone, "the mower continued on its course"

"And rebounded off the mayors leg." I had meant to say the statue of the mayor before I had been distracted by the assistants interruption, and the assistant had got as far as writing down "the mayors leg" before I realised my error, and so could not correct myself.

"What was the mayor doing there?" the assistant queried.

"How should I know? He doesn't confide in me," I responded, "and never has". At this the assistant regarded me with a look of prematurely terminated respect.

"This is quite serious." the assistant pronounced after some thought. "Go on. The mayor was not injured?"

"The mayor was not injured," I assured, "the mower merely glanced off his leg"

"How could it do that," asked the assistant, "if it were headed towards him? It would surely cause some serious injury from the blades."

I rather wished he would make his mind up. First he wants an uninjured mayor and then he wants the mayor to suffer a some serious injury inflicted by an uncontrolled automatic cutting machine. It was difficult to satisfy him on account of the mayor no longer standing on a stone pedastal, but I had the answer. "It was because of the knee length riding boots." I said.

"Riding boots!" - this clearly shocked the assistant. "The mayor does not ride! He cannot ride - and will not, ever since the incident - I was present - at which he..."

Here I interrupted. I was not interested in the incident at which the assistant administrator was present, and his promptings were beginning to prove more than a little difficult. "The mayor does not confide in me!" I repeated, "How should I know why he was wearing knee length riding boots." I paused. "It may have been for the photograph"

"Photograph?" the assistant queried with interest.

"There was a photographer present. Did I not mention that?" I asked.

"You did not" responded the assistant with slight annoyance, and resumed taking notes more fervently.

"He was from a national newspaper," I continued, "at least I think he may have been. It's hard to tell."

The assistant paled slightly, and his writing continued at a furious pace. "Who else was there?" he asked.

"The mayors wife," I said, and after some thought, "and I think the regional commissioner." but after seeing the effect this last statement had on the assistant I quickly added "but I could not be sure about that. He may have only been the deputy regional commissioner after all". (One doesn't want to over do things with an assistant administrator).

"What occurred next?" prompted the assistant once he had caught up in the notes.  "After the mower..." here he paused to read the notes "rebounded from the mayors riding boots"

"He said: You silly ass!" I replied.

"The regional commissioner called the mayor a silly ass..." the assistant repeated to himself as he wrote.

"No no," I said, "you have it wrong. The mayor is the one that said: You silly ass!"

"What? To the regional commissioner?" asked the assistant in a horrified voice, hands raised.

"No, to the gardener-" I replied, "but he was behind the commissioner, and so the commissioner thought the mayor was talking to him and took great offence."

"The regional commissioner... This is very serious indeed" the assistant said again. I could see he was struggling to control his emotion.

"Yes," I said, "the commissioner thought it was very serious too. He said: This is very serious, do you not realise I have a position of highest authority?"

"Did he? Is that what he said?" asked the assistant.

I assured him that it was. "What else could he say?" I asked. The assistant agreed.

When he had caught up again, he asked: "How did the mayor respond?"

"He was very embarrassed, when he realised the mistake. He said: No, no, not you!" The assistant wrote this down.

"And the regional commissioner?" - he paused, unable to go on.

"The commissioner," I added, "said: I do, I assure you, I report directly to the national policy office. You see he thought the mayor was questioning his authority..." I explained.

The assistant paused with his hands over his eyes and took a deep breath. "And what did the mayor do?"

"He apologised in a most humble manner, explaining that he was referring to the gardener, on account of being struck in the sides of the leg by the rotating blades of an automatic mowing machine."

"How did the regional commissioner take this?"

"He accepted the explanation," I said, "he was very moved by it. He laughed until tears came to his eyes, and he slapped the mayor on the back. The commissioner is known for his sense of humour, is he not?" I asked the assistant.

The assistant said that he thought he was - but without conviction. "What of the mower?" he asked.

"It rebounded from the leg of the mayor"

"Yes yes," interrupted the assistant, "what then?"

I resented the interruption, so I continued as fast as I could and waited for the assistant to catch up. "It carved a path through the main memorial flower bed" (I had actually seen the path which it had taken) "and continued through the annual picnic for sick orphans and then out into the road where it caused a minor accident or two, one of which involved an empty green grocers cart before coming to a halt outside the post office. The gardener was found to be unhurt after being revived by two or three restorative drinks."

After reviewing the notes, the assistant asked "Did you notice the source of the noise that startled the gardener?".

The waiting for the assistant to catch up had restored my calm, so I went on: "I think it was the guns".

"The guns!" exclaimed the assistant. He had stopped writing so I provided more information to stimulate him to continue.

"They were directed at the gardener," I responded with magnificent aplomb. "when the were fired."

The assistant sat back in his seat and stared at me. I looked towards the pad of paper and he quickly resumed his writing.

"They were firing blanks" I responded - before he could asked his next question - "for the photograph."

The assistant looked at me with reluctantly diminished excitement, and continued writing. I think I detected a glint of admiration in his expression.

"In summary," said the assistant, once he had finished his notes, "While the regional commissioner, the mayor and his wife were firing guns for a photograph in front of the city hall, they startled the gardener who fell from the municipal automatic mowing machine which struck the mayor in the leg causing no injury and the regional commissioner found the whole thing very funny."

I said that he had got the gist of it correctly but that I thought that the mayors wife was not carrying a gun. The assistant administrator seemed very pleased, and I signed the statement with great satisfaction.

The administrator then entered the room carrying his gold pen.  "Good, good," he said, looking over at the assistant, "we have found two other witnesses who are also giving statements about the ...".

I immediately arose and tore the page from off the top of the pad and fled the room as quickly as I could.

Why hadn't they told me they had found other witnesses? I would not have been so anxious to help. I used my statement rather unsuccessfully to light my pipe before leaving by the back gates.

It was only later that I learned that the witness pad was in triplicate, and that I had only torn out the top copy. As I had been so helpful to override the assistant with my correct address they were pleased to find and inform me that by signing the statement the charges were raised from the nuisance of wasting official time, to making a false statement - which I think is rather unfair as I did warn them from the start that I was an author.

I heard later that the gardener had been drinking a concoction that he brews in an old petrol cannister, and when ordered to immediately remove the recently renewed memorial flowerbed in preparation for an inspection by the new regional administrator he was so inebriated that the lawn mower was his tool of choice.

Thursday, 7 June 2012

Bash, and process termination reports

Bash is not supposed to report on process termination unless job control is turned on - and it isn't when running scripts.

Yet it will report on process termination if a background process which is not the last background process is terminated uncleanly:

This wrongly gives a terminated report:
bash -c 'trap "sleep 1" EXIT ; ( sleep 3 & wait $! ; kill -15 -$$ ) & X=$( sleep 4 )'

This fixes it by using setsid:
bash -c 'trap "sleep 1" EXIT ; ( sleep 3 & wait $! ; exec setsid bash -c "kill -15 -$$" ) & X=$( sleep 4 )'

This breaks it by using &&:
bash -c 'trap "sleep 1" EXIT ; : && ( sleep 3 & wait $! ; exec setsid bash -c "kill -15 -$$" ) & X=$( sleep 4 )'

The answer is to use if/then/fi and not &&:
bash -c 'trap "sleep 1" EXIT ; if : ; then ( sleep 3 & wait $! ; exec setsid bash -c "kill -15 -$$" ) & fi ; X=$( sleep 4 )'

Thursday, 10 May 2012

Why we have a recession:

When you borrow money to spend, you are spending tomorrows money today and agreeing that you will therefore not be able to spend it tomorrow.

It's now tomorrow.

Today's money was spent by the labour government along with yesterdays money.

While cutting back spending won't "recover the economy" right now, there isn't actually much left to spend. Borrowing even more will just rob our children of even more of their future.

If you think spending is important to maintain the economy, then don't spend tomorrows money today - or you can expect a bleak tomorrow.

Did I mention that it is tomorrow?

Labour have been very generous to you and your friends by maxing out your credit card.

Tuesday, 8 May 2012

Dolphins and Discrimination

I wrote this allegory to capture observations on discrimination that would not be safe to utter plainly. There are at least three lessons here.

Dolphins - an allegory on discrimination

(C) Sam Liddicott 2012

There were some Dolphins on the windward side of an Island. Like most dolphins, they sometimes behaved aggressively toward each-other.

There were some Dolphins on the leeward side of the Island. Like most dolphins, they sometimes behaved aggressively toward each-other.

In time, some of the windward dolphins became particularly aggressive towards the leeward Dolphins, for no other reason than that they were leeward dolphins, and often hunted them out, or ganged up to attack lone dolphins. This became a particular concern for the leeward Dolphins who began to question their own aggressiveness between each-other.

In time, the attacks of the windward dolphins became so aggressive that the leeward dolphins would often be severely wounded or killed. Sometimes the leeward Dolphins would respond with violent attacks of their own but these did little to change the persistent behaviour of some of the windward dolphins.

When the continual violence of the windward dolphins became too much to bear, the great dolphin sent an Orca to deliver this message:

That although they were all brothers, the windward dolphins would in future be reborn as leeward dolphins, both to experience the effects of their behaviour and perhaps in time to temper the violence of the windward dolphins to their own reborn brothers.

The leeward dolphins were horrified when they heard this. They idea of living with and sharing life and love with those who had so badly treated them - and not be able to recognise them - was repugnant to them and made light of their injuries (they said).

Don't worry, said the orca, they will continue to behave violently towards those who do not appear the same as themselves, and so you will know who they are. Don't hate them, or you may become like them; love them because they will also protect you from the windward dolphins.

I count at least three morals in this tale.

Stop facebook intercepting your links

Are you are fed up with posting links to face book (guardian, yahoo, etc) and find that when your friends follow the link they are forced to accept intrusive facebook apps in order to read the link?

then you may want to prefix your link with this before pasting into facebook:

to effectively paste a link like this:

When your facebook users click on the link, instead of being forced to accept the oppresive Yahoo facebook app, they will see this:

Which will allow them to follow on to the link in a civilised fashion.

NOTE: When adding your link on to the end of make sure you include the http:// part of the link you are copying.

Sunday, 8 April 2012

Gather Ye Chocolates

Another in my series of classic poetry re-worked for modern times.

To the Young Ladies, To Take Much Chocolate At The Easter Egg Hunt

by Sam Liddicott

Gather the choc'lates a'fore it's May.
    Old timers still a-trying :
For easter eggs that melt to-day
    To-morrow will be frying

The baking heat of heaven, the sun
    The hotter it is getting
The sooner chocolate starts to run
    And spoil your dress, upsetting

That aged beast which at the first,
    Would tend your clothes and laundry ;
But having over eat the, worst
    stains leave you in a qaundry.

The bean of cocoa speed your time,
    And while ye may go carry :
For having lost your chocolate time
    You may be very sorry.

The original, below, makes valid points, but perhaps intersects less with the mind of modern woman than my revision.


by Robert Herrick

GATHER ye rosebuds while ye may,
    Old time is still a-flying :
And this same flower that smiles to-day
    To-morrow will be dying.

The glorious lamp of heaven, the sun,
    The higher he's a-getting,
The sooner will his race be run,
    And nearer he's to setting.

That age is best which is the first,
    When youth and blood are warmer ;
But being spent, the worse, and worst
    Times still succeed the former.

Then be not coy, but use your time,
    And while ye may go marry :
For having lost but once your prime
    You may for ever tarry.

Tuesday, 20 March 2012

local variables are great

In the last few months I have really come to appreciate what perl and bash local variables really are. And it took a better understanding of list/scheme/tex/texmacs, and a couple of years to think about it.

And my bash scripts are more and more lisp-like using extreme parallelisations and local variables.

This bash function takes the name of a variable as a first argument and returns in this argument a free file descriptor number, rather like C's fopen(). The second argument can be the lowest file descriptor to choose from, but it defaults to the current value of the variable whose name is given in the first argument. The third argument is the highest value to work to, and defaults to 254.

The shell function closes stderr as it uses stderr for fdup to test if a destructor is in use. Ironically to close stderr, bash has to save it in another file descriptor - but internally bash can find one that is free, something that this function is written to do! But this means that this function will never allocate the descriptor in temporary use to save stderr even though that descriptor will be free when this function exits. Thus while this function can allocate a free descriptor it may miss some that were free. C'est la vie.

fd_allocate() {
  set "$1" "${2:-${!1:-3}}" "${3:-254}"

  printf -v "$1" ""
  while test "$2" -le "$3"
    if ! : 2>&"$2"
    then printf -v "$1" "%s" "$2"
    set "$1" "$(( $2 + 1 ))" "$3"
  return 1
} 2>&-

This function is used for high parallelisation like this:

do_something() {
  local fd=4 things
  for thing in "$@"
    if fd_allocate fd && exec 3< <( something "$thing" )
    then eval "exec $fd<&3 3<&-"
    else # spawn failed, do foreground instead
         echo "Output for $thing:"
         something "$thing"

The results (stdout) can then be reaped like this ($? cannot be obtained, if you want it, emit it to stdout):

  local output
  for fd in ${!things[@]}
     thing = ${!things[$fd]}
     read -d "" -u $fd output
     echo "Output for $thing: $output"

Of course cat </dev/fd/$fd might do instead of read

However, all these uses of local are abusive and ideally I do want scoped variables in bash too. In fact fd_allocate was specially written to not use any local variables but to re-write it's parameters instead.

But the point is I can reap the parallised results in the right local environment without having to pass parameters. This becomes more useful as I factor my code which is written using literate programming techniques; and so I now longer write linear functions but instead compose fragments of code, and of course in this context, the environment of local or scoped variables becomes an implicit API, and so this is the situation in which I find myself understanding the power of local variables or the environment.

Local variables are visible to all subsequently called functions and so reduce the burden to pass a lot of parameters (something which C++ tries to ameliorate with default parameters) or objects of parameter sets.

Local variables are part of the environment exposed to called functions.

C could never really have local variables.

Tuesday, 6 March 2012

Update Acer Aspire Bios

The readme file for the Acer Aspire BIOS update requires that FLASHIT.EXE and the BIOS file are copied to a dos-bootable disk.

Well... the Acer Aspire netbook does not have a floppy drive, and who these days can conveniently get a boot image working off USB? I can, but it's too much hassle (it involves loading a file system image as a ramdisk, blah blah boring boring).

But I find that there is a secret BIOS mode that let's the netbook flash it's own BIOS!

I quote for posterity's sake:
First format an USB stick with FAT.

Download the latest BIOS, and put both FLASHIT.EXE and the BIOS file in the root directory of the stick. Rename the BIOS file to ZG5IA32.FD, that's important. Do not remove the USB stick.

Turn the AA1 off, make sure both battery and AC adapter are connected. Press Fn+Esc, keep it pressed and press the power button to turn the AA1 on. Release Fn+Esc after a few seconds, the power button will be blinking. Press the power button once. The AA1 will now initiate the BIOS flash, do not interrupt it under any circumstances. After a while the power button will stop blinking, and the AA1 will reboot shortly after. Wait patiently.

The BIOS has been flashed and all settings reset to default.

If for some reason you made a mistake during the procedure and it doesn't reboot by itself wait 5 minutes before turning it off, just to be safe that it isn't still flashing the BIOS.
Also, thanks to

Thursday, 2 February 2012

HP Displayport Adaptor on Mint or Ubuntu

[Note: updated information here]

I post a correction on these notes: which over-specify /sys (as well as hard-wiring it) as well as bConfigurationValue.

#! /bin/bash

if [ -e "$1"/device/bConfigurationValue ]; then
  echo 1 > "$1"/device/bConfigurationValue

if [ -e "$1"/bConfigurationValue ]; then
  echo 1 > "$1"/bConfigurationValue


# DisplayLink devices always have the active configuration on configuration #1
SYSFS{idVendor}=="17e9", SYSFS{bConfigurationValue}=="2", RUN+="/usr/bin/dlconfig %S%p"

These cause the VGA adaptor to be intialized properly on each insert.