AuthorAlex

How to assert.throws on an async function with a callback

H

Recently, I was writing a module that took a callback, and needed to write a test, asserting on an exception. Here’s how to do it: it('throws error if myParam is less than 10', function(done) { var fn = function(){ myModule.doSomething(8, function(err) { if (err) throw err }); } assert.throws( function() { fn() }, /Value is less than 10/ ) done(); }); Assuming our module looks something like...

Scam Warning – Email with subject ACTION REQUIRED: A document has arrived for your review/approval (Document Flow Manager)

S

Received this email earlier this week… After some googling, I have determined that it’s a scam, and there’s usually a zip file attached. GMail had removed this zip file though I think. This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately...

Removing $id from JSON returned by WebApi

R

If you’re using the default JSON formatter (ie- haven’t set another one up) your outputted JSON may look something like this: [ { $id: "1", FirstName: "John", LastName: "Smith", }, { $id: "2", FirstName: "Sarah", LastName: "Harris", }, { $id: "3", FirstName: "Michael", LastName: "Jones", }, { $id: "4", FirstName: "Harry", LastName: "Green", } ] Notice the $id element appearing. What...

Unit tests failing when run all together with FakeItEasy

U

While running my tests, I noticed that if I ran my test suite all together, some would fail, giving the exception: API restriction: The assembly has already loaded from a different location This issue was happening both in ReSharper test runner, and using the NUnit test runner Debugging, the exception was being thrown on my SetUp methods like: [SetUp] public void SetUp() { _myFake = A...

Git Error – bad config file line 1 in .git/config

G

Last night, just before leaving the office, my development VM decided to crash unexpectedly. Upon starting the machine the machine the following morning, and trying a git pull, I got the following error: bad config file line 1 in .git/config I CD’d into my .git directory, and opened up config in notepad There was nothing in there, except for a load of whitespaces. To fix this, I removed the...

Useful way of exploring a StackTrace with Visual Studio 2012

U

I was shown a really handy way of viewing a StackTrace in Visual Studio 2012 today Steps are simply: Copy stack trace (from yellow screen of death for example) In Visual Studio, press ctrl + shift + e For example: at MyProject.Web.Controllers.ErrorController.MyMethod() in d:\Projects\MyProject\Web\Controllers\ErrorController.cs:line 23   at lambda_method(Closure , ControllerBase , Object[] )   at...

Dorset Sports Cars Review – I took them to court, and won

D

In July 2012, I bought a car (BMW 335d) from Dorset Jaguar & Sports Cars.I naturally tried to haggle on the listed price, but was assured that it was in immaculate condition, so wouldn’t budge. Based on their assertions I bought the car, paid the deposit and arranged to collect the car the following week.I collected the car on Friday, 20th July. A few days later, while driving home from...

Using custom options with KnockoutJS Drag and Drop

U

I was recently doing some work involving Knockout and needed to implement drag / drop (with jQuery UI draggable and droppable) I stumbled across this post from Wilsonhut that shows how to use custom binding to attach drag and drop functionality to your view model. Since that post (and previous posts in the series) covers that in detail, I won’t elaborate. However, I had a requirement to be...

Worst ever version control system

W

I once worked for a company, who, when I asked if they used a ‘version control system’ their lead developer eagerly replied

“YES – At the end of every day, I copy my directory, zip it, and rename it with todays date”

The best part was

“To make it easy to find, we cleverly use the date format YYYY-MM-DD in the zip file name”

I left around a week later.

Did you report to “John Smith” at your last role?

D

Recently, I had a conversation with a recruiter who apparently had the ultimate contract on offer for me. The conversation moved swiftly on from telling me how great the job was to this: Recruiter: So your last contract, did you report to <John Smith>? Me: No. –awkward silence– Recruiter: Ah, ok, who was it then? Me: Sorry, I don’t give out names Recruiter: Well I...

Syntax error using Yahoo YUI Compressor .net port – works using java version

S

Recently, I was tasked with creating a minified version of a web applications Javascript files. I settled on the Yahoo YUI Compressor, in particular, the .net port of it When I tried to compress a particular file (the jquery.caret plugin), it would throw up a syntax error. This error only occurred using the .net port of Yahoo YUI Compressor. Using the standard java jar version of YUI Compressor...

Download emails from GMail in a specific label with GMVault

D

I recently wanted to download around 20,000 emails from a specific label in my gmail account. To do this, I used GMVault. I’m not going to talk through the basics of setup / using this as it’s already talked about at length on the GMVault site. However, in order to get it to download only the mails in a specific label, you will need to do a custom sync. The command I used was this: gmvault sync...

Gmail reply all graduated from Labs– ‘r’ shortcut doesn’t reply all

G

I recently noticed that while replying to an email in google apps (or gmail for that matter) it wasn’t defaulting to Reply All – despite me enabling this lab. Upon further inspection, I noticed this was no longer an option in the Labs.Fearing that it had been removed altogether, I had a look over the General settings tab, and found that it had graduated from a ‘Lab’ to an actual feature: This was...

Equivalent of LINQ projection / select with Javascript

E

Not strictly an ‘equivilent’ but a way of achieving the same. For example, consider the following array: var products = [{ id: 1, name: "Product One"}, { id: 2, name: "Product Two"}, { id: 5, name: "Another Product"} ]; Say, for example, we just wanted a list of IDs from this array. With .net, using LINQ, we could do a simple Lambda: .Select(x=> x.id) With Javascript, we can use Map to achieve...

Incremental / Sequential int IDs with MongoDB using an IdGenerator

I

I blogged about using incremental ids with mongodb previously, so have a read of that for more information. Although it’s not ideal, we can use sequential / incremental IDs with MongoDB.Sometimes (when migrating legacy systems for example) we just can’t get away from using ints for id’s. While working on implementing MongoDB with N2CMS recently, I came across this very problem. All IDs are...

TFS – Forgot to untick the Preserve pending changes locally checkbox when shelving

T

Coming from using Git, I am used to using a stash in this scenario: Working on a piece of functionalityHigh priority change comes in on the branch I’m working on that would affect the above work In this instance, I would tend to stash my changes. After googling, I discovered the TFS equivalent is Shelving. So, I shelved my changes, and was horrified to see them still in existence in my source...

Returning my iPhone5

R

So, I’ve had and used my iPhone5 for around a week now, and I’ve decided to exercise my right to return it. Why? Lightning cable By far the biggest disappointment Apple have ever dished out.Fine, if there’s some technical reason to change the connector, then do it. But do so in a gracious manner, and don’t try to charge people £25 to make their accessories they’ve...

Parallels 8 Upgrade – Moving windows in Windows 7 snapping back

P

I recently upgraded my copy of Parallels desktop from version 7 to version 8. As soon as I had done, I noticed the supposed “improved multi-monitor support” wasn’t all it was cracked up to be. If I had a window open, and dragged it to the other monitor (either from external to macbook, or vice versa) it snapped back! See video: Update Parallels have now released a hot fix which...

MacBook Pro with SSD – Hanging / Crashing when using Windows 7 & Parallels

M

Just a quick blog to see if anyone else out there is experiencing hanging / crashing when using: Macbook Pro OSX Mountain Lion SSD (256mb Crucial CT064M4SSD1) Parallels – Windows 7 Guest OS Only started noticing the problem since I installed the SSD Every now and then, the whole system will sort of freeze. Won’t respond to mouse / keyboard. Freeze lasts around 10-30 seconds, then...

Create a standalone EXE to run a Node.js application

C

Download Advanced BAT to EXE converter () Download Node.exe from Joyent Now we’re ready to bundle the node.js executable and our js files into a single exe file. As for our BAT command, all we need is: CD %MYFILES%/ node test.js %MYFILES% is the variable given to the location of embedded files (more on that in a sec) Your Advanced BAT to EXE converter window should look like the image on the left...

Node RailwayJS app – Deploying to Heroku – ENOENT, open ‘/app/log/production.log

N

I’m currently working on a project involving a node.js app, using RailwayJS, deploying to Heroku. After doing my git push Heroku Everything seemed ok, however, the app was not running. I ran Heroku logs and was shown: app[web.1]: listening on port 32168 within production environment app[web.1]: app[web.1]: events.js:48 app[web.1]: throw arguments[1]; // Unhandled ‘error’ event...

Online hotel booking sites & credit card reservations – beware!

O

Recently, I was working on a project with a similar business model to hotel booking websites such as LateRooms.com and Booking.com: The customer reserves a “room” from a third party. The customer pays at the hotel. Failure to show, results in customers card being charged. I was intrigued about how the others got this process to work, and naturally went about finding out, and doing...