Archive for the 'Everyday Life' Category

An Easter Birdy

Saturday, April 3rd, 2010

Well it was time.

After about 2000 miles on the Dahon Vitesse D7, it was time to get a new bike. The Dahon had it’s fair share of problems. The frame split where the seat post frame tube met the cross tube – luckily within warranty, so a new frame was fitted. The wheels on the Dahon where very poor.  On average a spoke broke on the rear wheel every three to four weeks.  Eventually I had the rear wheel rebuilt with new spokes.

Of course there was all the usual stuff with chains wearing and the like… but that is normal for a bike that does 8 miles a day four day’s a week. So the Dahon is being retired to ’second bike’ for use in emergencies.

So, what about the new bike?

I am now a proud owner of a Birdy Touring bike.

This bike has 24 gears, nicely distributed from very low (hill climbing will be so much easier!) to pretty high. One of the things that I found with the Dahon was that there was not enough high end in the gears, and I was quickly at top speed, with a feeling that I could have gone further. The new bike has by contrast a massive high end in the gears. I topped 42 mph on the flat – with a tail wind!

It has full suspension using a combination of elastomer (rear) and spring/elastomer (front). And on a canal tow-path trip which varied from very uneven brick to muddy pools, it coped well.

It is fully kitted out with mudguards and Pannier racks (front and back).

And of course it folds.

Library offers fee tea bag

Saturday, February 27th, 2010

No really.

I went to collect a book I had reserved at my local Wolverhampton Library, and as I had the item issued, I was offered a free tea bag.

Bemused; politely; I said no, thank you, I don’t drink tea.

P.S. Wolverhampton Libraries, why can’t I reserve a book on-line if it is NOT on loan? quite often I would prefer you to send the book to my local library if it is in the Central Library on the shelf. And I know your system could do it!

A little bash deployment assistant

Saturday, February 6th, 2010

I wanted to copy some files from one directory to another while I am working on my wordpress blog-in-blog plugin.  Basically I needed to copy the files checked out from svn, from the working directory, to the root of the web directory on my local machine.

Feature requirements:

  • Should only move a file if it has been edited. (we assume that the filesize will have changed by at least 1 byte!)
  • Should not just sit there copying all the time.
  • Should find out about all files in the specified directory.
  • Should report when it updated the file and which file was updated
  • First run should copy all files to the destination directory. (assumes I have updated my working copy from svn)

So after several attempts, here is a more polished version which stores the filename and the last size of the file in a ‘bash hash’. OK bash doesn’t have hashes (mores the pity) but reading around on the web I found this post with a comment from Scott Mcdermott which does the job nicely (once I had stripped offending characters from the file names).

So here is the full code of the deployment assistant:

#!/bin/bash
# script to deploy code from SOURCEDIR to DELIVERDIR 

PROJECTNAME="blog-in-blog"
SOURCEDIR=blog-in-blog/trunk
DELIVERDIR=/var/www/wordpress/wp-content/plugins/blog-in-blog/
FILENAMES=blog-in-blog/trunk/*
LASTFILESIZE=0
COUNTER=1

echo "======================================================"
echo -e "delivering changes \n\tin \033[1m$SOURCEDIR\033[0m \n\tto \033[1m$DELIVERDIR\033[0m"
echo "======================================================"		

if [ -z $1 ]
then
	echo "usage$  $0 "
	exit 1
fi

hash_insert ()
{
	local name=$1 key=$2 val=$3
	eval __hash_${name}_${key}=$val
}

hash_find ()
{
	local name=$1 key=$2
	local var=__hash_${name}_${key}
	echo -n ${!var}
}

while true
do
	for FILE in $FILENAMES
	do
		FILESIZE=$(stat -c%s "$FILE")

		#tidy up file to avoid problems in variable name
		FILE=`basename $FILE`
		FILEORIG=$FILE
		FILE=`echo "$FILE" | sed 's/[\.\_-]//g'`

		LASTFILESIZE=`hash_find fileHash $FILE`
		#echo "filesize:"$FILESIZE
		#echo "lastfilesize:"$LASTFILESIZE
		if [ "$FILESIZE" != "$LASTFILESIZE" ]
		then
			echo "--- $COUNTER ---------------------------------------"
			date
			echo -e "deploying \033[1m$FILEORIG\033[0m from project $PROJECTNAME"
			echo "Size was $LASTFILESIZE bytes, now $FILESIZE bytes."
			cp $SOURCEDIR/$FILEORIG $DELIVERDIR
			hash_insert fileHash $FILE $FILESIZE
			UPDATE=1
		elif [ "$UPDATE" -ne "1" ]
		then
			UPDATE=0
		fi
	done

	if [ "$UPDATE" = 1 ]
	then
		echo "======================================================"
		let COUNTER+=1
		UPDATE=0
	fi

	sleep $1
done
#ends