Keys with undefined value are missing when converting to JSON

Ran into a quirk with JSON.stringify() recently. If you have an object with some keys of value undefined, they will be omitted when converting to JSON:

var obj = { a: 1, b: undefined };
JSON.stringify(obj); // -> "{"a":1}"

I’m sure there’s a good reason for this (it’s in the spec after all), but I had some data that needed those keys to be conserved. Luckily there’s an optional second parameter you can pass to JSON.stringify(), a replacer function, which can be used to modify the data before it’s encoded to JSON.

If we create a quick function to replace all undefined values with null:

var replacer = function(key, value) {
  return value === undefined ? null : value;

And call JSON.stringify() again with our replacer function as second parameter:

JSON.stringify(obj, replacer); // -> "{"a":1,"b":null}"

All our keys are now preserved.

Learn You Some Nashville Numbers

I created a little game that can help you learn to use the Nashville Number System. Check it out here:

Learn You Some Nashville Numbers (source)

I also created a port of the game using Ember.js which was fun to put together. One of the main challenges of the port was trying to maintain game state and transitions without using Ember’s router, since you don’t usually want to save game state in the URL. I ended up using an Ember object to hold the state variables and referenced that throughout the application, but if I were to do it again I might try to use Ember’s state machine instead.

Learn You Some Nashville Numbers (Ember.js edition) (source)

Installing Ruby on Rails on Windows

UPDATE: Apparently this is a common problem, so if you want to go the easy route then use and disregard the rest of this post.

I’ve been trying to get Ruby on Rails installed for the last couple hours and ran into some snags, but I finally seem to have overcome them. This page is supposed to get you up and running, but it’s apparently more difficult than that for Windows users. So here’s the steps I ended up using:

Read more

Yamaha AUDIOGRAM6 direct monitoring workaround

I bought the Yamaha AUDIOGRAM6 recently to have something easier to carry around than my 12-channel Mackie mixer. If all you need is an audio interface for recording, then it’s pretty great for the price – USB powered, built-in compression, phantom power, stereo recording. If you want to use it live, though, it has a fatal flaw, one which isn’t mentioned on their product pages or even in the manual. There’s no way to turn off direct monitoring.

I’ve taken to using Reason as my effects processor when playing electric guitar, and it simply doesn’t work to have the dry signal mixed in just as loud as your processed signal. I’ve since purchased the Propellerheads Balance audio interface, which works great, but it also costs about three times as much. So if you’re stuck with the AUDIOGRAM6 here’s a way to get around the direct monitoring if you’re using Reason on Windows.

Read more

ColdFusion Error: Element USER is undefined in SESSION

But I defined Session.User in the OnSessionStart method! How is this possible??

Turns out, if there’s an error in the OnApplicationStart method, then OnSessionStart will not run before your OnError method is called. And if your OnError method tries to log the Session variables it expects to be there, it will throw this error.

Live and learn.

To Node or Not to Node

I’ve been hearing about Node off and on for a while now, but haven’t really looked into it very deeply until now. I’ve really come to enjoy JavaScript as a language since discovering jQuery a couple years ago. (Before that I tended to shy away from it because it was just so frustrating to deal with the DOM.) So, naturally, to be able to use it on the server as well as the client has a certain appeal to me.


Read more