Monday, 17 November 2008

Dealing with snake bite

Before you panic, no, this hasn't happened to me (yet).

A kind colleague lent me a very old and rare book recently, that has a great story on the above title. The book, From Cape to Cairo, by Ewan Scott Grogan, tells of the first traverse of Africa from South to North.

The next time you have a bite of some description, be glad the treatment isn't what follows:

"During lunch a native rushed in, saying that he had been bitten by a night-adder (one of the most deadly snakes in Africa). I promptly collared him by the arm, stopped the circulation with some string, slit his finger crosswise with my pocket-knife, exploded some gunpowder in the cut, while Dodson administered repeated subcutaneous injections of permanganate of potash. Meanwhile the arm, chest, and left side swelled to the most appalling proportions. Cavendish then appeared on the scene with a bottle of whisky, three parts of which we poured down his throat. Then we told off three strong men to run the patient round the camp till he subsided like a log into a drunken stupor. The following morning he was still alive, but the swelling was enormous, and the colour of his nails indicated gangrene. Not knowing what else to do, we put a pot on the fire, and made a very strong solution of the permanganate which we kept gently simmering, while six stalwart natives forced the unfortunate's hand in and out. His yells were fearful, but the cure was complete. The swelling rapidly subsided, the nails resumed their normal colour, and the following morning, with the exception of the loss of the skin on his hand, he was comparatively well."

Wednesday, 29 October 2008

Help - the Storm Troopers have got me

Help - the Storm Troopers have got me
Originally uploaded by visited
Visited the Alien Invasion at the Spinnaker Tower recently. The best bit was the Storm Troopers from the UK Garrison. Scarily realistic!

Basil and teddy

Basil and teddy
Originally uploaded by lyndsayp
Five years of nagging, and we finally do it!

Yes, we've got a dog (the one on the right). The kids agreed to give up Christmas presents in exchange for having a dog. He's a Border Collie and is ten weeks old in this picture. Named Basil, after Basil the Brush (the one on the left).

House training is going well so far!

Tuesday, 14 October 2008

Serialising, streams and strings

A common operation is to serialise and object to a string. I'm still finding better and better ways of doing this. My current favourite makes use of .Net 3.0's DataContract. It uses a UTF8Encoding and a MemoryStream as this ensures that the output XML is UTF8.


using (MemoryStream stream = new MemoryStream())
DataContractSerializer serializer = new DataContractSerializer(typeof(SomeClass));
serializer.WriteObject(stream, instanceOfSomeClass);

// Serialisation defaults to UTF8Encoding when used with a stream.
// See Simple Serialization at
string data = Encoding.UTF8.GetString(stream.ToArray());

// Do something useful with the data.

Filtering log4net messages

I can never remember how to do this: filter out logging message based on where they come from.

The solution is to use a LoggerMatchFilter. The code below can be inserted into any appender definition:

<filter type="log4net.Filter.LoggerMatchFilter">
<loggertomatch value="NHibernate.Loader.Loader"/>
<acceptonmatch value="false"/>

Tuesday, 7 October 2008

Love is ... unconditional (really, truely)

I've been a blown away by the book Velvet Elvis. It challenges many assumptions we make about faith, and strips it back to its bare essentials.

A quote from the book that particularly struck me was this:

"If the gospel isn't good news for everybody, then it isn't good news for anybody.

And this is because the most powerful things happen when the church surrenders its desire to convert people and convince them to join. It is when the church gives itself away in radical acts of service and compassion, expecting nothing in return, that the way of Jesus is most vividly put on display. ... We have to surrender our agendas. ... I have learned that when I toss out my agenda and simply love as Jesus teaches me to, I often end up learning more about God than I could have imagined."

Mind blowing stuff. The exciting part is living it.

Wednesday, 3 September 2008

Redundancy, L=V+E and being a great leader

I pleased to read in Clusters words that I often say to others. When describing my aim at work, I often state that I strive to make myself redundant, so that:
  1. The team grow to be able to do all that I do, but without me.
  2. I can focus on higher-level goals.
p.159 of Clusters states that "the intention of a good leader ought to be to do themselves out of a job and to do this they need to be aware of the seasons of leadership that God takes them through"

