Posts

A generic singleton using Lazy< T >

Carring on from the generic singleton post here. Since we have .NET 4, we can now make use of Lazy public class Singleton where T : class, new() { private Singleton() {} private static readonly Lazy instance = new Lazy (() => new T()); public static T Instance { get { return instance.Value; } } }

Please turn off hyperlinks in PowerPoint

Image
When giving presentations, you should really turn off PowerPoints AutoCorrect feature of it changing a hyperlink into an underlined link. Unless you actually are going to click on the link during the presentation, then turn it off. It's much easer to read without it being in a different font and underlined. To turn it off in PowerPoint, goto Tools -> Options -> Proofing -> AutoCorrect options. Untick the box highlighted below.

Recursive CTE (Common Table Expression)

There is sometimes a problem of wanting to remove data (email addresses in this example) from within a string which are delimited. For example, if you want to remove all non bybox email addresses from "some.name@bybox.com; simon@hicrest.net; fred.bloggs@bybox.com" and do this for every table, without having to create functions to break apart the string first, how are you going to do it? Here's how: Our example table looks like this CREATE TABLE data_export ( data_export_id INT NOT NULL IDENTITY(1, 1) PRIMARY KEY, email_address VARCHAR(255) NOT NULL -- ... Other fields left out for brevity ) Insert some test data INSERT INTO data_export (email_address) VALUES ('some.name@bybox.com; simon@hicrest.net; fred.bloggs@bybox.com'), ('neo@matrix.com; me@bybox.com'), ('fred@b.com; xxx@bybox.com'), ('fred@bbc.com'), ('an.other@bybox.com') Next is the recursive CTE SQL is in several sections: spli...

C# 5 attributes on optional parameters

With C# 5, you can put a special attribute on an optional parameter and the compiler will fill in the value not with a constant but with information about the calling method. This means we can implement the Logger.Trace to automagically pick up where it’s being called from: public static void Trace(string message, [CallerFilePath] string sourceFile = "", [CallerMemberName] string memberName = "") { string msg = String.Format("{0}: {1}.{2}: {3}", DateTime.Now.ToString("yyyy-mm-dd HH:MM:ss"), Path.GetFileNameWithoutExtension(sourceFile), memberName, message); LoggingInfrastructure.Log(msg); } Now, if the caller calls Log.Trace("some message") the compiler will fill in the missing arguments not with the empty string, but with the file and member where the call happens: // In file called Fred.cs public void SomeFunc() { Log.Trace("Hello"); // Compi...

www.stilettos-sos.com

Image
I've created yet another WordPress CMS system for a friend of my wifes this time. Home page is a blog, the others are static pages. www.stilettos-sos.com

The real doomsday date is Tue Jan 19 2038 at 03:14:07

Some said it was the Y2K bug we had to worry about, but it's actually Tue Jan 19 2038 03:14:07 you've really to worry about. There are many, many systems built with time saved as a 32bit long integer value. The max value of a signed long integer is 2147483647. This value is the number of seconds elapsed since midnight (00:00:00), January 1, 1970, coordinated universal time (UTC) Here is an example C program, built with Visual Studio 2010. __time32_t t; t = 0; printf( "The min is %s\n", _ctime32( &t ) ); t = 2147483647; printf( "The max is %s\n", _ctime32( &t) ); t = 2147483648; printf( "The date is %s\n", _ctime32( &t) ); Output: The min is Thu Jan 01 00:00:00 1970 The max is Tue Jan 19 03:14:07 2038 The date is (null) So after Tue Jan 19 03:14:07 2038, the date goes to null which will cause a crash. Let's just hope all the critical (including embedded) systems get fixed before then.

PowerShell script to automatically clone/update all repos in Kiln

Image
PowerShell Script files Download the files here . Change and replace the following url Change https://your fogbugz root url to be your root url for fogbugz. For example, if your companies fogbugz url is something like https://secure.bbc.com/FogBugz/default.asp, then your root url will be https://secure.bbc.com Obtaining a Kiln Token The first thing you need to do before you can use this script is to obtain a Kiln token. Copy and alter the following link in your browsers URL https://your fogbugz root url/FogBugz/api.asp?cmd=logon&email=[yourEmail]&password=[yourpassword] Changing the text in square brackets (and also removing the brackets). You should receive something like this: ymjt123f8882a6s7td0j8eefa6u2g8 Take the token text: ymjt123f8882a6s7td0j8eefa6u2g8 and paste it into the powerShell script (edit your local copy instead of the SVN one) Running the script Start PowerShell and run the script passing in the root path of your Kiln repos. Will it clone every...