Arduino Christmas Tree Project

I decided that it was essential to give our customers the ability to turn our Christmas tree lights on and off over the web.

treeapi

Check out our Christmas Tree API here, Arduino code below.  Live stream to follow!

IMG_0386

IMG_0384

Code Running on Arduino UNO

 

Self-Executing Functions in JavaScript

I’ve been steadily migrating my JavaScript assets to use self executing functions (and more recently literals) as they are a good way to enforce scope on variables and make your JavaScript more readable.

The examples below show the difference between implementing a self-executing function and using literals.

I have found that on most browsers (except Safari), there is a considerable performance win when using literals.

Creating a module via a self-executing function

 Creating a module via object literals

 

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.

 

Deleting duplicate records using T-SQL

 

T-SQL script for identifying deadlocked processes

A useful script for identifying SQL deadlock cause/victim.

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.

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
context.HttpContext.Response.End();
}
}

///
/// 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;
$(document).ready(
function() {
$("body").ajaxError(
function(e, request) {
if (request.status == 401) {
if (errorMessageThrottlerEnabled)
alert(request.responseText);
window.location = '/SSO/LogOff';
errorMessageThrottlerEnabled = true;
}
}
);
}
);