Wednesday 26 December 2007

Recession? --Bah, humbug!

My take on the conversation about Britain following the US into recession is that ours is a very different economic situation to that of our cousins on the other side of the pond.

American house prices fell because the American housing market had more houses for sale than house buyers with money were creating demand for. Building and planning laws in the US are a lot different to those in the UK so when people over extended themselves to buy houses they couldn't afford and were unable to make the mortgage payments the market became saturated and prices dropped and the whole vicious cycle of bankruptcies ensued.

In the UK, our situation is more of a correction. We too had lots of people buying houses they couldn't afford, so that when interest rates rose, a few camel's backs were broken. The difference here is that when these properties were returned to the market, they were snapped up by investors who still had deep pockets.

UK house prices are not about to drop, they are going to continue rising. We still don't have enough housing on the market and that isn't about to change quickly. As long as that's true (and I predict it will remain true for a few decades still), home owners can rest assured that their investment is safe. Meanwhile all those folks who fell off the ladder are about to get some hard knocks schooling about buying a house they can afford.

Friday 21 December 2007

Self certifying your IIS 6 website for SSL

Every time I need to enable https / ssl for a development or staging server I spend 30 minutes googling for instructions. Now I'm blogging just to remind myself how it's done:

Install the IIS 6 Resource Kit referenced at:
http://support.microsoft.com/kb/840671 from:
http://www.microsoft.com/downloads/details.aspx?FamilyID=56fc92ee-a71a-4c73-b628-ade629c89499

Obtain the site Id of the website you want to install the certificate for by clicking on the Web Sites major heading in the left hand side of the IIS admin tool and view the "Identifier" on the right hand side for whichever site you need. This is the site ID. further instructions at: http://weblogs.asp.net/owscott/archive/2005/07/29/421058.aspx

Run the following command replacing www.example.com with the host header of your site and 123456 with the site id obtained in the previous step (the /V:365 indicates that the certificate should be valid for 365 days, adjust accordingly):
"C:\Program Files\IIS Resources\SelfSSL\selfssl.exe" /T
/N:CN=www.example.com /V:365 /S:123456

Thursday 12 July 2007

Postcode Validation Regex

Validating postcodes in .Net has a couple gotcha's. The default behaviour for the RegularExpressionValidator is to perform case sensitive validation so I've modified a regex by Chris Applegate to suit my needs.
([Gg][Ii][Rr] 0[Aa][Aa]
|[A-Pa-pR-Ur-uWwYyZz][A-Ha-hK-Yk-y0-9][A-Ha-hJjKkSsTtUuWw0-9]?
[AaBbEeHhMmNnPpRrVvWwXxYy0-9]?
\s[0-9][AaBbD-Hd-hJjLlN-Un-uW-Zw-z]{2})

Saturday 9 June 2007

Mono is maturing!

I have a simple .Net 2.0 project on the go at the moment that uses a web application project, a web service application project, the MySql connector and some C# class libraries that take advantage of generics. I decided to give MonoDevelop another whirl and have been pleasantly surprised with the results.

Importing the sln and csproj files works but you lose the debug automation. It's just a case of some missing lines in the project files but I opted to create a blank mds solution and associated mdp projects using the MonoDevelop templates. The result is that running a debug fires up xsp2 so that you can see your web and web service output.

There's a minor glitch in mono-xsp2 for Debian and Ubuntu where the preinstall script run by the package manager barfs on a syntax error. I had to open up the deb and fix the script, repackage and reinstall with dpkg. I would upload my fixed deb, but I reckon it'll be fixed upstream before anyone else notices. I found the information to do this at these url's: maebmij.org/~jim/ synthesize.us

The result of this bit of phaffing is that it's rather simple to create multi platform web projects in .Net without a great deal of dependency installs. Yay for mono!

The code and solutions I've mentioned here are available at: http://code.google.com/p/nimble/

Saturday 5 May 2007

camelCase in C# and the CLR

I want to address the issue of differentiating private fields from public properties using case alone. Everyone knows that the subject is a matter of preference and everyone has a strong argument to support their preference.

My favourite comment on this debate comes from an observer of Brad's series on the Framework Design Guidelines at http://blogs.msdn.com/brada/archive/2005/10/28/486215.aspx .