It then goes on to list these seasons/steps (as modelled by a great leader 2000 years ago):
  1. State a clear vision.
  2. Adopt a "I do, you watch" approach ...
  3. Followed by "I do, you help" ...
  4. Followed by "You do, I help" ...
  5. Followed by "You do, I watch".
The final point I noted on leadership was from p.178, where the useful formula was stated of:

Leadership = Vision + Empowerment

A useful exercise is to consider what a team would feel like to be in if either Vision or Empowerment is Low or High, e.g.
  1. Low vision + low empowerment = dead
  2. High vision + low empowerment = burnt-out
  3. Low vision + high empowerment = cosy
  4. High vision + high empowerment = dynamic

Accountability in life

Was given the book Clusters to read this Summer and thoroughly enjoyed it whilst on holiday. It was a great book to read following on from my trip to Karamoja and then reading Velvet Elvis.

The following points stayed with me about being accountable to each other (in a small faith group, or equally at work). Several references were made to the John Wesley Class-meeting System, which would also be worth researching.
  • p83. "Relational, rather than institutional accountability is entirely different ... the relationship is indispensable."
  • p81. Accountability questions:
    1. "What do you want to see changed in your life?"
    2. "What do you sense God is challenging you on?"

Effective evangelism requires ...

Went to a great talk at New Wine by David Parker on what evangelism requires. It is based on Mark 14. Here are the key points I took away:

Effective evangelism requires:
  • Self-denial - personal sacrifice for the good of others.
  • A broken heart for the lost.
  • Demonstrative love: "evangelism is an outward demonstration of all other gifts".
  • Consistency in:
    1. Friendly contact.
    2. Meaningful connections.
    3. Significant content.
  • Creating a climate of pleasant surprise, instead of disappointment.
  • Embracing ultimate joy - anticipation of the good to come.

Thursday, 14 August 2008

SQL errors don't cause exceptions if nocount is off

We had a strange problem today: an end-user was getting unexpected results (no data), but no exceptions were occurring.

The cause was traced to incorrect database permissions, i.e.

Server: Msg 229, Level 14, State 5, Procedure xyz, Line 123
SELECT permission denied on object 'abc', database 'pqr', owner 'dbo'.

The question was, why did this not cause an exception? A possible cause is our use of SqlDataReader, but I was unhappy with the suggested fix. The underlying cause however was that nocount was set to off (its default setting). This caused the row count messages to mask the error, and thus no exception was raised.

Lesson learned: always set nocount on at the start and off at the end of each stored procedure, e.g.

create procedure xyz

set nocount on


set nocount off



Tuesday, 12 August 2008

God sees you now as one day we could be

These were the words of Brother Andrew, spoken at this year's New Wine Summer conference my family attended. These words are echoed by Paul and Rob Bell, in his book Velvet Elvis that I'm really enjoying at the moment.

A truly inspirational speaker.

Thursday, 17 July 2008

Deciding between ref and out

C# defines two keywords for parameter passing modes: ref and out. For a full discussion of why this is, see this msdn article, from where the below examples are taken. This is a summary of which to choose and why.

When to use neither

ref and out are used for methods that pass back two or more values to the caller. This is often a code smell indicative of the need for a new encapsulating struct or class. As a rule of thumb, where three or more ref’s or out’s are required, use a struct or class to encapsulate them into a single parameter instead.

When to use 'out'

Use out when the method’s focus is to provide two or more new return values, some of which may be null/empty.

In the following example, the firstName and lastName parameter values are only of interest after the call to SplitName. Neither the callee nor the caller require knowledge of their initial value, and its valid that either or both remain null/empty.

class OutExample
static void SplitName(string fullName, out string firstName, out string lastName)
// NOTE: firstName and lastName have not been assigned to yet. Their values cannot be used.
int spaceIndex = fullName.IndexOf(' ');
firstName = fullName.Substring(0, spaceIndex).Trim();
lastName = fullName.Substring(spaceIndex).Trim();

static void Main()
string fullName = "Yuan Sha";
string firstName;
string lastName;

// NOTE: firstName and lastName have not been assigned yet. Their values may not be used.
SplitName(fullName, out firstName, out lastName);
// NOTE: firstName and lastName have been assigned, because the out parameter passing mode guarantees it.

System.Console.WriteLine("First Name '{0}'. Last Name '{1}'", firstName, lastName);

When to use 'ref'

Use ref when the method’s focus is to return a value and make use of and potentially update a second value.

