Posts tagged with 'Code'

Switching to Astro

This blog has been neglected for about 5 years and has been burning away compute cycles on an old Wordpress install and MySql DB. And I've been too lazy busy to update it to something that's not needlessly costing me £10/month. But no longer. Now we're on Astro, taking advantage of static site generation and…

Published

Split your cmder window into multiple panels

cmder is my go-to shell for Windows. Up until recently, I was unaware that it could be split into multiple panels. There doesn't seem to be a menu option to do it, but it’s easily done with these commands (which, yes, I need to look up every time). Split the window horizontally (left/right split): cmd -new_console:s…

Published

Writing Cleaner AngularJS with TypeScript and ControllerAs

Our team made the move to TypeScript and Angular at the tail end of last year. I'd had a look at Angular a year or so ago but struggled to get my head around the excessive usage of $scope and the nesting of $parent items that needed to be traversed. Since then (with version 1.2.0), Angular now supports Controller As…

Use Karma and Grunt to Run Your Jasmine Tests in Real-Time

As JavaScript applications become more common and more complex, the need for good unit test coverage also increases. Hopefully you’re already writing tests. If not, why not? When I’m doing TDD with C#, I use NCrunch to monitor all tests within the Visual Studio Solution and run them as they change. This saves me…

.NET Distance Model

I actually put this together a while ago but have just realised I never put it up here. The Problem As part of some of the work I've been doing over the past year or so, we've run into issues dealing with units of distance. The most problematic of these being when an app that was created for a US market had to be…

Published

Adding Business Layer Caching Using Castle Windsor AOP

Aspect Oriented Programming (AOP) is a programming paradigm that allows separation of cross-cutting concerns. But you probably already knew that if you're reading this. If not, go have a read at the Wikipedia page on AOP or the introduction page on the Castle Project site. The Problem If we have an existing…

Published

Notes from the Future – The City SDK

Wouldn't it be great if there was a common data source you could query for all information about an area – bus timetables, ATM locations, cost of housing etc.? I just spent the end of last week and the weekend down in Manchester for the Future Everything conference and Innovation Challenge Hackathon and got to see and…

Published

This week’s most horrifying code

And the winner of this week’s most horrifying code goes to this snippet: Dictionary<string, Dictionary<GeoDirection, Dictionary<bool, List<Route>>>> routes = new Dictionary<string, Dictionary<GeoDirection, Dictionary<bool, List<Route>>>>(); Generic, eh.

Published

Fix Visual Studio when templates disappear from your Add New Item dialogue

So, I was trying to add a new class to a project in Visual Studio and the template for it seemed to have disappeared. I still had the “Add Class” option in the dropdown but no “Class” option when I got into the “Add New Item” dialogue. Luckily, it’s pretty easy to fix. Find the templates If you have a look inside your…

Published

Completely disable cache in Google Chrome

I like debugging JavaScript in Chrome. The console is pretty excellent for stepping through code, logging, checking for bounds events etc. The one issue that I kept running into was that of caching. As I was making changes to my JS file, I found myself having to go through a couple of menu settings every time I wanted…

Published

Use Ant and Closure Compiler to compress every JavaScript file in a project if you have lots of files

In a previous post, I set out how to use an Ant script to run every JavaScript file in a project through the Closure compiler. For the most part, this has been working fine for me. Then I ran it against a project with some 50-odd JavaScript files and it started to throw PermGen OutOfMemoryError errors. So, it needed…

Enabling bundling and minification support in a .NET 4 application

.NET 4.5 is going to offer support for bundling and minifying content on the server before passing that down to the client. If you want detailed information on what this is, go and read Scott Gu’s blog post about the features. In a nutshell, bundling is combining several files into one combined file and minification…

Publishing a Node.js Express App to Windows Azure

Windows Azure has really come on in the past few months. With the new management dashboard, support for other web technologies (even horrible ones like PHP) and removal of Silverlight, it’s actually become a pleasure to use. One of the new supported technologies is Node.js. I'll not go into the reasons for using Node…

Published

Getting Started With Node.js Part 1: A Quick App

Node.js is a server platform built on Google Chrome’s JavaScript runtime. It has an event-driven, non-blocking I/O model so it’s a fast and efficient as you could want. It’s also probably a good glimpse into the future of server technology. With the server running pure JavaScript, it’s a great plaform for development…

Published

Code Hell: JavaScript Error Messages

