Matching in a comma-separated list with Regular Expressions

Tonight’s quiz:
How to see if ‘foo’ is a unique entry in comma-separated list ‘foo,bar,foobar,foo,foo’?

We want to match the ‘foo’ at the beginning, at the end, and also in the middle, but not as part of the word ‘foobar.’ Also the comma-separated list might only be ‘foo’.

First attempt:

Plain wrong, because ^ means something different inside a set

Second attempt:

Works, but clunky.

Third attempt:

Works perfectly. Especially when you remember to escape the ” in your .NET string assignment ๐Ÿ™

Thanks to the Rad Software Regular Expression Designer too!

Visual Studio Stops Recognising Mouse Input

The shine is starting to wear off Visual Studio 2010 Professional for me. Recently the IDE has started to hang, in a rather strange way. The code editor still appears to respond to mouse events, but nothing actually happens. E.g. you can highlight some code, right mouse click and choose copy from the context menu, but then when you come to paste, nothing happens. Or you’ve been coding away, and you see the file name has an asterisk against it, so you hit ‘Control+S’ to save, but nothing happens. And the only way you can save your changes is by closing the file – at this point VS prompts you if you want to save.

This seems to be something that others have noticed, certainly in the Beta:

One of the tips is to uncheck the ‘Enable the Visual Studio hosting process’ checkbox in Project Properties > Debug pane – and this seems to have fixed it for me.

This is not very impressive. I’ve used all of the previous .NET editions of Visual Studio, and never seen this kind of stuff before.

Parser Error Message: Could not load type

Have been wrestling with the ‘Parser Error Message: Could not load type’ error for the past day and a half.

Plenty of people on Google having the same problem – it turns out my version of this problem was caused by a rather subtle mistake.

The directory structure in my web site is as follows:

I had duly configured app_directory to be an Application Virtual Folder in IIS, and was getting the Parser error every time I opened the following URL:

Before I got as far as the Parser Error Message, I was getting another message:

“It is an error to use a section registered as allowDefinition=’MachineToApplication’ beyond application level” – this error message pointed to the line:
<authentication mode=โ€noneโ€>

I got round this error by removing the node from web.config – but really this was pointing to the solution.

The URL I should have been accessing was:

I had gotten confused between the physical location of the folder on the server, and the path in the URL. Because the ‘dir1’ folder actually existed, IIS was still able to serve up the URL, including any test HTML pages I placed in the directory, but it did not consider it to be the Virtual Application Folder, and thus I was unknowingly breaking all sorts of rules.

Not sure what I could have done to spot this earlier – and I guess I take back what I was saying about Microsoft at midnight last night. Or some of it, anyway.

Windows Live Messenger, IE and Hotmail

Here’s something that’s been winding me up for ages. Whenever I access my Hotmail account through Internet Explorer, it launches Windows Live Messenger. I spend half my day shutting it down in my system tray.

Finally have found out how to turn the blooming thing off – it turns out it is not something you can do through Messenger options at all:

To my mind this is poor usability – isn’t the ‘Hotmail launches Messenger’ option something you’d expect to either be in Hotmail or Messenger?

BCP – Collation woes

Spent a long time trying to get data from one instance of SQL Server to another with BCP. Couple of things I learnt along the way:

1. SQL_Latin1 _General_CP1_CI_AS v. Latin1 _General_CP1_CI_AS

May as well be Latin v. Russian as far as BCP is concerned. Was unable to import data from a Latin1 _General_CP1_CI_AS column into a SQL_Latin1 _General_CP1_CI_AS column. Banged my head against the wall for a good while on this, until eventually just manually set the collation on each column in the target database to match the source.

2. Identify columns

Because my identity values had a few gaps in in one table, the master-detail relationships became jumbled up, and the data was no longer consistent. Worked around this by inserting some dummy rows in the BCP files so that there was a row for every identity column.

Since I had deleted all of the rows in the target table after a failed attempt at importing, also needed to reset the seed. Which is straightforward:

DBCC CHECKIDENT (TableName, reseed, 0)

This means that when you use BCP to import, the first value will be 1, and so on.

LARGE() function and rows with same rank

A finesse you can apply with the LARGE() function is to consider the case where you have rows with the same value, e.g:
1 James
3 Fred
2 Ian
1 Graham
3 Nigel

The LARGE(A1:A5,1) function will simply tell you that 3 is the largest value. But you may actually want the top three rows, e.g. to return the set (Fred, Nigel, Ian)

The way to achieve this is to add some unique key value to each ranking value so that they become distinct. In the example above, we could create a new column with value as follows:

This will then give us:
1 James 1.000001
3 Fred 3.000002
2 Ian 2.000003
1 Graham 1.000004
3 Nigel 3.000005

If we run the LARGE() function against Column C, we now have our unique values, which we can then feed into a VLOOKUP to return the person’s name.

ADODB Connection Object

Was banging my head against the wall a bit tonight trying to close my ADODB.Connection object down cleanly. My mistake was writing something like the following:

If Not objConnection Is Nothing Then objConnection.Close

It seemed that objConnection was both not nothing, and throwing an error about already being closed.

Solution was to check the State property first, so now I have:

If objConnection.State <> adoStateClosed Then objConnection.Close

Ubuntu Server on VirtualBox

Just got an Ubuntu LAMP server running on VirtualBox. Bought the disk image from TradeBit, which turned out to be a good move, as the chap selling the image was incredibly helpful. Talked me through various tweaks to get me up and running which I would basically have never found (No PAE support? Resetting DHCP client?)

But now, I have a little Ubuntu server running on my Windows machine! I managed to set up port forwarding under my own stream, and also installed a Gnome GUI layer, Firefox and Webmin. I can browse to it from my Windows host, and am now all set to start a WordPress site development exercise without needing to be online.

I think this is the first time I’ve had an ‘aha’ moment with Linux. I’ve had a go through the years, but never managed to get the OS running, for one reason or another. Particularly enjoyed the GUI package manager that gives me a whole universe of softare to choose from and install in an apparently reliable way.

Here’s the VDI image, in case you are interested:–ubuntu-8-10-server-lamp