I had to use the Javascript encode method to escape some data in a hidden control recently. That data was then posted and I wanted a method to be able to convert it back. It turns out that the way to do it is using Uri.UnescapeDataString.

If anyone knows of a better method, or any issues with this approach, please leave a comment.

jQuery Ancestor Plugin

September 8, 2009

Today I wanted to select a parent element somewhere up the hierarchy using jQuery. I’ve since found that you can use the Parents function to do a similar job. In my case however I wanted the next parent item that matched the specified selector (I’m really only looking for a single item). I decided to create a jQuery plugin to do the donkey work for me.

Here is the implementation:

jQuery.fn.ancestor = function(selector) {
  return check($(this), selector);
}

function check(element, selector) {
  if(element.is(selector)) {
    return element;
  } else if(element.is("body")) {
    return null;
  } else {
   return check(element.parent(), selector);
  }
}

And here is an example usage:

$(this).ancestor(".menu-row");

I think this might be useful to anyone who wants to create their own jQuery plugins, and perhaps the actual plugin itself will be useful. Feel free to grab it.

Open Source CMS

July 15, 2009

Started work on Aardvark, an open source Content Management System, to be written in .NET.

Just had the need to compare that a list was in the correct order for a test I’d written. Handily there is a Linq extension method that makes the job easy, as the following snippet shows.

private static bool 
 OrdersMatch(IEnumerable newsItems, IEnumerable newsIds)
{
  return newsItems.Select(n => n.Id).SequenceEqual(newsIds);
}

You can use an extension method as I have, if you need to match on a specific part of the objects you are comparing.

This is something I have to do about two times a year and always forget. It’s useful if you are restoring a backup from a development or live server, and the data files are pointing in different places.

RESTORE DATABASE SOME_DB
FROM DISK = 'C:\backups\some_db.bak'
WITH REPLACE,
	MOVE 'some_db' TO 'C:\Program Files\Microsoft SQL 
              Server\MSSQL.1\MSSQL\Data\dsome_db.mdf',
	MOVE 'some_db_log' TO 'C:\Program Files\Microsoft SQL
              Server\MSSQL.1\MSSQL\Data\some_db_log.ldf'

LINQ Sytax

June 17, 2009

This post was going to be longer but I decided to cut it down, mainly due to the fact that it has been sat in my drafts for about 6 months. So in the end it’s a (very) short post about different LINQ to entity syntax, nothing to taxing but someone might find it useful.

As you may be aware LINQ provides various extension methods that allow you to perform query like operations (the ones we are interested in right now are Select, SelectMany and Where). This allows you to get data from any IEnumerable collection.

There are two syntaxes that you can use to get data from a collection.

The first is SQL like:

   1: var pilots = from tieFigher in tieFighters select tieFigher.Pilot;

Or using extension methods:

   1: pilots = tieFighters.Select(n => n.Pilot);

The second method uses the Select method which takes a Lamda Expression that allows us to specify what we want to select; in this case the Pilot. Both of these return the same result, and now that we have a list of pilot strings, we can iterate through them using foreach:

   1: foreach (var pilot in pilots)
   2: {
   3:   Console.WriteLine(pilot);
   4: }

So now we understand how to Select something but what would be really great, is if we could select a particular something. To do this is where we have to make use of the Where clause, again I will demonstrate both syntaxes.

The SQL like syntax:

   1: var pilots = from tieFighter in tieFighters
   2:     where tieFighter.Pilot == "Darth Maul"
   3:     select tieFighter;

And the equivalent would be:

   1: pilots = tieFighters.Where(n => n.Pilot == "Darth Vader");

As pointed out at the start this post has been dramtically cut down, I aim to publish something I bit more detailed soon.

SocialSafe

June 17, 2009

The company I work for, have just co-launched a great little tool for backing up your Facebook details. It’s called SocialSafe, and you can get it here.

Twitter Client

March 6, 2009

Not posted for some time. After a recent contract I’d lost the will to code.  Back in the zone now and looking forward to getting some posts up on the blog.

Myself and a college have decided to write our own Twitter client. OK so it’s not exactly original but having tried a few different clients recently I have to say I’m not really that impressed.

Plan is to post some items here about progress. The project will be agile and be developed completely test first. Cards will be created and managed using PivitolTracker.

Stay tuned for progress.

Self Organising Teams

November 10, 2008

In my opinion, one of the key concepts for any agile development project, is the idea of self organising teams. This concept is deceptively simple, and often badly implemented, or more worryingly ignored. Part of the power of agile development is developer by-in. When a developer feels in control, they will be more motivated, happier and crucially more productive.

During Sprint planning, developers agree to implement a set amount of work in a given time span. They have produced the estimates, and they have committed to the process. So it naturally follows that during the sprint, they must be allowed to determine how best it is for them, to undertake that commitment.

Micromanagement is the enemy of any self organising team, it stifles creativity and harbours resentment. That isn’t to say that developers can’t be guided along during the sprint but it must be just that, a guide.

Another advantage of allowing developers to manage what they do during a sprint, is that they are often the best people to make decisions at the coal face; they live there on a daily basis! They may have come across similar issues that they know instinctively how to tackle.

Obviously management want to be able to track progress during a sprint, and this is where scrums (daily progress meetings), burn down charts and card walls come into play. It’s through these mechanisms that management can understand current progress. It is incumbent on the developers to ensure that they communicate impediments quickly, and that management take these seriously, and move to remove them as quickly as possible.

Without developer by-in, any software project is at serious risk of failure. True some managers may be able to drag their team along by sheer force of will, but why bother when by simple empowering your team, they will probably end up carrying you on their shoulders.

Random LINQness!

September 11, 2008

This post was going to be longer but I decided to cut it down, mainly due to the fact that it has been sat in my drafts for about 6 months. So in teh end it’s a (very) short post about different LINQ to entity syntax, nothing to taxing but someone might find it useful.

As you may be aware LINQ provides various extension methods that allow you to perform query like operations (the ones we are interested in right now are Select, SelectMany and Where). This allows you to get data from any IEnumerable collection.

There are two syntaxes that you can use to get data from a collection.

The first is SQL like:

   1: var pilots = from tieFigher in tieFighters select tieFigher.Pilot;

Or using extension methods:

   1: pilots = tieFighters.Select(n => n.Pilot);

The second method uses the Select method which takes a Lamda Expression that allows us to specify what we want to select; in this case the Pilot. Both of these return the same result, and now that we have a list of pilot strings, we can iterate through them using foreach:

   1: foreach (var pilot in pilots)
   2: {
   3:   Console.WriteLine(pilot);
   4: }

So now we understand how to Select something but what would be really great, is if we could select a particular something. To do this is where we have to make use of the Where clause, again I will demonstrate both syntaxes.

The SQL like syntax:

   1: var pilots = from tieFighter in tieFighters
   2:     where tieFighter.Pilot == "Darth Maul"
   3:     select tieFighter;

And the equivalent would be:

   1: pilots = tieFighters.Where(n => n.Pilot == "Darth Vader");

As pointed out at the start this post has been dramtically cut down, I aim to publish something I bit more detailed soon.