Ahh, I had gone almost a week without a good Case Sensitivity Holy War. I do love to watch the monkeys fling poo. I feel supporting case insensitive languages is important because it helps give this whole debate even more room to blaze. -Shawn Oster

On a more serious note,
  • The point of differentiating by more than case is CLR compliance.
  • CLR compliance provides interoperability between programming languages within the framework.
  • The rule is that publicly accessible properties must differ by more than case in order to disambiguate references or calls between assemblies on accessible API's.
A private field cannot be accessed by another CLR language. There is therefore no requirement to disambiguate by more than case because no language that would be confused by case sensitivity can access the field in question.

It is my experience that the issue of adding an underscore before private fields usually comes about after a rule in a default code analysis policy file is violated and it barfs an error about CLR compliance. The policy file is at fault, not the code. The policy should first have examined the accessibility of the field in question.

Microsoft's standard internal policy is to use camelCase for private fields and PascalCase for publicly accessible properties (http://blogs.msdn.com/brada/articles/361363.aspx - 2.6 Naming). This is not a violation of the CLR. Furthermore, it makes for far more elegant code.
Consider the following comparison. Underscores are just butt ugly:

private string myString;
public string MyString
{
get { return myString; }
set { myString = value; }
}
------
private string _MyString;
public string MyString
{
get { return _MyString; }
set { _MyString = value; }
}

Please don't make me use underscores...

Thursday 3 May 2007

Do recursive things from the command line

Ever wanted to recursively delete all files of a particular type from the command line or a script? Linux gives you lots of options for this and it turns out so does the cmd prompt. Try this for removing html files from a folder tree on Windows:
C:\>for /d /r "C:\My Clutter\And Chaos" %v IN (*) DO del "%v\*.html"
You've probably noticed that you can amend this line to run any command your mischievous mind can conjure.
  • The for obviously gives you your recursion
  • The /d gives you a directory listing
  • The "C:\My Clutter\And Chaos" is your working directory
  • %v is the variable that will capture the output of your directory listing
  • Everything after DO is the command that gets run for each variant of %v
Enjoy your new power...

Tuesday 1 May 2007

ASP.Net Generic Recursive FindControl

I was attempting to find a nested control on my page today and realised that the built in FindControl is useless for this. A bit of googling turned up a post by Eric Porter and a neat little function he'd written to solve the problem.

