James Crisp

Software dev, tech, mind hacks and the occasional personal bit

Wedding Reception in Sydney

On 10 May, we had our “second wedding” in Australia! It was awesome and we had a really good time with friends and family 🙂

More photos here:
http://flickr.com/photos/soosun_and_james/sets/72157605121741281/

The Long Tail by Chris Anderson

Just finished reading “The Long Tail – How Endless Choice is Creating Unlimited Demand” by Chris Anderson. In summary, the long tail is about selling small volumes of a vast variety of items instead of large volumes of a small number of “hits”. This possible when the cost of distribution to geographically distant customers is low and the cost of storage for stock is not a concern (eg, intellectual property in electronic format, JIT manufacture). Popular companies capitalising on the long tail include eBay, Amazon, Google Adwords and Lulu.

The book has a lot of interesting stories and statistics but tends to repeat itself often. The long tail idea is probably not new to most readers these days, and I think if you’re familiar with Amazon, there’s little that comes as a surprise. However, I did find an interesting section in the book about the tyranny of choice. Anderson suggests that choice is good, customers want choice, and choice is only a problem if you don’t know what to choose to suit your taste. Hence, an important part of a long tail business is helping people find what they want (ie, filter out noise) in all the vast array of choices. He suggests using user reviews, rankings, sorting etc as means to help people find the “best” choice for them. I also hadn’t come across Lulu before – looks worth checking out, a site for mini self-publishing.

Ginger Beer Recipe

Ginger Beer BottlesHome made ginger beer is awesome, and not hard to do at all. It takes a few hours to prepare all the ingredients, then several days fermentation, then another hour or two for bottling. Usually I make about 8 or 9 1L bottles of ginger beer in a batch, and I like to make it less sweet than the commercial stuff. It is slightly alcoholic (1-2% approximately) and has a really nice gingery bite the goes well with pizza, spicy food or just about anything else! I use a recipe adapted from the Ye Olde Ginger Beer Recipe. It is as follows:

Ingredients

  • 4 lemons
  • 900g sugar
  • 9L of water (enough to fill a demi-john)
  • 1 packet / 2 teaspoons of Ale yeast (you can use bread yeast if you’re desperate)
  • 200g fresh root ginger
  • 4 heaped tea spoons of tartaric acid (Cream of Tartar)

Equipment
Carboy

  • A large pot that can boil four litres of water
  • A jug
  • A glass
  • A coarse cheese grater
  • A wooden spoon
  • 10L carboy (10L water container does nicely) washed & sterilized with bleach
  • A bubble seal for the carboy
  • A lemon juicer
  • A lemon zester / fine grater
  • A fine sieve
  • 9 X 1.25 litre soft drink bottles, empty, washed & sterilized with bleach

Method

1. Fill pot with water and put on to boil

2. While the water is coming to the boil…

  • scrape the zest from one of the lemons
  • grate the ginger on the coarse cheese grater
  • add the sugar to the ginger and lemon zest in a bowl
  • cut the lemons in half and squeeze the juice into the jug
  • add the tartaric acid to the lemon juice
  • put the yeast into some warm water with a little sugar in a glass

3. When the water has boiled ….

  • add the sugar, ginger and lemon zest to the water, turn off the heat and
    stir
  • allow the water to cool to roughly blood heat, stirring occasionally
  • add the lemon juice and tartaric acid to the water
  • add the yeast mixture

Carboy with bubble seal

4. Use the jug to pour the mixture into the carboy and top up to 9L with boiled water (cooled to blood temperature)

5. Seal the demijohn with the bubble seal (I use salt in the water to sterilize the seal)

6. Stand the demijohn in a warm place for 48 hrs or for several days in a cool place

7. After 48 hrs pour the mixture through the sieve into the jug and fill the bottles leaving an air gap for the pressure to build up in (1L into each bottle). Screw the caps tightly onto the bottles

8. Leave the bottles at room temperature for 24 hrs (to generate the C02 fizz)

9. Put the bottles in the fridge for 2-3 days to allow the yeast to settle

10. Drink and enjoy 🙂

Notes
If you ferment the mixture in the carboy for longer before bottling, it will be less sweet and more alcoholic.

Photos from Sapa, Vietnam

I put holiday photos on my screen saver, and these favourites just came up. I thought I’d share them with you…

Exploring Sapa

Sapa Guides

Bounded Actions Using Lambda – IDisposable is old and ugly!

In .NET 2, it was all the rage to make hand-crafted, clever IDisposables that let you do a bounded action with clean up. Eg,

void SomeMethod()
{
        using (new SetCursorToWaitEggTimer())
        {
            VerySlowOperation();
        }
}

void VerySlowOperation()
{
    ... etc ...
}

This was kind of cute – you could make sure that, even if an exception was thrown, your clean up (eg, changing cursor back to normal) would occur. Implementing the IDisposable was a bit ugly but consuming it wasn’t bad.

Now, with the sexy C# 3 syntax, you can do something similar much more elegantly. Eg,

void SomeMethod()
{
       DoWithWaitEggTimer(VerySlowOperation);
}

