occasionally useful ruby, ubuntu, etc


Sharing session state in Node.js between your HTTP server and websockets server

At first, sharing your session state between your Node.js HTTP server and websockets server might seem difficult. However, if you're using Express and NowJS (or the technologies they're built on, Connect and Socket.IO, respectively), most of the work has already been done for you -- it's just a matter of connecting the right pieces together. An example follows, written in Coffeescript.


HydrateJS: Smarter Javascript Serialization

Finally, here it is: HydrateJS.

It's a library that helps you serialize proper Javascript objects, more than just hash-like objects like JSON.stringify can handle. Anyway, I put a lot of time into the documentation inside the library as well as on the Github Pages link, so check those out! There is also a full suite of specs.

For some of the technical challenges, see my previous post.

Let me know what you think in the comments, and if you're using it, feature requests, etc.


Javascript Serialization

Note: RSS subscribers, I've (finally) enabled summary-only feed entries, so you will have to click through to see the full post.

Have you ever wanted to serialize entire Javascript objects? When I say objects here, I don't mean the simple hashes that you get by saying {foo: "bar"} -- I mean instances of your User, Product, Query, etc prototypal Javascript instances. JSON.stringify gets you part of the way there, but notice this doesn't work:

Inconvenient, to be sure -- and to make matters worse, there don't appear to be, well, any libraries out there that handles intelligent serialization of Javascript objects. So that's what I'm writing now (but it's not ready yet). Look for it soon though!


MVC, Games, and a message bus

It seems to me that many approach the use of MVC in games with skepticism, but the more I develop a game in MVC, the more I am reassured in my decision to do so. I operate by the principle that models should absolutely not know about their view(s) (or controllers) -- models should be completely standalone chunks of state and logic that can only reference other models. However, this can present us with a few problems.


Announcing Crow, a path-finding library in Javascript

Over the past few weeks I've been building out a clean and fast path-finding library in Javascript with a particular gaming site in mind, and I'm pretty happy with where it's at right now. If you're interested in at least one of: API design, Google Closure library, Google Closure compiler, or QUnit, then hit the jump for more. In the future, I'll cover Javascript (and object-oriented patterns), path-finding (breadth-first search, Dijkstra's algorithm, and A*), rake, games, and the embedded Sinatra+Bundler.


LockNLoad is…locked and loaded?

I've just completed and pushed the initial version of LockNLoad, a Spring-like Inversion of Control container for Javascript, which follows the dependency inversion principle (I think I'm getting all these terms right...). Given the proper configuration, you can simply say LNL.$("my_id") and get a prototype or singleton object or function. Read on for more information.


Debugging unobtrusive javascript in jQuery

So if you work for a large enterprise website like I do, where each page loads dozens or hundreds of kilobytes of javascript, it can be hard to figure out exactly what happens when you click that div and something magically happens, due to the wonders of unobtrusive javascript.

Or, to rephrase the question, "I know how to add event handlers to an object -- how do I enumerate what's already been attached?"

And it's pretty easy, but unfortunately it doesn't use a public API. Anyway, try this in Firebug:


If there are any events on that element, they'll be displayed. The only drawback is...you have to know exactly which element the events are attached to, or guess around a bit.



Accessing GM_xmlhttprequest from event handlers bound by jQuery

So I like jQuery. And I like Greasemonkey. I especially like the ability of Greasemonkey's ajax calls to go cross-domain. But how do I get access to this functionality in my event handlers? Calling GM_xmlhttprequest in a method that doesn't execute while the Greasemonkey sandbox is still alive doesn't work. At first I didn't think it was possible, but I discovered a way...using setInterval.


DEPRECATED: Announcing: jQuery optimization races

Note...this site is down for now...

You don't have to understand it to see that it's at least a bit interesting, so check it out:


It documents a bunch of different ways of doing similar things, and compares them in terms of performance. How much are you really losing by using the jQuery convenience method?


Google Visualization API + jQuery

TODO: bring animations to charts in the Google Visualization API via jQuery to illustrate performance described in previous post.

Relevant link.

Filed under: google, jquery, web 2.0 No Comments