Tuesday, 12 October 2010

I learnt you can achieve a childhood dream

... although it doesn't always turn out as you would hope.

On 12th June 1984 I was on a family holiday in the US. We had spent three weeks travelling around Florida and then up the east coast to finally end up in Boston. During the day we had a guided tour of the city and we were told that it was game seven of the NBA finals that night between the Boston Celtics and the Los Angeles Lakers.

I was only thirteen but, possibly as it was the last night of the holiday, managed to persuade my parents that I could stay up and watch the game. My mum and I stayed up late into the night watching Boston beat the Lakers. Despite being in Boston, for some reason I decided to support the Lakers.

And so started my love of basketball and the Lakers. It also became a dream to see them play.

Living in the UK makes this a bit of a challenge. I was fortunate to see the first game between two NBA teams in the UK when the Orlando Magic, including a young Shaquille O'Neal, took on the Atlanta Hawks. I saw the Houston Rockets play in the McDonalds championship.

The closest I came was when Magic Johnson brought a team over to play and absolutely destroy the UK national team. I got to see one of my childhood heroes play.

A bit later I got to go to Los Angeles for a holiday and saw the Forum and the Staples Center, but only when driving by. It was out of season so no chance of seeing a game.

On the 4th October 2010 I was able to fulfil my childhood dream and see the Lakers play. The Lakers played the Minnesota Timberwolves at the O2 Arena in London. Kobe Bryant played only six minutes and the Lakers went to sleep in the second half but I got to see them play.

It would have been nice to see them play well. It would have been nice to see them win. However sometimes these things take second place to achieving a childhood dream and sometimes childhood dreams don't work out quite as you hope.

Monday, 20 September 2010

I learnt about the top idea in your mind

I came across a post by Paul Graham a month or two ago that really made me think and I meant to write something about it but never got round to it. (Read it here).

The basic premise is that whatever is the main focus at the moment will take up all your spare thought processing time, potentially at the detriment of other things. His example is for a start-up that has grown to a certain size and is looking for funding and this becomes the focus to the detriment of all the other activities they had been doing to that point. This is not a concious choice but the thought of fund raising takes all the spare thought time that previously would have been for other things.

I have encountered this so many times in both a positive and a negative way. The positive way has happened when I am completely consumed by a problem, typically at work, and eventually a solution will arrive or it will lead to something else.

On the negative side it can certainly be a massive drain on brain power to be thinking about less productive and potentially less important things.

We moved house recently and this has definitely been the "top of the mind" idea. Every spare moment was filled with either the logistics of moving or locating a new house or finances etc. I did notice that it impacted other areas especially the creative side of thinking about issues and also relaxing.

Now I try to catch myself when the focus gets too much on one thing and deliberately spend some time focussing on other things - sometimes it works, sometimes the old idea just creeps back in - but I am certainly more conscious of what is happening.

Friday, 2 July 2010

I learnt about VS2010 crashes and a few possible solutions

On my new project we are evaluating using Visual Studio 2010, but still building against .NET 3.5 ... for the time being.

We have been experiencing frequent lockups of the IDE and crashes.

After some investigation I came across a couple of possible reasons:

AnkhSVN version (via Resharper Blog) ... http://blogs.jetbrains.com/dotnet/tag/resharper-51/
Patch for VS2010 Cut and Paste ... http://blogs.msdn.com/b/visualstudio/archive/2010/06/25/patch-available-for-cut-or-copy-displaying-insufficient-memory-error-in-vs-2010.aspx

We are still seeing the odd crash/hang but it has improved the situation a lot.

Hope this is useful for someone.

Wednesday, 10 February 2010

I learnt how to inject WPF DataTemplates into a window using MEF

I am working on a WPF project where it needs to be able to support new item types dynamically. I am writing the core framework and other teams will produce functionality specific to certain object types.

This has all been working fine until I hit the scenario where I have a screen and a section of it needs to be built based on the object type.

In the non-extensible approach you would use a series of data templates which would then populate the section based on the item type.

However in my scenario these templates need to implemented by third parties. Wouldn’t it be nice to be able to inject these into the window at run-time.

