Friday, March 30, 2007

Murphy's Law

I'm to London today. This means sitting on a train for over two hours. So, what do I do? That's right, I forget the phone with the big memory card so I can listen to music and block out the sounds of moaning as those who didn't have the foresight to book a seat raise as we're told of yet another delay.

Chaturanga Dandasana

Chaturanga Dandasana makes the front of your shoulders/armpits hurt in the most unusual way.

Friday, March 23, 2007

Entirely redundant C# 2.0 code

private static IEnumerable< int> Range ( int start, int end )
for ( int i = start; i != end; i = (start > end ) ? i - 1 : i + 1 )
yield return i;
yield return end;

private void PopulateDaysDropDown ( )
foreach ( int day in Range ( 1 , 31 ) )
DateOfBirthDay.Items.Add ( day.ToString ( ) );
The only benefit of this is Range accepts start > end, so I could equally well do
foreach ( int day in Range ( 31, 1 ) ) {  //... }
I'm determined to find a valid use for yield return somewhere!

Tuesday, March 20, 2007

"The Air Car - Zero Pollution and Very Low Running Costs"
Just one question: How does the air get compressed in the first place?


Just finished the most nerve racking deployment of my life.
Here are some things I need to remember:

  • Don't think you can finish stuff up whilst doing the deployment
    Rushing stuff when you're under pressure is a sure fire way to mess up royally.
  • Deploy when no-one's looking
    It's no fun finding and fixing bugs when you've got the whole company's watching.
  • Don't trust sourcesafe
    It's shit. It can't branch or merge properly. It corrupts all the time. It's a steaming pile of cow shit. Don't trust it.
  • Remember to set your alarm
    Waking up an hour later than you meant to and then rushing into work doesn't help your feeling of calm
  • Don't trust anyone else's code
    Unless you're happy with the rest of the team you work with, make sure you've got tools and monitors to see what's going on.
I'm sure there's other stuff that I need to remember, but I'm drained know. I'm going to spend the rest of the day trying to look like I'm doing work.

Friday, March 16, 2007

Ruby to screen scrape whether my train home is on time

require 'hpricot'
require ' open-uri'

while(1) do
html = open( '' )
doc = Hpricot(html)
results ="//td:eq(0)[text()='Middlesbrough']/../td:eq(1)[text()='17:55']/../td:eq(2)/text() ")
results.each { |r| puts "#{'%H:%M')} :\t#{r}" }

# ruby is such fun!

Wednesday, March 14, 2007

Is Air Travel being made a scapegoat?

Yesterday, Gary made the important point about why Air Travel is currently being targeted for carbon reductions.
Make no mistake, mile for mile, air travel is the most polluting way of travelling, and it is predicted to expand in the future. But, this aside, Gary's point was that air travel accounts for such a tiny proportion of everyday travel (~3%) that, if it suddenly becomes twice as expensive, there's not going to be too much of a fuss.
I also think people expect air travel to be expensive - I was surprised that a return flight from Manchester - London was ~£70, which is tempting when an off-peak return by train is ~£60.
We've recently seen the uproar created by suggesting that the road users pay per mile. No politician is going be be popular by suggesting the cost of using your car should reflect it's impact on the environment. British society is too focused around the car for that.

Monday, March 12, 2007


WHY WHY WHY WHY WHY do train companies use session state to store my itinerary?
I used a tabbed browser, which means changing the itinerary in one tab fucks up the itinerary in the other tabs. fuckers.
It's just taken me an hour to book a return journey because of this evil fucking ploy.

Thursday, March 01, 2007

?? - C#'s Secret Operator

If you look at the MSDN documentation for ??, you might think that ?? is only useful for Nullable Types. However, it can be used with any non-value object.
So, in place of

return x == null ? default : x;

You can now write:

result x ?? default;

Cryptic? yes.
Wrist friendly? marginally.

I'm currently using an API that returns null instead of empty arrays. The basic construct now becomes:

ContentData[] dataToDelete = content.GetChildContent (folderId, false, "Title");
foreach (ContentData itemToDelete in dataToDelete ?? new ContentData[0] )
    content.DeleteContentItem( itemToDelete .Id);

This way I avoid NullReferenceExceptions, and get away without putting extra 'if' statements in.