Friday, 27 December 2013

How to solve the Rubik's cube

My kids got rubik's cubes for christmas this year, and the first thing I wanted to do was solve it for myself. I remember when I was a child, only being able to solve one face of the cube, and in the age of youtube I thought there may be a training video out there to show my how to solve all three levels of the cube. Sure enough a quick type into youtube search engine for Rubik's cube brought up these two great training videos.

Full solution

3rd level codes

For my reference I wrote down the codes for the 3rd level as follows


Wednesday, 18 December 2013

SQL Server Report Server Investigations

The following SQL will let you find the worst performing reports, and also the ones that error on your reporting services database instance.


          , E.Requesttype
           --WHEN 1 THEN 'Subscription'
           --WHEN 0 THEN 'Report Launch'
           --ELSE ''
          ,[TimeTotal (ms)] = DATEDIFF ( millisecond , E.TimeStart , E.TimeEnd )
     FROM Reportserver.dbo.ExecutionLog E (NOLOCK)
     INNER JOIN Reportserver.dbo.Catalog C (NOLOCK)
       ON E.ReportID = C.ItemID
--    WHERE C.Name = 'Project Full Control Comments'
and E.Requesttype = 0
and E.Status <> 'rsSuccess'

ORDER BY [TimeTotal (ms)] DESC

Wednesday, 11 December 2013

Altering the HTTP response using Fiddler

Should you ever have the need to change the http response to a web server, then please note in the latest version of Fiddler it's actually possible to do this without having to hack the CustomRules.js file that the Fiddler training videos and documentation tell you about.

You can simply set up an AutoResponder tab rule as follows

1. Stick a file in %userprofile%\Documents\Fiddler2\Captures\Responses folder

2. Highlight the request you want to set up a rule for

3. Got to the AutoResponder tab and check Enable automatic responses and unmagtched requests passthrough

4. Click Add rule

5. In the dropdown list control at the bottom, select the file that you dropped in the folder in step 1 above.

6. Hit the save button

7. Clear the Cache


Now next time you request that resource, the version you have saved on disk will be downloaded instead. You can check this by looking in the IE cache folder %userprofile

%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files

More detail about request and response breakpoints in fiddler here… (this is very useful should you wish to change the request going to the server in the first place as well)…

P.S. For more powerful / permanent debugging solution you can just alter the fiddler customrules.js as follows