We are using MEF for our extensibility and already have the means to inject custom controls into windows. However this problem seems more suited to using DataTemplates rather than having to know which control to inject.

The solution I have produced is as follows:

1. The user creates a data template in a resource dictionary and adds it to their assembly. Fairly standard stuff.

2. I have a static class (yes this could be injected as well) that locates a resource within an assembly.

    public static class ResourceLocator
{
/// <summary>
/// Gets the first matching resource of the type.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="assemblyName">Name of the assembly.</param>
/// <param name="resourceFilename">The resource filename.</param>
/// <returns></returns>
public static T GetResource<T>(string assemblyName, string resourceFilename) where T : class
{
return GetResource<T>(assemblyName, resourceFilename, String.Empty);
}

/// <summary>
/// Gets the resource by name
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="assemblyName">Name of the assembly.</param>
/// <param name="resourceFilename">The resource filename.</param>
/// <param name="name">The name.</param>
/// <returns></returns>
public static T GetResource<T>(string assemblyName, string resourceFilename, string name) where T : class
{
if (string.IsNullOrEmpty(assemblyName) || string.IsNullOrEmpty(resourceFilename))
return default(T);
string uriPath = string.Format("/{0};component/{1}", assemblyName, resourceFilename);
Uri uri = new Uri(uriPath, UriKind.Relative);
ResourceDictionary resource = Application.LoadComponent(uri) as ResourceDictionary;
if (resource == null)
return default(T);
if (!string.IsNullOrEmpty(name))
{
if (resource.Contains(name))
return resource[name] as T;
return default(T);
}
return resource.Values.OfType<T>().FirstOrDefault();
}
}


 



3. In the third party assembly it calls the ResourceLocator somewhere to locate the template:



m_template = ResourceLocator.GetResource<DataTemplate>("TheAssemblyName","Resources/TheResources.xaml");


Where the first parameter is the name of the assembly and the second in the name of the file with the resource (this could be in the static constructor).



4. This is where MEF kicks in. I now have a property that exposes this DataTemplate using a known contract name.



        [Export(MyTemplateContract)]
public DataTemplate MyTemplate
{
get { return m_template; }
}


5. In MEF I can now import all the instances of the MyTemplateContract and inject them into my window resources.



        private void LoadTemplates()
{
IEnumerable<DataTemplate> templates = Composer.GetExportedObjects<DataTemplate>(MyTemplateContract);
foreach (DataTemplate template in templates)
Resources.Add(template.DataTemplateKey, template);
}


And that’s it. Now the other teams can create a new data template, use the resource locator to find it and export it as a property. My application will then pick these up at run-time and inject them into the window.

Wednesday, 23 December 2009

I learnt how a restaurant influences choices

This article has a very interesting study on how restaurants can influence choices of dishes. I will never look at a menu the same way again.
Restaurants Use Menu Psychology to Entice Diners - NYTimes.com
I wonder what other areas have the same approaches. Supermarkets is an obvious example.
And how difficult would it be to come up with a set of "rules" for a completely new domain.

Update: And along the same lines ... The hidden psychology of menu design

I learnt about formatting multiple strings in a binding

Such an obvious solution, but in the past I have tended to write converters to format multiple values:

<MultiBinding StringFormat=”Date: {0:MM/dd/yyyy}, Percent: {1:P}”>
<Binding Path=”BeginDate” />
<Binding Path=”Percent” />
</MultiBinding>


From http://goldmanalpha.wordpress.com/2009/12/23/lab-this-month/


 

Tuesday, 8 December 2009

I learnt about checking a .NET application is running as 32 bit

We had a scenario where an application had to run as 32 bit on a 64 bit server, due to an external library.

I’ve used the corflags command line tool in the past but in this scenario we are using the Target Platform flag in the build. As I don’t have access to the server it is deployed on I needed to check that the build was being built with the correct flag.

I came across this page:

http://bytes.com/topic/net/answers/617520-how-determine-assemblys-target-platform

Using the information on this page I was able to check, using ildasm, that the build was being done correctly.