Add editable column headers to handsontable

I am using Handsontable in some of my projects at work. One of the requirements I had to implement recently was the ability to enter custom header values. Fortunately the developer of Handsontable did a very good job on documentation, so it was not as hard as I thought.

First step is to define a function for the colHeaders property. The function returns the HTML code for an input element, which gets the initial value of an array that contains the original values of the data.

var colHeadings = ['', 'Maserati', 'Mazda', 'Mercedes', 'Mini', 'Mitsubishi'];
var data = [
    ['2009', 0, 2941, 4303, 354, 5814],
    ['2010', 3, 2905, 2867, 412, 5284],
    ['2011', 4, 2517, 4822, 552, 6127],
    ['2012', 2, 2422, 5399, 776, 4151]
container = document.getElementById('example'),

hot = new Handsontable(container, {
    data: data,
    colHeaders: function (index) {
        var textbox = '<input type="text" value="' + colHeadings[index] + '" />';
        return textbox;

The result looks like this:

What I don’t like so far is the fact, that the whole column gets selected if the textbox is clicked. To deactivate this behavior I needed to implement another function for the event afterOnMouseDown inside the Handsontable constructor:

afterOnCellMouseDown : function(sender, e){
    if (e.row === -1)


You can find the complete example on jsfiddle and play around with it:

SSAS: A connection could not be made to the data source

I got the following error message, when I was trying to process an Analysis Services cube on my development machine:

Errors in the high-level relational engine. A connection could not be made to the data source with the DataSourceID of ‘xxx′, Name of ‘yyy′

The error message is not very meaningful. To resolve the issue you should check the impersonation settings of the datasource and specifiy an appropriate Windows account:


Concatenating values from multiple rows with T-SQL

Today I had the problem that I needed to concatenate values of a column from multiple rows of a table. I was developing a report for SQL Server Reporting Services and the data source was a SQL Server Database. So I ended up using T-SQL with the special FOR XML PATH – Command. The FOR XML command is used with T-SQL to format the results of a query as XML.

The following table contains a list of some car manufacturers:


To get a comma separated list of manufacturers I can take the following T-SQL statement:

   1:  SELECT STUFF( (SELECT ',' + Manufacturer From CarManufacturer FOR XML PATH('') ), 1, 1, '') as 'Car Manufacturers'


The result looks like this:


Reducing Size of VirtualBox Harddisks

VirtualBox is my favourite tool for virtualising my systems. To save diskspace on my physical machine I am using dynamic harddisks. In this case the VDI file is allocating necessary space when it needs it. Once the space was used it is not being freed in an automatic way. So you have to do this by hand. Just follow the steps below:

1. Start your virtual machine
2. Zero out free space inside your virtual machine. Under Windows you can do this with SDelete
Just run the following command with [driveletter] replaced by the drive (i.e E:) you want to free.

sdelete -c [driveletter]

3. After the command has completed shut down your virtual machine
4. Run the following command on your host. [vdifilename] has to be replaced by the full path of the VDI you want to compact.

VBoxManage modifyvdi [vdifilename] --compact

VBoxManage is located inside your VirtualBox installation folder.
Depending on the size of your VDI file the command can take several minutes to complete.

JustMock: Returning null in unit tests

Sometimes it is necessary to return null inside a unit test. JustMock has its own style doing this. Take a look at the following method:

public string GetUsername(Guid userId)
  User user = UserRepository.GetUser(userId);
  string username = string.Empty;
  if (user != null)
    username = user.Username;
  return username;

If you want to test that the method returns an empty string if no user is found inside your repository, you have to arrange that your mocked repository returns null.

The testmethod should look like this:

public void GetUsername_Returns_Empty_String_If_User_Not_Found()
  IUserRepository userRepository = Mock.Create<IUserRepository>();
  Guid userId = Guid.NewGuid();
  Mock.Arrange(() => userRepository.GetUser(userId)).Returns(null);

  UserManager userManager = new UserManager(userRepository);
  string username = userManager.GetUsername(userId);

The code won’t compile, because the line

Mock.Arrange(() => userRepository.GetUser(userId)).Returns(null);

throws an error.

The correct way would be

Mock.Arrange(() => userRepository.GetUser(userId)).Returns((User)null);

– or –

Mock.Arrange(() => userRepository.GetUser(userId)).Returns(() => null);

Subversion: Restoring db/current

Today I had a strange issue when I was trying to update a working copy of my Subversion repository. The /db/current file was missing for some reason and therefore any subversion related operation was not possible. After querying Google I found a blog post, that offered a very simple solution without restoring from a backup:

svnadmin recover <PathToRepo>

The command took a while, but when it finished the current file was recreated and my repository was intact. I have to mention that this is only working for repositories with version 1.5 and above.

HOWTO: Order generic collections with LINQ

To order collections in LINQ you can use the extension method OrderBy(), which can be found in the static class Sytem.Linq.Enumerable. It can be used in all types of collections that implement the interface System.Collections.Generic.IEnumerable. The following example orders a list of Person objects by their age.

List persons = new List();

persons.Add(new Person("Peggy", "Bundy", 39));
persons.Add(new Person("Doug", "Heffernan", 34));
persons.Add(new Person("Tim", "Tailor", 41));
persons.Add(new Person("Homer", "Simpson", 34));
persons.Add(new Person("Al", "Bundy", 41));

persons = persons.OrderBy(person => person.Age).ToList();

Heffernan, Doug (34)
Simpson, Homer (34)
Bundy, Peggy (39)
Tailor, Tim (41)
Bundy, Al (41)

The person class is quite simple:

public class Person
    public int Age { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }

    public Person(string firstName, string lastName, int age)
        FirstName = firstName;
        LastName = lastName;
        Age = age;

    public override string ToString()
        return string.Format("{0}, {1} ({2})", LastName, FirstName, Age);

If you want to order the persons also by their last name you can use the extension method ThenBy(). It has to be appended at the end of the OrderBy() method.

persons = persons.OrderBy(person => person.Age).ThenBy(person => person.LastName).ToList();


Heffernan, Doug (34)
Simpson, Homer (34)
Bundy, Peggy (39)
Bundy, Al (41)
Tailor, Tim (41)