static function OnBeforeResponse(oSession: Session) {

        if (m_Hide304s && oSession.responseCode == 304) {

            oSession["ui-hide"] = "true";


if (oSession.uriContains("Name=ViewerScript")) {




Monday, 9 December 2013

Using the DataContractSerializer to serialize and deserialize


To serialize a Business object marked with [DataContract] and properties marked with [DataMember] attributes…

public static string DataContractSerializeObject<T>(T objectToSerialize)


using (var output = new StringWriter())


using (var writer = new XmlTextWriter(output) { Formatting = Formatting.Indented })


var dataContractSerializer = new DataContractSerializer(typeof(T), EntityUtilities.GetAllKnownTypes(), int.MaxValue, true, true, null);

                    dataContractSerializer.WriteObject(writer, objectToSerialize);

return output.GetStringBuilder().ToString();




Then to deserialize back to your DataContract type, use this logic…

public static T Deserialize<T>(string xml)


using (Stream stream = new MemoryStream())


byte[] data = System.Text.Encoding.UTF8.GetBytes(xml);

                stream.Write(data, 0, data.Length);

                stream.Position = 0;

var dataContractSerializer = new DataContractSerializer(typeof(T), EntityUtilities.GetAllKnownTypes(), int.MaxValue, true, true, null);

return (T)dataContractSerializer.ReadObject(stream);



Thursday, 5 December 2013

Cross platform mobile development in C#

Microsoft Virtual Academy - ASP.NET MVC

I’ve just got into the Microsoft Virtual Academy, and I have to say it has a wealth of up to date, excellent training videos.

Razor syntax escape characters…


Html anti forgery token..

ASP.NET MVC 4 Content Map

Script including - always use the longhand version for the <script></script> tag, otherwise your script file will not be downloading to the client browser - a fantastic javscript, jquery, html and css online playground like and The nice thing about this one though is that you can download the entire finished article file as a single html page.

What's coming in ASP.NET -

Signed nightly builds of vnext -

Getting started with web api -

Web API 2 (video) -

Wednesday, 23 October 2013

Windows 8.1 USB installer and dual booting

Looks like Microsoft make the task dead simple for you now…

Although if you get into the trouble I had with GPT bios issues, then use this trick instead…

Also for all you need to know about dual booting between various flavours of Windows see here

EaseUS Backup Free here (for system imaging backups)

MyDefrag defragger to move MBT here

Thursday, 17 October 2013

No Cache Attribute in MVC

    using System;
using System.Web;
using System.Web.Mvc;
using RRA.Core.Services.Utilities;

/// Disables browser caching.

public class NoCacheAttribute : ActionFilterAttribute
/// Called by the ASP.NET MVC framework before the action result executes.

/// The filter context.
public override void OnResultExecuting(ResultExecutingContext filterContext)

Tuesday, 15 October 2013

My VS macros

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Public Module Module1
    'Empty routine that just causes VS to flush its memory to disk
    Sub ReleaseMemory()
    End Sub
    Sub RebuildDocumentationUpwards()
    End Sub
    Sub AttachToW3p()
    End Sub
    Sub AttachToLocalWebDev()
    End Sub
    Sub AttachToMyProcess()
    End Sub
    Sub AttachToMyProcessScript()
        AttachToProcess("MyProcess.exe", True)
    End Sub
    Private Sub AttachToProcess(ByVal ProcessName As String, Optional ByVal ScriptOnly As Boolean = False)
            Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
            Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
            Dim dbgeng(2) As EnvDTE80.Engine
            dbgeng(0) = trans.Engines.Item("Script")
            If ScriptOnly Then
                Array.Resize(dbgeng, 1)
                dbgeng(1) = trans.Engines.Item("Managed")
            End If
            Dim proc2 As EnvDTE80.Process2 = dbg2.GetProcesses(trans, System.Environment.MachineName).Item(ProcessName)
            Call proc2.Attach2(dbgeng)
        Catch ex As System.Runtime.InteropServices.COMException
            Select Case ex.ErrorCode
                Case -2147352565
                    ShowMessage(ProcessName & " is not currently a running process")
                Case -1989083106
                    ShowMessage("You are already attached to " & ProcessName)
                Case Else
                    ShowMessage("Unhandled error message from Attach to process macro")
            End Select
        Catch ex As System.Exception
            MsgBox("Unhandled exception occurred: " & ex.Message)
        End Try
    End Sub
    Private Sub ShowMessage(ByVal message As String)
        Call MsgBox(message, MsgBoxStyle.Exclamation, "Attach to process macro")
    End Sub
End Module

Wednesday, 9 October 2013

GOTCHA: The resurrection of TFS source control folders

Today we found something very interesting with Team Foundation Server (TFS) source control folder workflow. A colleague of mine had deleted a source control folder from TFS source control, but as I hadn't got latest on the parent folder, I was not aware that he had done this.

I was then able to add a script to this deleted folder, check in my change, and this had the implicit effect of undeleting the folder that my colleague wanted removed.

One to watch out for in case you don't always do a full get latest from the route of your source control project.

Wednesday, 18 September 2013

Preload Images with CSS, Javascript or Ajax

See here for many ways to achieve this...

Personally I'm sticking with the following...

Note the type check for array in this example is probably overkill, as it is for all browser versions, we could have used jQuery isArray instead, or even Array.isArray in ECMA script 5 (IE 9 or higher).

Wednesday, 28 August 2013

How to put back AirDroid 2.0.3 on Galaxy S2

  1. Force stop
  2. Move it to SD Card
  3. Uninstall

Then download the .apk from another device that's running the old 2.0.3 version, using airdroid against that device, apps, download button, and then install that on your Galaxy S2 again.

or just use the one here

All is good in the world again.

Note: The direct browser link to airdroid version 2.0.3 is now

Saturday, 24 August 2013

Plunkr Noughts And Crosses Game

Spent some time with my new favourite javascript online editor of the moment I've found I can use my tablet, an iPad and even a smart phone to edit my HTML using this editor, although most of the time it's done using Google Chrome on a laptop.

My daughter and I find this game is best played with two wireless mouse devices plugged into the laptop, and you take it in turns to move the pieces into the squares.

P.S. Some hidden gems in Plunkr are the keyboard shortcuts:

Ctrl+S = Save
Ctrl+Up/ Ctrl+Down = Cycle through files
Ctrl+Enter = Preview / Run your code

To run the game, click here:

To edit the code, feel free at this link:

Plunkr - Noughts and Crosses Game

Tuesday, 23 July 2013

Unit of work pattern in WCF

See here for an example of how to implement a unit of work pattern in WCF (using Unity).

public class CustomServiceHostFactory : ServiceHostFactory
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
return new CustomServiceHost(serviceType, baseAddresses);

public class CustomServiceHost : ServiceHost
static IUnityContainer _container;
static CustomServiceHost()
    _container = new UnityContainer();
    _container.RegisterType<ICompanyRepository, CompanyRepository>();
    _container.RegisterType<IUnitOfWork, DbUnitOfWork>();
    _container.RegisterType<SVCContext>(new ServiceInstanceLifeTimeManager());
public CustomServiceHost(Type serviceType, params Uri[] : base(serviceType, baseAddresses)
protected override void ApplyConfiguration()

public class UnityServiceBehavior : BehaviorExtensionElement , IServiceBehavior
IUnityContainer _container;
public UnityServiceBehavior(IUnityContainer container) : base()
    _container = container;
public void AddBindingParameters(ServiceDescription serviceDescription,
ServiceHostBase serviceHostBase,
Collection<ServiceEndpoint> endpoints,
BindingParameterCollection bindingParameters)
public void ApplyDispatchBehavior(ServiceDescription serviceDescription,
ServiceHostBase serviceHostBase)
Type serviceType = serviceDescription.ServiceType;
IInstanceProvider instanceProvider = new UnityInstanceProvider(_container, serviceType);
foreach (ChannelDispatcher dispatcher in serviceHostBase.ChannelDispatchers)
foreach (EndpointDispatcher endpointDispatcher in dispatcher.Endpoints)
        endpointDispatcher.DispatchRuntime.InstanceProvider = instanceProvider;
new UnitOfWorkMessageInspector(_container)
public void Validate(ServiceDescription serviceDescription,
ServiceHostBase serviceHostBase)
public override Type BehaviorType
get { return this.GetType(); }
protected override object CreateBehavior()
return this;

public class UnityInstanceProvider : IInstanceProvider
IUnityContainer _container;
Type _serviceType;
public UnityInstanceProvider(IUnityContainer container, Type serviceType)
    _container = container;
    _serviceType = serviceType;
public object GetInstance(InstanceContext instanceContext, Message message)
return _container.Resolve(_serviceType);
public object GetInstance(InstanceContext instanceContext)
return this.GetInstance(instanceContext, null);
public void ReleaseInstance(InstanceContext instanceContext, object instance)



public interface IUnitOfWork
void Commit();

public class DbUnitOfWork : IUnitOfWork
SVCContext _context;
public DbUnitOfWork(SVCContext context)
    _context = context;
public void Commit()


public class UnitOfWorkMessageInspector : IDispatchMessageInspector
IUnityContainer _container;
public UnitOfWorkMessageInspector(IUnityContainer container)
    _container = container;
public object AfterReceiveRequest(ref Message request, IClientChannel channel,
InstanceContext instanceContext)
return _container.Resolve<IUnitOfWork>();
public void BeforeSendReply(ref Message reply, object correlationState)

Friday, 24 May 2013

Icon editor for favicon in the web

Came across this in the book I'm reading at the moment, - rather clever little tool from Microsoft for creating the favicon for your website, for when users book mark it on their iPad / iPod or desktop PC.

Monday, 25 March 2013

Windows 7 Performance Boosting

20 Amazing Windows 7 Performance Boosting Tips In Under 10 Minutes!

Note: If you use the search facility in MS outlook, then ignore the step about disabling windows search service...

Friday, 15 March 2013

Logical fragmentation in SQL Server Indexes

My colleague Lawrence today discovered that a query we had that was taking over 2hrs to run (and still timing out), was due to a non clustered index being badly fragmented on the table in question.

To discover this fact he used the following queries, before rebuilding all indexes on the table, which then fixed the issue, and got the query coming back in 2 seconds.

--1. find index names
sp_helpindex 'dbo.MyTableName'

--2. show index logical fragmentation. Scan density should be above 97%
dbcc showcontig (MyTableName) WITH TABLERESULTS, ALL_INDEXES

--3. show when indexes were last rebuilt
Declare @dbid int
Select @dbid = db_id('Beacon')
Select objectname=object_name(i.object_id)
,, i.index_id
, o.create_date, o.modify_date
from sys.indexes i, sys.objects o
where objectproperty(o.object_id,'IsUserTable') = 1
--and i.index_id NOT IN
--(select s.index_id
--from sys.dm_db_index_usage_stats s
--where s.object_id=i.object_id and
--i.index_id=s.index_id and
--database_id = @dbid )
and o.object_id = i.object_id
and object_name(i.object_id)= 'MyTableName'
order by o.modify_date desc

Wednesday, 6 March 2013

WCF DataMember attribute issue

Got caught out by this issue today. Spent ages trying to find out why I was getting a WCF exception after adding the DataContract and DataMember attributes into my class, and it turned out I had a property that didn't have both a getter and a setter declared.


The error was simply reported as

System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue

Monday, 4 February 2013

BT Tampering with Epsom cabinet 53

Broadband from £5.99 a month with an included wireless router when you sign up to Plusnet - terms apply
It appears that the only people able to receive a fibre optic connection to the Epsom exchange on our estate are BT infinity customers. I've contacted my neighbours (all of whom registered interest around the same time on the web site), and it appears only those that are BT broadband customers were sent the "Fibre is now available email".
What's more strange is what appears to have happened with our cabinet (number 53). See below for pictures showing the old cabinet 53 that is now connected to a brand new shiny fibre cabinet, and you can clearly see the road having been dug up where the cable is lying that connects the old cabinet to the new one...
Cabinet 53 which serves all houses on our estate.
Cabinet 53 with road way dug up to connect new cabinet (see next picture)
New fibre cabinet
Note how the only people in our area reporting fibre optic speeds (i.e. greater than 8MB speed) are BT customers exclusively!
The only address that now lists as being able to receive broadband on our estate is the following one... (although somehow they're connected to cabinet 43).
What's even more strange is that customers that already have fibre connection with BT infinity are told that they can't have it, if they search using their postcode and house number (i.e. pretending not to be an existing BT customer), however if they search with their BT landline number, it comes up saying they can have fibre optic.
Note the picture below, where I have used my landline number on the left, and then the neighbour who already has BT infinity fibre connection on the right. Both of us are connected to Cabinet 53 as you can see...(click each picture below in turn)
NOTE: this web site has now been replaced by this one

Update: 05/02/2013 15:04:56
From: Neville @ BTSent: 05 February 2013 14:50
Subject: Re: Cabinet 53
Hi Merrick - please see below for update:-
OR have come back and confirmed the cabinet 53 has been temporarily withdrawn from service as “full”. Or have activity to look at increasing the capacity and once completed will open the cabinet for service. Cabinets are available to all SPs/CP on equivalent basis so whilst you may only see BTR users reporting this does not mean that other users are not using the cabinet they may simply not be reporting.

OR have not given an indication of how long it will be before the cabinet comes back into service.

Update: 08/02/2013 22:58
Seems that sometimes the little guy can get stuff done then. Fibre available now to us again on the 26th February 2013.

Update:26/02/2013 10:36:30: I am now officially a fibre customer. I have to say that the gulf of difference between their customer service and BT is finally what made my mind up on which provider to choose. (P.S. Fibre is now available to all on our estate via cabinet 53 again, as of this morning 26th Feb 2013).
Update: 02/03/2013 11:37: After ringing up about my order and letting them know that bt wholesale site are listing availability from the 12th March now, it appears that my Fibre connection is being put on hold for now.
Update: 12/03/2013 11:25: Checked this morning, and for some reason now the BT wholesale site is saying that there is no fibre available, and does NOT even list an availability date now!
I've kindly asked Neville at BT wholesale to look into this issue for me. Luckily he understands that people that are connected to this cabinet already have a fibre connection.
From: neville
Sent: 12 March 2013 15:37
Subject: RE: Epsom cabinet 53

Hi Merrick – we have received an update from our suppliers to advise that providing no issues this cab should be back up and running by the end of next week. I can only suggest that you continue to monitor and place order as soon as it becomes available. Cheers Nev
Guess I'm going to have to keep waiting then.
Update: 13/03/2013 10:37: Now showing next Tuesday 19th March. Let's hope this is the last of it.
Update 27/03/2013 13:45: James Moyse (BT Open reach engineer number 606415840) came today and connected me to fibre finally. Have to say James was excellent, and confirmed my suspicions that there are a finite number of ports in the cabinet, and that there was nothing needing to be done at the exchange today in order to get me connected.
So I've now officially gone from this...
to this...
Also just to confirm that I wasn't crazy, it turns out that there are a finite number of new patch boards connected to the new fibre cabinet, and that these are solely occupied by BT customers at the moment. I'm now officially a fibre customer connected to number 71 of 150, so just glad I got in there before they all run out!

Friday, 1 February 2013

How funny is that!

I wonder who left this endorsement on


Thanks Dzone!

Back when I used to blog for Conchango, someone once asked me why do I bother blogging. Well yesterday I received my free bundle package, which included a nice new T-Shirt, 8GB USB memory stick, and some toys for my kids amongst other things... ALL FREE!!! - So you see sometimes in life, you do get something for nothing.


It also included print outs of a couple of ref cards including this one that opened my eyes to HTML5 WebSockets...

The funniest part is the author @peterlubbers, who even has a number plate reading HTML5 in California...


Friday, 18 January 2013

<PRE> tags and white-space: pre style

When you need to preserve tab characters and line breaks within HTML elements other than multiline input fields, you can use the <pre> tag or the style attribute of white-space: pre.

Just noticed that there is a slight difference in using a <pre> tag and a div with the white-space: pre style attribute applied to it. As the default user agent setting for the font-family style attribute for a <pre> tag is mono


Found more of a description on this site...


Use Plunkr to test it out if you like....

<!DOCTYPE html>

  <head lang="en">
    <meta charset="utf-8">
    <title>Awesome Game</title>
  <pre>Test this wer awereaw
  <div id='content' style="white-space:pre">Content!

Thursday, 17 January 2013

Project Silk for all your HTML web application needs

A colleague of mine pointed out this white paper article that Microsoft have kindly put together, which appears to be a full overview on how to construct a web site in this day an age.

"Guidance for building cross-browser web applications with a focus on client-side interactivity. These applications take advantage of the latest web standards like HTML5, CSS3 and ECMAScript 5 along with modern web technologies such as jQuery, Internet Explorer 9, and ASP.NET MVC3"

You can also download it all in pdf format from the following link

Tuesday, 8 January 2013

Ctrl+Shift+WinKey+B in Windows 10

Ctrl+Shift+WinKey+B in Windows 10  This resets the graphics display on your laptop and can sort out lagging issues as well "Since yeste...