Using a Git repository with an existing Heroku app

You can  take an existing Git repo and add a remote using the git URL provided when you created your app. You may need to do this to associate a Git repository with an existing application.

The Heroku git:remote command will add this remote for you based on your applications git URL.

heroku git:remote -a myApp
Git remote heroku added.


George Square, Glasgow – 19th September #throughglass

I was working late at our St. Vincent Place HQ on the day after the referendum and heard some noise down at George Square with Google Glass so I went down to investigate and got the following footage…

T-SQL script for identifying deadlocked processes

A useful script for identifying SQL deadlock cause/victim.

WITH [Blocking]
AS (SELECT w.[session_id]
 FROM [sys].[dm_os_waiting_tasks] w
 INNER JOIN [sys].[dm_exec_sessions] s ON w.[session_id] = s.[session_id]
 INNER JOIN [sys].[dm_exec_requests] r ON s.[session_id] = r.[session_id]
 CROSS APPLY [sys].[dm_exec_sql_text](r.[plan_handle]) q
 CROSS APPLY [sys].[dm_exec_query_plan](r.[plan_handle]) p
 WHERE w.[session_id] > 50
  AND w.[wait_type] NOT IN ('DBMIRROR_DBM_EVENT'
SELECT b.[session_id] AS [WaitingSessionID]
      ,b.[blocking_session_id] AS [BlockingSessionID]
      ,b.[login_name] AS [WaitingUserSessionLogin]
      ,s1.[login_name] AS [BlockingUserSessionLogin]
      ,b.[original_login_name] AS [WaitingUserConnectionLogin] 
      ,s1.[original_login_name] AS [BlockingSessionConnectionLogin]
      ,b.[wait_duration_ms] AS [WaitDuration]
      ,b.[wait_type] AS [WaitType]
      ,t.[request_mode] AS [WaitRequestMode]
      ,UPPER(b.[status]) AS [WaitingProcessStatus]
      ,UPPER(s1.[status]) AS [BlockingSessionStatus]
      ,b.[wait_resource] AS [WaitResource]
      ,t.[resource_type] AS [WaitResourceType]
      ,t.[resource_database_id] AS [WaitResourceDatabaseID]
      ,DB_NAME(t.[resource_database_id]) AS [WaitResourceDatabaseName]
      ,b.[resource_description] AS [WaitResourceDescription]
      ,b.[program_name] AS [WaitingSessionProgramName]
      ,s1.[program_name] AS [BlockingSessionProgramName]
      ,b.[host_name] AS [WaitingHost]
      ,s1.[host_name] AS [BlockingHost]
      ,b.[command] AS [WaitingCommandType]
      ,b.[text] AS [WaitingCommandText]
      ,b.[row_count] AS [WaitingCommandRowCount]
      ,b.[percent_complete] AS [WaitingCommandPercentComplete]
      ,b.[cpu_time] AS [WaitingCommandCPUTime]
      ,b.[total_elapsed_time] AS [WaitingCommandTotalElapsedTime]
      ,b.[reads] AS [WaitingCommandReads]
      ,b.[writes] AS [WaitingCommandWrites]
      ,b.[logical_reads] AS [WaitingCommandLogicalReads]
      ,b.[query_plan] AS [WaitingCommandQueryPlan]
      ,b.[plan_handle] AS [WaitingCommandPlanHandle]
FROM [Blocking] b
INNER JOIN [sys].[dm_exec_sessions] s1
ON b.[blocking_session_id] = s1.[session_id]
INNER JOIN [sys].[dm_tran_locks] t
ON t.[request_session_id] = b.[session_id]
WHERE t.[request_status] = 'WAIT'

Engaging Business Customers with Mobile in 2014 – Apps vs. Mobile Websites

When we started the process of delivering a business mobile application to our customers, we asked ourselves a fundamental question which has haunted development teams and project managers for many years now; should we go native or mobile web in our development approach and, more importantly, why do we have to make this decision in the first place?

To answer this question, we first looked at the consumer market for trends. A recent report by Flurry shows that consumers only spend 20% of mobile time on websites. The remainder is spent in mobile applications such as social networking and games.  Businesses however are showing the complete opposite trend. A 2013 Forrester report reports that almost 60% of companies surveyed stated that developing a mobile experience for customers was a high priority, but just 44% reported that they were focusing on a mobile app, with a whopping 56% opting for a mobile-optimised version of their current system.

A link between consumer and businesses trends

We can see from the surge in BYOD and BlackBerry’s recent dip in market share that business users want to use familiar tools at work.  We also know that mobile, fixed-line and IT operate differently and learned from our customers that technological expectations of staff in this market sector are higher. Despite implementing responsive design in our application, we found that they wanted their data to be closer and more convenient.  Users have been spoiled by the benefits of ‘now’ apps which don’t require login or navigation and present the data you need instantly.  Digital banking apps are a great example of this; many of the app features like being able to log in and stay logged in for easy access to your account information, having a screen code to keep it secure, and being able to transfer money easily, things that are only possible because we’re able to tap into the device’s native features.

A paradigm “nudge” – the best of both worlds

Proper design & build of mobile applications requires significant investment in time, money and resources which may lead many a development team to come to the conclusion that a single, responsive website, built on HTML5, may be a viable alternative to a native applications.  There was a time when many developers thought HTML5 would completely eliminate the need for mobile apps, with industry experts telling us that we’ll forget the day we ever wrote native apps. However, in an interesting twist of fate, HTML5 is actually being used a tool for cross-platform native app development. In fact, it’s now the number one choice for developers building apps for multiple platforms. Tooling like PhoneGap and Telerik’s App Builder are leading the way in turning HTML5 and JavaScript into usable cross-platform apps using Apache Cordova– "a platform for building native mobile applications using HTML, CSS and JavaScript.“

Why is mobile engagement increasing and which approach should I take?

For experienced business users, apps are more engaging because they utilise more of the built-in capabilities of your smartphone or tablet.  For now, it’s important to offer both options to users, because mobile apps and mobile sites are different tools for different tasks. But as more and more device options and development platforms become available, it’ll  be interesting to see how the consumer vs. business usage stats change.

The SSE Hydro Arena, Glasgow – Photo & Video Timeline

24 September 2013


24 September 2013

24 September 2013

24 September 2013

24 September 2013

24 September 2013


14th September 2013

28th August 2013

17th July 2013

9th June 2013

25th May 2013

20th May 2013

23rd February 2013

13th October 2012

13th October 2012

14th September 2012

1st June 2012

6th April 2012

6th April 2012

3rd February 2012

6th November 2011

Interior – 13th August 2013

Handling Unauthorised Ajax Requests in ASP.NET MVC App

The following post describes an application-wide method of handling unauthorised Ajax posts within an ASP.NET MVC application.

Modifying the Authorize attribute as per the example below shows how HandleUnauthorizedRequest can be overridden, returning a Ajax401Response when using Ajax. You’re then able to intercept all requests using jQuery and process them accordingly.

Custom Authorize Attribute

using System.Web;
using System.Web.Mvc;
namespace MyApplication.Attributes {
/// Custom authorisation attribute to return 401 request when Ajax request posted and user session has expired
public class AjaxAuthoriseAttribute: AuthorizeAttribute {
private class Ajax401Response: ActionResult {
// Called by the MVC framework to run the action result using the specified controller context
public override void ExecuteResult(ControllerContext context) {
context.HttpContext.Response.StatusCode = 401; // The request requires user authentication
context.HttpContext.Response.Write("Please log out and back in again to continue"); // HTTP response

/// Overriding AuthorizeCore as an entry point for custom auth from base controller
/// The HTTP context, which encapsulates all HTTP-specific information about an individual HTTP request.
protected override bool AuthorizeCore(HttpContextBase httpContext) {
if (!_authorisable) // When _authorise is false, don't perform authorisation
return true;

var result = base.AuthorizeCore(httpContext);

return result;

/// Encapsulates the information for using AuthorizeAttribute. The filterContext object contains the controller, HTTP context, request context, action result, and route data.
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) {
if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest()) {
filterContext.Result = new Ajax401Response(); // return 401 - unauthorised
} else base.HandleUnauthorizedRequest(filterContext);

private readonly bool _authorisable;

public AjaxAuthoriseAttribute() {
_authorisable = true;

// AjaxAuthorise can be turned on in any base controller if required
// Switch it off with this constructor
public AjaxAuthoriseAttribute(bool authorisable) {
_authorisable = authorisable;

You can then handle the response on the client side using jQuery

var errorMessageThrottlerEnabled = false;
function() {
function(e, request) {
if (request.status == 401) {
if (errorMessageThrottlerEnabled)
window.location = '/SSO/LogOff';
errorMessageThrottlerEnabled = true;

Analysing your .NET App for Memory Issues

In this post, I will look at the hard & the not-as-hard (but still hard) way to isolate and diagnose memory issues within a .NET application using both free and commercially available profiling software.

Memory issues in .NET?

Many a .NET developer places too much of their trust on the garbage collector to manage application memory and only notice issues when they begin to cause problems in their applications.  Others think that, since the birth of virtualisation, servers can be scaled up with infinite amounts of RAM and virtual memory can be used on cheap disk space to increase this capacity.

It’s important to remember that you’ll solve a memory leak faster if you are equipped with the correct tools, conduct ample planning and are methodical in your approach.

So what’s leaking?

There are a few different areas to look at when analysing the type of leak you have.

  • Too many allocations
  • Long lived memory allocations
  • Managed memory leaks – like references

So what do I need to start?

You’ll need to be familiar with the Windows PerfMon tool in order to analyse detailed performance stats on the machine and a tool like New Relic to monitor memory usage at a higher level.

An essential tool for analysing a memory leak is a profiler in order to understand how your memory allocations connect up to the garbage collector’s root, track unintentional references to objects and long-running reference allocations.
Ok, which profiling tools?

There are a few ways to profile, by purchasing an ‘off the shelf’ memory analysis tool like Red Gate’s ANTS profiler or by analysing memory dumps of your application using a freely available tool for Windows, WinDbg.

Let’s focus on the hard way…

Here’s my 5 step guide to using PerfMon and WinDbg to check you have a leak.

Step 1 – So you think you have a leak?

Firstly, convince yourself you actually have a leak in your application!

You can do this using Windows PerfMon and adding counters which are relevant to your application.
In the case of our IIS .NET MVC application, things you want to look out for when determining if you have a memory leak are

.NET CLR Memory
– Bytes in All Heaps – Total Memory usage of managed application,
– Process MemoryLeak

– Private Bytes – This counter tells me how much memory the process is using that is not shared with other processes.
– MemoryLeak

Rescale them using ‘Scale’

If everything’s going at the same rate, it’s a managed leak and we can continue with our analysis.

Step 2 – Create memory dump files of your application over time

In order to analyse the difference in memory usage over time, we need to create two memory dumps of our offending application.

Create a full dump of the app using

procdump -ma w3wp MyWebApp.dmp

Create another dump some time later after performing the operations which are causing the memory to rise.

Step 3 – Get the data – open the memory dump files in WinDbg

Launch a copy of WinDbg and grab the first one and put it inside and issue the command

.loadby sos mscorwks

Step 4

Now we have the data, let’s figure out why the objects aren’t getting release? We need to ask the garbage collector what the reference chain is…

I’m not going to into the individual commands of WinDbg here as there are plenty of resources out there which will help you, however to try and diagnose the memory leak….

You’ll need a list of all heaped objects
A diff of heap objects between dumps

!dumpheap -stat - Summary view of all heaps and sizes on managed heap

Step 5.

It’s time to open another WinDbg window and open the second dump and compare

This should help you identify the highest growing objects and some fiddling about with WinDbg should help you to identify the reference chain to the GC.

The easier way

So, the easier way.  While it doesn’t make fixing your application any simpler, using a tool like Red Gate ANTS profiler can help pinpoint those lingering in-memory objects and point you in the direction of any offending part of your application.  This tool has some great features to enable you to analyse and profile your application.

The latest version features “attach to process”, giving developers a way to profile performance of a live website with little or no overhead to affect results.

Here’s a great guide on how to use ANTS profiler to analyse your in-memory objects.


Root – The base object holding references to other objects. Perhaps a static field, method parameter or event handler
Root path – The path of referees from the selected instance to GC.Root


New Website Launched – The Layer

We’ve just launched a new website for The Layer, a system for mobile & IT resellers.The website launch was backed up with the following ad in Mobile News.

Layer Systems May 2013 Ad

The Layer takes advantage of everything that is unique about the mobile, fixed line and IT channels, setting the system apart from other CRM tools on the market. The product enables you to grow your VAR business by improving control, empowering users and delighting customers through unique web-based software.