In the following example, the index parameter’s value is of interest before and after the call to FindNext. Both the callee and the caller require knowledge of its initial value, and its valid that it may be modified by the call to FindNext.

class RefExample
static object FindNext(object value, object[] data, ref int index)
// NOTE: index can be used here because it is a ref parameter
while (index < data.Length)
if (data[index].Equals(value))
return data[index];
index += 1;
return null;

static void Main()
object[] data = new object[] {1,2,3,4,2,3,4,5,3};

int index = 0;
// NOTE: must assign to index before passing it as a ref parameter
while (FindNext(3, data, ref index) != null)
// NOTE: that FindNext may have modified the value of index
System.Console.WriteLine("Found at index {0}", index);
index += 1;

System.Console.WriteLine("Done Find");

Friday, 13 June 2008

URL rewriting with multiple websites

Less exciting than my previous posts I'm afraid (safely back in the UK now).

I recently consolidated a number of websites onto a single Windows 2003 server. One such site (dokuwiki) used url-rewriting via ISAPI Rewrite to present user-friendly URLs. Unfortunately our original rewriting configuration broke the other websites as it tried to re-write their url's also!

Although I'm happy to pay the $99 for the full version of ISAPI Rewrite, I was pleased that we could solve the problem with the Lite one by using the RewriteCond directive, e.g.:

RewriteCond %{HTTP:Host} =ourWikiHostName
RewriteRule ^/_media/(.*)\?(.*)$ /lib/exe/fetch.php?media=$1&$2 [L]
RewriteCond %{HTTP:Host} =ourWikiHostName
RewriteRule ^/_detail/(.*)\?(.*)$ /lib/exe/detail.php?media=$1&$2 [L]

The same technique will also prove useful in hosting multiple .Net 3.5 web services on the same server, e.g.:
RewriteCond %{HTTP:Host} =webServiceHostName RewriteRule RewriteRule ^/(.*)$ /service.svc/$1 [L]

Sunday, 18 May 2008

You know you're in Africa when ... (Kotido, Kachiri, Kaabong)

We've been in Kachiri Monday - Friday, Kaabong this Saturday and Sunday and Kotido in-between.

I hope the following gives a taste of what we've seen and done....

You know you're in Africa when ...

10:30 am actually means 12pm, or maybe 1 or 2 pm.

It rains for less than an hour and everywhere is flooded. But the people are over-joyed.
... and more rain

The local church is just a tin roof.
Kacheri church

You have four armed police men guarding you at night.
Four policeman with AK47's was assigned to guard us at night for the week

Almost one-hundred people meet under a tree, and will listen to three locals and three Muzungu's talk about God.
one of the many learning trees we visited

Only English men use umbrella's when it rains.
Peter is a real Englishman ... he didn't forget his umbrella

Children have swollen bellies because there is no food.
the signs of famine

Young and old have eye problems that are a minor operation in the West. Yet when they look at you, you also see their love and gratitude for meeting you.
we prayed for many people

You borrow a local's bike, only to discover it has no brakes.
There goes Lyndsay

Your vehicle gets stuck in a dry river bed, and you and half a village dig, push and pull it out.
We needed some help to get out of a ditch

People who have nothing give you their fatest goat and chicken as a leaving gift. Some passengers (me) seem to worry about travelling with them though!
our gift catching a lift home