Mine has the same signature but actually works. :P
public static T FindControl(ControlCollection controls, string controlId) where T : class
{
T found = default(T);
int i = -1;
while ((controls != null) &&amp; (found == null) && (++i < found =" ((controls[i]" id ="="">(controls[i].Controls, controlId);
}
return found;
}

Sunday 29 April 2007

MonoDevelop

I want to use mono for a hobby CMS project I'm working on because I intend to open source the product and I'd like for it to be compatible with Linux hosting. MonoDevelop has made slow but steady progress over the couple of years I've been downloading it and abandoning the projects I create with it. But the 0.13.1 release has actually made the platform useable for me. The ASP.Net implementation can handle Web Application Projects with Generics, Serialization, Web Services and lots of the other tricks VS 2005 users take for granted.

I shall update this post as OpenShowCase evolves and highlight the adequacies and inadequacies of the Mono platform for a developer thats used to having all the toys.

I work off several development machines depending on whether I'm on my lunch hour, at home or in a hotel so I need both the IDE and source to be available wherever I am. My laptop runs Ubuntu and my PC at home runs Debian so I just added Mirco Bauers Debian repository to both apt sources (deb http://debian.meebey.net/ ./).

As it's a non-standard repository you also need Mirco's PGP key:
gpg --keyserver hkp://wwwkeys.eu.pgp.net --recv-keys 0x7127E5ABEEF946C8
gpg --export -a 0x7127E5ABEEF946C8 | apt-key add -
apt-get update && apt-get install monodevelop monodevelop-versioncontrol kdesvn
I haven't tried to get MonoDevelop working on Windows yet but I'll update this when I have.

For source control I've used subversion and taken advantage of Google's code and project hosting. The version control plugin for MonoDevelop works well but has a problem with adding a newly created solution to an existing repository. The same problem appears to affect kdesvn so the simplest thing to do is just create the code.google.com repository and use the command line client to make the first commit. From the console change to the directory that you keep all your projects in and enter the command below:
svn checkout https://.googlecode.com/svn/trunk/ openshowcase --username 
Afterwards the plugin seems to work fine.

Friday 27 April 2007

Localisation in .Net

I'm all fired up at the moment about integrating localisation for a major on-line retailer in the UK. Implementation seems to be another religious debate among those who have an opinion but the business constraints of our clients can sometimes simplify our options.

My choices were to use the built-in functionality in framework 2.0 or go find another job. So now, I'm working hard on moving the resource repository into SQL server and rolling a custom ResourceProviderFactory that uses the database (instead of resx files) to store my localised strings.

The first bit was pretty straight-forward. Google is my friend and I found some great resources and examples on the web.

You would think that the technology is old enough now that it would be simple to roll a robust solution but I can't seem to find any examples that implement IDesignTimeResourceWriter and DesignTimeResourceProviderFactory. My research leads me to believe that these classes are the key to making Visual Studio's "Generate Local Resource" tool work it's magic on my string repository instead of its native resx repository. So I'm rolling my own. It's a work in progress and I don't have any reason to believe it works but the code is here.

Tuesday 27 March 2007

Google Account Security

I think that everyone who makes heavy use of Google services would agree that losing control of their Google account would constitute a serious breach of privacy. I came within a click of losing my account to an opportunist.

Recently another gmail user with a similar name attempted (and failed) to reset the password of my gmail account. He then attempted to add my email address as a secondary address for his account. At this point Google sent me an email in Dutch prompting me to click a link which would have given this other user complete access to my email and Google account. I don't speak Dutch so I used an online translator to check the message from Google. If I had been feeling tired or lazy, I might have clicked some of the links in the message to try and work out what it was about.

Surely, correspondence from Google to its users should be in the language of the account holder, not the language of the account hijacker!

Thursday 18 January 2007

What the hell is a "Field Class"

So, I've been plotting the great escape from England since, well, about 10 minutes after I got here. Someone emailed me about a Job in Singapore with an investment bank and I got all excited. Earlier in the week I had a telephone interview at rise-and-shine 7 o'clock in the morning with the development manager of said investment bank and his big dot net question was "explain what a field class is". ?@!!!. I've never heard of it and I went with an admission of the same while suppressing the urge to try and sell a bag of blag.

He was a friendly bloke and said that it was "a class that could not be inherited". I just mumbled a bit and we moved on. Today I got the dreaded we'll-keep-your-cv-on-file letter and decided to do some research on this bastard "field class" that actually is a type of goo that prevents you from leaving England as opposed to an uninheritable code block.

The font of all knowledge that is Google, says a field class is many things but no reference to uninheritable code could I find. And since you've arrived at this post as a result of a Google search for the meaning of "field class" let me definitively explain, once and for all, that a field class is a very sticky goo that keeps you in England. Q.E.D.

Update: thanks smartass, I now realise he was talking about a sealed class...

Wednesday 17 January 2007

Contracts and Commitment

Are blogs places where you rant about your pet hates? No? Well, you know what really grinds my gears? I know you don't really want to know but I'll tell you anyway. Contracts. Long term commitments to pay money for something I don't really know if I'll want in a couple months time. I'm an impulsive character by nature and sooner or later any commitment I've made comes back to bite me in the rear.

My mobile is pay and go. I don't want to be paying 35 quid a month to shout into an outdated brick that has the battery life of a celebrity marriage.

In the UK there are some things you just can't have for love or money, without a contract. And at the top of the list is gym membership. Now who wants to be committed to that beyond January 5th? Nobody, that's who. Oh, and fit people. But I'm not nobody and I'm certainly not fit. So when my wife's sister said she'd take over my membership contract I was laughing all the way to the bank. I mean telephone. Only there are some contracts you can't get out of and you guessed it, my gym membership is one of those. I've decided that corporations who don't let me do what I want are victims of Borg assimilation. And since there's no recourse for someone who's put there name on a Borg contract, I resort to the last refuge of the consumer who screwed himself. Yes, complaining online, as noisily as possible.