Archive for December, 2009

Quick post to say that on Friday morning I received my acceptance letters from ThoughtWorks. This means I can finally close the door on one Saga (and open the door to another one).  All in all it should make for an interesting start to the New Year.


5 Second IList ordering with Linq and strings

Ok, so Im only writing this blog post as a reference for myself so I dont have to think about it again, but hey it *may* be useful to someone but me.

I just needed to order a generic list based upon a property name string, here what I have:

public static IList<T> OrderByName<T>(this IList<T> items, string order, string coloumn)
 // don't try to sort if we have no items
 if (items.Count == 0) return items;
 var propertyInfo = typeof(T).GetProperties()
                             .Where(p => p.Name == coloumn)
 return propertyInfo == null
    ? items
       : (order.ToUpper() == "ASC"
       ? items.OrderBy(n =>propertyInfo.GetValue(n, null)).ToList()
       : items.OrderByDescending(n => propertyInfo.GetValue(n, null)).ToList());


myList.OrderByName("asc", "Property");

After yet another day of being distracted WAY too much by twitter, I recall a tweet that Paul Cowan posted:

“what are people using to combine all their .js files into 1?”

Now I had no idea how people we doing this but, ironically, this is functionality that I will require myself shortly. What I did know though was that the kind people at Google recently released their JavaScript closure compiler a tool that cleans, optimizes and minifys your .js scripts. This library is available as either a downloadable command line tool, or via a RESTful API.

So, for the purpose of testing this library (and given the fact that Mads Kristensen has created a small wrapper around it) I opted to play with the RESTful API. My aims were to build a quick and dirty HttpHandler around this library that would mash all my .js files together, send them to be complied and stuff the results into the cache.

With this in mind I give you my 15 minute spike:

If you download this solution you’ll see a web project that references my HttpHandler and has the following config section:

<add verb="GET" path="*.mash" validate="false" type="MashPotato.Core.ClosureHttpHandler, MashPotato.Core"/>

This configuration allows me to add “.mash” file in the same folder as my scripts which contains a list of newline separated names of the JavaScript files to be mashed together i.e.

Looking in scripts.mash you’ll see:

Now simply reference the .mash file like any other JavaScript files and you should get the mashed, compiled, optimized of the referenced file i.e:

<script src="../../Scripts/scripts.mash?cache=true" type="text/javascript"></script>

Also, notice the “cache=true” uri parameter… guess what this does?


I’d say there’s likely to be hundreds of issues as it took me approximately twice as long to write this blog post than to write the handler, but off the top of my head here goes:

  • Googles RESTful API has a size limit of the amount of data that can be posted to it so no mashing up your large framework scripts like JQuery.
  • Obviously, the console application should perform much better than the RESTful API
  • I don’t know, it took me 10 mins I’m sure it’s  buggy as hell.