When you're tasked to make changes to a legacy 3000+ line JavaScript file, seeing this at the start doesn't inspire confidence: // ErrorMessage this._EventLocationControl_JS_NoClientDataHolder_ErrorMessage = …

Published

Simple JavaScript Method Chaining

Method chaining is a way to return an object from a method call that allows for further methods to be called. It’s easier to see than to describe. Instead of this: var people = helper.getPeople(); var bob = people.find('bob'); var email = bob.getEmail(); You could do this: var email =…

Published

Use Ant and Closure Compiler to compress every JavaScript file in a project

There’s an updated version of this script in this blog post. At work, we use TeamCity to automatically build and deploy to dev projects as we check in changes. One thing that’s always been a bit of a nuisance is dealing with the compression of JavaScript files that we've written for the projects. Developing locally,…

Starting to write JavaScript that doesn't suck

A couple of people I've spoken to in the past few days have made comments about how much they hate JavaScript and how bad it is as a programming language. I'd agree that this is true for the code that people new to the language can sometimes create. Take this wrapper for the Google Maps API: var map; function…

Published

Getting Extensionless URLs for WordPress on Windows Using ISAPI_Rewrite

Okay, a little bit niche but I couldn't find any decent info online. <p class="disclaimer"> DISCLAIMER: This works for my hosting. Don't blame me if this borks your install. Remember that I'm just some random guy on the internet. </p> My site is hosted with Blacknight. I originally had the site set up…

Published

Get, y’know, thingy

Today’s code discovery: _user = userRepository.GetUserByEmail(UserName); Genius.

Published

Hateful Code

I wonder if the person who wrote this had any idea of how much trouble it'd eventually cause? catch (Exception ex) { // TODO: log? }

Published

Unit Testing Database Access

The goal of unit testing is to create a small, self-contained tests for a piece of code that tests the functionality of that piece of code in isolation from the rest of the system. Put more simply, it should test the code you want to test and nothing more. This can be a little tricky when dealing with writing tests…

Published

Not enough time in the world

I like learning new things. I've been like that as far as I can remember, from getting a “How Does It Work?” massive textbook-like tome when I was about 8 or 9 which, despite the intonation of the title, actually did a pretty good job of explaining how things actually worked from how they made Christopher Reeves fly…

Published

Getting Sublime Text 2 to Compile CoffeeScript on Windows 7

Okay, this is maybe a bit niche but I might as well document this for whoever else comes across it. Sublime Text 2 is a pretty nice text/code editor in the same style as TextMate for Mac. CoffeeScript is a reduced syntax for writing JavaScript code. Getting them to work together isn't all that straightforward but is…

Published

Regular Expression Attribute for checking for a number of non-alphanumeric characters

[RegularExpression(@".[a-zA-Z0-9 ]+.", ErrorMessage = "Passwords must contain at least 1 non-alphanumeric character.")]

Published

Randomise a list of anything in C# with LINQ

/// /// Shuffles the specified list into a random order. /// /// The type of the list items /// The list of items. /// A randomised list of the items. public static IList Shuffle(this IEnumerable list) { Random rnd = new Random(DateTime.Now.Millisecond); var randomised = list.Select(item =&gt; new { item,…

Published

Regular Expression for Matching a Decimal

Just because I know I'll need to look this up in future. -?d+(.d+)?

Published

I’m in your phone, watching you

While I was doing some reading on HTML5 geolocation on Friday, I noticed a method that I had missed previosuly – watchLocation. While navigator.geolocation.getCurrentPosition will return the current position of the device, watchPosition fires off an event every time the device changes position. So, you can have real…

Published

A New Back End

Not that you should notice, but I decided to move my site’s code to ASP.net MVC 3 with Razor. Initial impressions are that it’s far easier to work with than the webforms view engine although the lack of automatically resolving objects' namespaces is a little annoying. There’s no change that should be visible (apart…

Published

Geolocation JavaScript

var locator = function () { var _logger; /* Public Methods *******************************************************************/ this.attachLogger = function (logger) { _logger = logger; _logger.log('attached logger'); }; this.resolveLocation = function (successCallback, failCallback) { …

Published

Converting Access Database to MySQL

This was something that I was struggling to find decent info on but eventually managed to get it working. So, here’s how to do it: 1. Create your database in MySQL Open up MySQL Front or whatever MySQL administration software you use. Add a new database (in MySQL Front, right click on the data list on the left hand…

Published