Planting a hedge is blister-making, back-breaking work (if you're a Muzungu, that is).
Planting the hedge

Going to the toilet (long-drop) at night may mean being shot (by a sleepy policeman, or whoever they're guarding us from).
our toilet

A game of hop-scotch attracts half the village.
hopscotch on the streets of Kacheri

People play football barefoot, despite inch-long thorns.
playing with the gifts we brought

A three-hour church service is short. It (plus free lunch) attracts 720 people and ends with 102 people becoming Christians.

Sunday, 11 May 2008

Arriving in Kotido

We left Kampala on the 7.30 am MAF flight to Karamoja.Flying from Kampala in the South to Karamoja in the North-East was uneventful, but mind-blowing. As we crossed the Nile, and got closer and closer to Karmoja, the land went from being lush and green to dry and brown. River beds were very visible, with not water to be seen. I asked Laurie, the pilot, how long they stayed wet for. His reply was just one day. This is a region that only gets 5 cm of rain a year, and yet people have lived here for thousands of years.

Arriving in Kotido was very exciting. To finally be here after seven months of planning was a great feeling. It was mid-thirties, so we found the nearest bit of share to wait for our pickup.

After a fantastic welcome ("you are most welcome" was a phrase we would hear a lot from then on), we got to work. More on that next post. Our accomodation was basic, but suficient. We were just very glad for the mosquito nets!

Laurie prepares the MAF plane for take-off The NileDry river bedsManyatta up close
Finding shade as quickly as possible Our bed for the night

Thursday, 8 May 2008

First impressions of Uganda

We've done a fair bit of driving around Kampala today, what with needing to buy some wireless routers to take to Karamoja, plus visiting various sights and markets. When I say driving, I fortunately mean "being driven", as for a Westerner, the traffic is a nightmare! From what the others say though, Kampala is fairly typical of a large, 3rd-world city: busy, noisy, smelly and lots and lots of bikes and scooters. The only rule road-users seem to follow is keep to the left, though this does not stop over/under-taking at any opportunity!

What's surprised me about my visit so far is how normal everything seems. I was expecting to feel huge culture shock, both from being an ethnic minority and also due to the poverty. Both are very, very present, and the poverty saddens me, but I think I have yet to see it at its worst. I think that this has been tempered also by the seemingly even spread of poverty across the city: everywhere we go, we see people begging, selling things or otherwise impoverished, and yet right next to them will be someone in a suit, or a smart car, or even a private tennis court!

We were also treated to a view of Uganda's Prime Minister today! His convoy of a pickup, loaded with bored, but armed soldiers, followed by his chauffeur-driven Merc honked past us. We decided not to take any pictures though, having been warned by a traffic police-woman earlier in the day that taking photos without prior permission was not allowed (even from a car)!

Flying up to Karamoja tomorrow. Need to be up at 6 am :-(

Flickr photo stream of Uganda trip

Modern technology rocks! Although I can't claim responsibility for any of these snaps, they were taken by various members of the team...

First post from Kampala

I'm writing this post from Namirembe Guest House, in the capital of Uganda, Kampala. It still feels a bit surreal to be here, and inside I'm feeling very wobbly, like my head is not connected to my body!

I'm here with nine other Christians from Church of the Good Shepherd, Four Marks, as part of its Mission 2008 program. The basic idea is that we're celebrating the church's 100th anniversary by sending out 100 "blessings" to others, across the room, across the street and across the world. Our team are here to serve the church in Karamoja, an impoverished region of Uganda that is linked with the Winchester diocese.

Tomorrow morning we'll be flying to Karamoja on a MAF flight that will take six of the team to Moroto, in South Karamoja, and three of the team (including myself) to Kotido, in the more rural North Karamoja. One of my functions in the team is to install two laptops in the diocesan office in Kotido, and provide training in their use. The team will also be visiting local schools and manyatta's and speaking in local churches (Christ Church, Kotido on the first Sunday and St Peter's Church, Kabong on the second Sunday).

We'll be living with the locals, possibly in a manyatta like the one below!

Wednesday, 20 February 2008

Test run initialisation code

The problem of enabling log4net under NUnit required some unit test code that ran once at the start of a test run. Note that this code requires once-per-run execution, not per test or test-fixture.

After much puzzling and googling, I finally found the answer: SetupFixture. The NUnit documentation says it all.


Wednesday, 16 January 2008

Browser shortcuts

Condensed version of Coding Horror's excellent article:
  • Alt+D - address bar
  • Ctrl+E - search box
  • Alt+Enter (with cursor in address bar or search box) - open item in new tab
  • Middle mouse click - open/close a tab

Thursday, 10 January 2008

message.IsEmpty fixed by .Net 3.0 SP1

I've been enjoying writing some WCF services lately, including a Windows Service for consuming a WCF data feed.

Tests on the pre-production environment showed up a defect that seems to be present in .Net 3.0 but fixed in .Net 3.0 SP1. I've not located the release notes for the Service Pack so can not confirm this for sure.

The Defect

The provider web service returns an empty message in certain legitimate situations. The Windows Service therefore avoids processing a message's body if message.IsEmpty was true.

On my development PC all was good, but the pre-production environment gave exceptions whenever an empty message was processed.

Installing .Net 3.0 SP1 fixed the defect. If you know why, please leave a comment!