Posts tagged with 'Code'

Publish Your Mastodon Posts to Astro

I'm a big fan of hosting your own content. Partly because I like keeping control over what I've posted, partly because platforms like MySpace some older video sharing sites will just lose all of your content that you hadn't backed up anywhere else because you were young(er) and stupid(er). Since the implosion…

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…

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…

.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…

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…

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…

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.

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…

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…

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…

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 = …

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 =…

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…

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? }

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…

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…

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…

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,…

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…

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…

Geolocation JavaScript

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

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…