void DoWithWaitEggTimer(Action action)
{
    try
    {
        Mouse.OverrideCursor = Cursors.Wait;
        action();
    }
    finally
    {
        Mouse.OverrideCursor = null;
    }
}

If you’re feeling like more adventures, you can also start passing these delegates around and injecting them. For example:

class SomeClass
{
    public Action RunSlowCode 
    {
    	get { return runSlowCode ?? new Action(a => a.Invoke()); }
    	set { runSlowCode = value; }
    }
    Action runSlowCode;

    void DoSomethingSlow()
    {
         RunSlowCode(PullDataFromExternalSystem);
    }
}

This approach allows you to inject the delegate for what happens when slow code is run. So you could inject DoWithWaitEggTimer() or something new like DoWithWaitMessageDisplayedToUser(). Similarly, it could be used for unit testing or injecting between layers in your application.

C# Default Access Modifier for Class Members – and drop that private habit!

The default access modifier for the members of a C# class (eg, fields, methods, and properties) is ‘private’. As such, I recommend never using the redundant ‘private’ keyword for class members. Leaving off the private nicely separates your privates from your public/inheritable interface in syntax highlighting. It also saves people having to read redundant code – you wouldn’t want your code to be full of un-needed casts, or redundant ‘this.’ references, would you?

WPF Control Inheritance With Generics

Working in WPF is quite exciting – there’s a lot of new possibilities, especially with easy control composition, much improved binding and Expression Blend to make sexy interfaces. One of the things you’re likely to want to do though, when writing anything more than a toy application, is to have a base class for your UserControls or Windows, to share common functionality. It is also quite likely you will want to use generics in conjunction with control inheritance. With both the code behind, and the XAML, it’s not immediately obvious how to do generic inheritance. It is a bit fiddly to get going, and sometimes the errors are not helpful. Here’s a simple example that outlines how to bring it together.

The base control

namespace WpfGenericsDemo
{
    public class BaseUserControl<T> : UserControl where T : IPresenter
    {
        public BaseUserControl()
        {
            ... various configurations ...
        }

         ... Awesome functionality to share ...
    }
}

The child control code-behind

namespace WpfGenericsDemo
{
    public partial class ChildUserControl : BaseUserControl<ChildPresenter>
    {
        public ChildUserControl()
        {
            InitializeComponent();
        }

         ... More code ...
    }
}

The child control XAML

<WpfGenericsDemo:BaseUserControl x:Class="WpfGenericsDemo.ChildUserControl"
    x:TypeArguments="WpfGenericsDemo:ChildPresenter"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:WpfGenericsDemo="clr-namespace:WpfGenericsDemo">
    
    ... The rest of your awesome XAML ...

</WpfGenericsDemo:BaseUserControl>

Notes

  • Your top level node is the parent class of the control you want to create (eg, BaseUserControl). You specify the control class you want to create with ‘x:class’ (eg, ChildUserControl)
  • ‘x:TypeArguments’ is the way you specify the generic type (eg, ChildPresenter)
  • You need to namespace your classes – eg, with ‘xmlns:WpfGenericsDemo’ which uses a clr-namespace style reference
  • Only your top level node can be genericised in XAML

Treo 650 phone radio turns off by itself – a solution!

Recently, I’ve been disappointed to find my Treo 650 turning off the phone radio by itself. If I was lucky, I heard the melodic sound that means “radio now off”, and then I manually turned the radio back on. If I was unlucky, I didn’t hear it, and missed phone calls and messages.

It seems that the cause is that the Treo 650 SIM case gets looser with wear, and any break in connection between the SIM and the phone causes the phone radio to be deactivated. The solution is pretty easy, and described at the end of a FAQ I came across. In summary, take out the SIM tray from the phone, remove the SIM. Put several layers of paper (cut small to fit) in the SIM tray, and then clip the SIM back on top. When you put the SIM tray back into your phone, it should work reliably again, with no more random turn-offs!

Loan Calulator: Monthly repayment and interest breakdown

Wondering if your loan repayment calculations have been performed correctly this month, taking into account interest rate rises and extra repayments? You might be interested in giving my monthly loan calculator a go.

As my home loan provider doesn’t show balances online, and only sends statements every 6 months, I like to ring up every month or two to make sure things are on track. I used to calculate interest, new balances etc in a spreadsheet / calculator but spent an afternoon writing a little Rails app to calculate it for me. Hopefully my little monthly loan calculator is of some use to you too.

NUnit Test Runners Were Not All Made Equal

NUnit tests can be run using a variety of different runners. Some common ones are:

The NUnit GUI and Test Driven create a new instance of the test class for each test run. This leads to more isolation but potentially slower performance.

Resharper and NUnit MSBuild Task re-use the same instance of the test class when running each test in the class. This can lead to unintended interaction between tests. Using these runners, it is vital to to assign initial values to instance variables in SetUp, rather than when they are defined or in the constructor.

If you use a mix of different test runners, you can end up with tests that pass on some machines and fail on others (eg, Test Driven locally works fine, but you use NUnit MSBuild Task on your build box and get intermittent failures).

Page 11 of 20

Powered by WordPress & Theme by Anders Norén