Dropping Legacy IE Is No Panacea

29 Aug 2013 | By Alex Young | Comments | Tags browser ie dojo chrome

The presiding sentiment of client-side developers seems to be that dropping legacy IE support fixes cross-browser issues. While it does reduce a lot of rendering quirks, it doesn’t mean you can stop browser testing altogether.

The reality is that there are four popular browsers with a wide range of versions. Using DailyJS’s readership during August as an example, Chrome’s versions break down like this: Chrome 28 has 53%, and Chrome 29 is at 13%. Firefox has 43% on version 22 and 41% on version 23. That means we see very few Firefox and Chrome readers on older versions, so they’re doing an excellent job of keeping users up to date. Digging into the IE stats, I can see 50% using IE 10, and 0.33% on IE 6!

Why am I bothering you with browser stats? It was because I saw this bug in Dojo earlier today: #17400: Chrome 29 breaks dojo.query in Dojo 1.4.4 through Dojo 1.6. The Dojo developers quickly fixed the bug. It seems someone had used array-style accessors on a DOM node instead of the children and childNodes properties.

Even though IE 10 is far better than its predecessors, and Chrome and Firefox see fast upgrade rates due to their update mechanisms, you can’t leave out proper cross-browser testing. It’s hard work and dull, but unfortunately still important. I have a feeling the disparity in mobile browser technology will be the new IE 6, but that’s another story…

Node Roundup: 0.10.17, Defining Global Scripts in npm, loadtest

28 Aug 2013 | By Alex Young | Comments | Tags node modules http benchmarking npm

Node 0.10.17

Node 0.10.17 is out, so it seems like we’re back to weekly releases again. This version updates uv, tls, stream, dgram, and readline. The stream module fix makes errors raise exceptions when 'error' listeners are removed, which seems like a slight oversight to me…

Defining Global Scripts in npm

Joe Sullivan sent in his post about how global scripts are defined in popular npm modules. This is the kind of thing I like to see – learning from the pros. Joe summarises the common approaches at the end of the post.


loadtest (GitHub: alexfernandez / loadtest, License: MIT, npm: loadtest) by Alex Fernández is a load testing module inspired by and partly compatible with Apache ab. It can be invoked as a command-line script or used as a module.

var loadtest = require('loadtest');
var options = {
    url: 'http://localhost:8000',
    maxRequests: 1000,

loadtest.loadTest(options, function(error, result) {
  if (error) {
    return console.error('Error:', error);

  console.log('Tests run successfully');

The callback is run when the requests have been made, or the specified number of seconds have elapsed.

Do You Use the jQuery Plugin Site?

27 Aug 2013 | By Alex Young | Comments | Tags jquery plugins

The jQuery Plugin Registry was released in January 2013. It uses its own JSON format for defining a plugin and requires that you add http://plugins.jquery.com/postreceive-hook as a post-receive hook. This lets the repository collect information about new and updated plugins. The plugin site’s code is open source, and the authors use GitHub to manage feature requests and bugs.

jQuery was released in 2006, and since then a lot has changed on the web. In the JavaScript community there is a vocal group that has moved away from more monolithic frameworks, now that tools like npm, Bower, and Grunt have made it easier to manage dependencies and build client-side projects. That doesn’t mean jQuery isn’t still influential, and it’s still hugely popular.

What concerns me is despite jQuery’s continued popularity, the number of new releases on plugins.jquery.com is lacklustre. It’s far from stagnant, but npm leaves it in the dust. Not a fair comparison? Perhaps, but I know for a fact most of the plugins readers send DailyJS do not have jquery.json manifest files. I find it increasingly common to see package.json or bower.json files.

Do you use the jQuery plugin site for publishing or discovering plugins? If not, please discuss your issues with the service in the comments. Also, if you’ve been writing client-side scripts without the jQuery dependency let us know your reasoning.

Embedded JavaScript: Your Next Career Move

26 Aug 2013 | By Alex Young | Comments | Tags v8 microsoft google embedding

Most of us started out writing JavaScript for web pages. Even if you’re a server-side developer focused on Node, you probably wrote client-side JavaScript first. We see JavaScript as a language closely integrated with the DOM, and as a relatively lightweight server-side language, but you can flip this around and think of it as en entirely embedded language: after all, it’s embedded within web pages – it’s bridged to native data structures and functionalities that are required by the runtime.

Why Embed?

Why are scripting languages embedded in other software at all? If you think about a large C++, C#, or Objective-C project, then build time and deployment are major issues. Certain programming chores lend themselves well to scripting languages, so rather than rebuilding a huge project every time a small tweak is required, changing a script might be more productive.

In game development Python and Lua are typical choices for scripting. They’re used for game interfaces, logic, asset loading, AI, and more. Part of the success of the modding community based around Unreal engine games came from the use of UnrealScript.


You’re probably wondering: why Python and Lua? It’s mainly because these languages are widely adopted and suitable for embedding. Boost.Python and Luabind are examples of libraries that help with binding. Without bindings to the underlying native code it’s impossible for the scripting language to communicate, so this has to be fast and easy.

Web UI

An alternative to low-level binding is to use a web view that hosts JavaScript code, with some event-based bindings to the underlying application. Many mobile and desktop applications use web views for chunks of UI that are easier to implement with HTML, so this is happening more often than you might realise.

Once you’ve got large amounts of UI written with HTML, the required JavaScript starts to become messy. That’s where modern MVC frameworks like Backbone and AngularJS come in: but writing this code properly is a whole skill in itself, so that’s when the C++/Objective-C developers call us for help!

Unfortunately, embedding JavaScript as a runtime isn’t simple as it should be. There are many different ways to do it for each language.


In the .NET world there are lots of projects for running JavaScript inside your applications. IronJS is an ECMAScript 3.0 implementation built on Microsoft’s Dynamic Language Runtime. ClearScript allows multiple scripting languages to be added to .NET applications: it supports JavaScript through V8 – imagine being able to add using Microsoft.ClearScript.V8 to a C# program and then do engine.Execute("Console.WriteLine(lib.System.DateTime.Now)"). There’s also Jurassic – another ECMAScript runtime.


The general wisdom seems to be that embedding V8 is the way to go. There are also SpiderMonkey-based projects like libjspp.


Apple’s Introduction to WebKit Objective-C Programming Guide explains how to access JavaScript from Objective-C.

Another approach is to embed JavaScriptCore. Apparently, Appcelerator Titanium uses JavaScriptCore for iOS projects – you should be able to figure this out by looking at Appcelerator’s GitHub projects.

Job Opportunities

I’m currently contracting at a particularly eclectic office: my team has Objective-C, C++, C#, and JavaScript developers. The shared wisdom amongst the non-JavaScript developers is they want to embed JavaScript in their projects: whether they’re games, desktop software, or mobile applications.

That’s great for us, but it’s worth remembering that JavaScript isn’t good at everything – the type system might not suit certain projects, its scope and coercion rules can be a source of frustration for people from other backgrounds. It looks C-like, but that doesn’t mean it’s C: and that’s the problem when you’re working with people who are more fluent in C than JavaScript.

If you’re wondering how people see JavaScript from the other side, then I found Choosing a scripting language by David Rosen interesting: he struggled with JavaScript’s readability because he couldn’t overload operators, and wanted to write maintainable linear algebra code.

However, it seems like there’s a huge amount of momentum behind JavaScript in a growing number of platforms, so it’s an area you should take seriously. Don’t be surprised to find yourself writing scripts for games or apps in the near future.

Bitcoins and JavaScript

23 Aug 2013 | By Alex Young | Comments | Tags node modules security


Bitcoin might seem like a crazy cryptocurrency, mainly because it is, but it’s also becoming more widely adopted. I find it fascinating because it feels like I’m finally living in a 90s Neal Stephenson or William Gibson novel, although the possibility of making online payments outside of the standard merchant account/bank model has its appeal.

I’ve been researching the state of bitcoin payments in JavaScript to see how easy it is to set up. The first thing I found was CoinWidget – this allows you to accept donations using client-side JavaScript. I’ve added a widget to DailyJS in case you want to donate, but it should be easy enough to add to your own sites as well.

Address validation

A bitcoin address includes a four byte checksum, which means addresses can be validated without talking to any servers. The bitcoin-address module (GitHub: shtylman / bitcoin-address, npm: bitcoin-address) by Roman Shtylman implements the algorithm: a double SHA-256 digest of the 21 bytes before the checksum is calculated to validate the address.

var btcAddr = require('bitcoin-address');
// true

Addresses are encoded with base 58, so Roman’s module includes his own decoding library. He also uses Node Buffer objects to work with the decoded data. Node’s crypto core module is used to create SHA-256 hashes.


If you install a wallet like Bitcoin-QT, you should get bitcoind running in the background. This has an optional JSON API. There are several npm modules for this API, like: bitcoin. This allows you to query the daemon for transactions, account balances, and you can even create backups of wallets. There’s a full API call list on the Bitcoin wiki.

Accepting payments

There’s no easy way to accept payments for web-based transactions, because you really need to talk to a bitcoin wallet to see if a customer’s payment has been made. I’ve seen people hosting Java-based wallets on Heroku, and wallets usually have APIs that we can talk to from Node, but this isn’t exactly ideal.


That’s where bitcoin merchants come in. They handle all the messy stuff so you can keep your web application code simple. Popular merchants with sensible APIs include BIPS and Coinbase.

This is the BIPS REST API (PDF), and the Coinbase API. There are Coinbase modules on npm and a BIPS API library.


Exchanges, like the infamous Mt.Gox, also have APIs. Through exchanges you can track interesting information about bitcoins, particularly exchange rate values, and some even allow trades to be made. There’s an Mt.Gox module on npm, which is light on documentation: check out MtGox/API for a general overview.

If you’ve written any bitcoin-related Node or client-side projects, send them in!

Debugging with Mocha

22 Aug 2013 | By Alex Young | Comments | Tags node modules testing techniques

I do a lot of work with Mocha, because I like to write well-tested Node projects. Sometimes there are things I just can’t figure out non-interactively, and that’s when I reach for the debugger. It’s a lot better than repeatedly running tests with more and more console.log statements.

Rather than using any extra Mocha extensions, I find Node’s standard debugger works great. With Mocha you access it by running your tests in debug mode:

mocha debug

The debug option works just like node debug file.js. Node’s debugger comes from V8, which has a built-in JSON-based protocol that supports communication with a live process using TCP. That means you’re not limited to Node’s command-line tools: the fancy GUI debugger in Chrome can be used instead.

Debugging a Failing Test

To debug a failing test, look at the stack trace to figure out a good place to add a breakpoint. I usually put them in test cases, just before a failing assertion, but you can put them anywhere in the program.

Breakpoints are added by inserting debugger on a single line by itself. Once you’ve strategically placed some breakpoints, run the tests with mocha debug.

Whenever you run mocha debug or node debug, you’ll be dropped into the debugger on the first line of the program. Type c to allow the tests to continue until the first debugger statement is encountered – there may be a delay after you issue the continue command, so be patient. After that the program will run until a breakpoint is hit, at which point you’ll be dropped into a prompt.

Debugger Commands

The commands are like gdb or lldb for the most part – if you’ve used another debugger before you should be able to figure out what’s going on. If not, there are three main commands that will get you started:

  • s: Step into code
  • n: Run the next line without stepping into it if it’s a function/method call
  • repl: Enter a REPL, which we mainly use for printing values and objects

As I have some experience with other debuggers, I found it took me a while to get used to typing repl: in most debuggers there’s a specific command for printing and formatting values or locations in memory. This REPL mode is exited by typing CTRL-C once. While you’re in the REPL, you can type the name of a value or object to see it: this is usually how I fix most of the problems in my tests.

Other Thoughts

I haven’t found a way to automatically drop into a debugger when an assertion fails. I’d really like to do this – it would be a bit like how IDEs work, but I’m not sure if it’s possible.

Node Roundup: 0.10.16, ungit, image-size

21 Aug 2013 | By Alex Young | Comments | Tags node modules git apps images
You can send in your Node projects for review through our contact form.

Node 0.10.16

Node 0.10.16 has been released, which includes an update for npm, and fixes for the crypto, http, and stream modules.


ungit logo

ungit (GitHub: FredrikNoren / ungit, License: MIT, npm: ungit) is a web-based UI for Git, written with Node. It makes Git repositories easier to visualise, a bit like gitk or git instaweb, but it has some GitHub-specific tweaks.

ungit repo

It can be installed with npm install -g ungit, and is run with ungit on the command-line. You can set up an .ungitrc which is a JSON file that currently just changes the port.

Once you’re running ungit, you can make commits, discard them, fetch remote changes – pretty much the standard Git operations you’re used to, with a friendlier workflow.


If you need to get image sizes without using command-line binaries, then take a look at image-size (GitHub: netroy / image-size, License: MIT, npm: image-size) by Aditya. It looks at the relevant bits in a file by using a Node buffer, and supports popular formats like PNG, GIF, BMP, and even PSD.

It has an asynchronous and synchronous API:

var sizeOf = require('image-size');
sizeOf('images/example.png', function(err, dimensions) {
  console.log(dimensions.width, dimensions.height);

jQuery Roundup: Fine Uploader, SimpleSlideView, jQuery.uheprnGen

20 Aug 2013 | By Alex Young | Comments | Tags jquery plugins ui widgets mobile html5 cryto
Note: You can send your plugins and articles in for review through our contact form.

Fine Uploader

Fine Uploader

Fine Uploader (GitHub: Widen / fine-uploader, License: GPLv3) by Mark Feltner is a client-side library for managing file uploads. It’s free of dependencies, but there’s a jQuery plugin for convenience. It supports multiple file uploads, progress bar, drag and drop, upload cancelation, validation, and direct to Amazon S3 uploads. S3 uploads work using CORS, and XHR2 is used for browsers with File API support and monitoring upload progress.

The author maintains a blog about the project, and a recent post includes details on the S3 support.


SimpleSlideView (GitHub: cloudfour / SimpleSlideView, License: MIT) by Tyler Sticka is a mobile-style UI widget for displaying and managing animated view hierarchies:

This plugin was designed to work well with non-fixed layouts, which means it can be helpful to scroll to the top of the window or container prior to a view changing. If a $.scrollTo plugin is available, SimpleSlideView will attempt to use it by default. It has been tested with jquery.scrollTo and ZeptoScroll.

The views are divs marked up with a container so they can be displayed and hidden as needed. Data attributes are used to associate navigation with markup: a link with data-popview or data-pushview allows movement through the view hierarchy. There’s also a JavaScript API for managing this.

The readme has full documentation and an example for using it in a responsive interface.


jQuery.uheprnGen (GitHub: ryanmcdonough / jQuery.uheprnGen, License: Public Domain) is Ryan McDonough’s first attempt at a jQuery plugin, but it’s cool because it wraps around Steve Gibson’s UHE PRNG script, which stands for Ultra-High Entropy Pseudo-Random Number Generator.

This carefully designed PRNG utilizes more than 1536 bits of internal state memory. The operating parameters of the generator’s algorithm were carefully chosen (it uses a safe prime factor) to guarantee that every possible PRNG state is visited before the sequence begins to repeat.

With Ryan’s script, you can call $(this).uheprngGen({ range: 100, count: 10001 }); to generate 10001 random numbers with a range of 0 to 100.

Speech Router, Botdylan, Google Cloud Storage

19 Aug 2013 | By Alex Young | Comments | Tags api storage speech chrome github

Speech Router

Speech Router (GitHub: lukasolson / speech-router, License: MIT) is a router that wraps around Chrome’s Web Speech API. It’s based around a constructor function that accepts a routes object:

new SpeechRouter({
  routes: {
    'search google for *query': function(query) {
      window.open('https://google.com/search?q=' + query);

If you haven’t seen the Web Speech API before, it’s worth checking out. At least the results seem quite good with my accent and Chrome – your mileage may vary!


Botdylan (GitHub: botdylan / botdylan, License: MIT) by Pau Ramon is a Hubot-inspired GitHub automation system:

We use GitHub heavily. There are some repetitive tasks that were taking away our time to hack on a better product. Since we are in the productivity space we decided to stop doing things manually and start to have a more productive environment to work with.

It can do things like add labels to issues based on events, integrate with a CI server, talk to chat rooms, and so on. It runs as a daemon, and can execute tasks periodically in the background.

Google Cloud Storage

Google Cloud Storage, sent in by Jonathan Simon, is a screencast that demonstrates a JavaScript application that talks to Google’s Cloud Storage platform. The source code is here: storage-getting-started-javascript.

This demonstration covers getting started with Google Cloud Storage using JavaScript. See the process of setting up the sample application, running the sample and using it to try out Cloud Storage API commands like ‘list buckets’.

NoFlo, Peppy

16 Aug 2013 | By Alex Young | Comments | Tags node



NoFlo (GitHub: noflo) is a project to bring a visual-based approach to programming. It currently focuses on Node, but the authors want to branch out to other platforms if you give them enough money.

The project and the site seem interesting enough, but the Kickstarter video comes off a little bit too enthusiastic. Here is a spoonfull of delicious hyperbole for you to digest: “Nothing new has really been invented in programming in the last 50 years”, “code starts as whiteboards”, “flow-based programming can eliminate spaghetti code”.

Whether or not something is truly new is irrelevant: monads have been around less than 50 years, but even so we’re still exploring their uses after a good 20 something years (random citation: Extensibe Effects: An Alternative to Monad Transformers). Just because strongly typed object oriented programming is the dominant paradigm doesn’t stop thousands of papers a year being published about programming and related fields. Even if you spend all day writing JavaScript, Java, C#, or whatever, the field is still forging ahead: these languages themselves are evolving.

The assumption that we use whiteboards perplexes me. I don’t think I’ve used a whiteboard once in my career, and I’ve been programming commercially for 12 years now. How can making tangled masses of diagrams be a solution to spaghetti code? Won’t we just end up with spaghetti diagrams?

NoFlo has been written in CoffeeScript for simplicity.

Oh, OK… Before I give up and post that Grandpa Simpson hat gif, I’ll say this: I’m not sold on the idea, but that doesn’t mean I won’t try it. Let’s set aside the hilariously hyperbolic marketing video and see what it can do.


Peppy (GitHub: jdonaghue / Peppy, License: FreeBSD) by James Donaghue is a CSS selector engine. He originally wrote it over four years ago, and it was well known at the time for being fast. He’s recently rewritten it with a different focus:

Peppy no longer uses large regular expressions for parsing selector strings. It now uses a selector parser that I wrote called LLSelectorParser. This is a top down parser that returns an abstract syntax tree. Peppy internally now works off of this tree.

Back when I regularly wrote the Let’s Make a Framework posts I was fascinated by how CSS frameworks work. Things have changed since then, but parsing selectors is still an interesting topic. Check out LLSelectorParser if you want to see how James implemented his.

A Look at Facebook's React

15 Aug 2013 | By Alex Young | Comments | Tags frameworks facebook ui reactive


React (GitHub: facebook / react, License: Apache 2.0, npm: react-tools, bower: react) from Facebook and Instagram is a UI framework. It’s maintained by Paul O’Shannessy, and Paul and Christopher Chedeau both post to the React blog regularly about new features and community news.

React is meant to be a declarative framework, so it focuses on transforming data into interface components. Data can come from servers and user input – there’s no specific transport layer support, instead other libraries like jQuery are relied on.

The first thing you’ll notice about React is it mixes HTML and JavaScript:

var HelloMessage = React.createClass({
  render: function() {
    return <div>{'Hello ' + this.props.name}</div>;

React.renderComponent(<HelloMessage name="John" />, mountNode);

What’s going on? Well, this snippet is intended to be placed inside a script tag, with the type attribute set to text/jsx. JSX is React’s XML-based template language. It doesn’t hit the DOM until it needs to: instead a mock DOM, or faked browser is used to maintain an in-memory representation of your templates. Be aware that this comes with caveats: everything is escaped by default, so HTML entities can easily be double escaped.

You don’t need to use JSX, however: React.DOM.div({}, 'Hello ' + this.props.name) is equivalent to the previous example.

Applications made with React are based on components. Components are created with React.createClass method (not React.createComponent). Components have a “state” and “props”: the state is private, and mutable. If the state is updated, then the component will be re-rendered: this is known as reactive state, and is how React models reactive data flows. React doesn’t re-render the entire component, it tries to only render what changed:

render() methods return a description of the DOM, and React can diff this description with the in-memory representation to compute the fastest way to update the browser.

React plays well with Node-based build systems: there’s a Grunt task for building JSX, in case you don’t want to render everything in the browser. The documentation has a section on React’s tooling integration.

The documentation for React is straightforward and easy to follow: there’s a tutorial that introduces the main aspects of the framework. It’s difficult to say how it compares to other frameworks like AngularJS, but I like the distinction between mutable and immutable state and properties for modeling reactive data flows.

Node Roundup: The Future of Node, takeapeek, subtitle

14 Aug 2013 | By Alex Young | Comments | Tags node modules subtitles video
You can send in your Node projects for review through our contact form.

The Future of Node

Yakulu posted The Future of Programming in Node.js to Hacker News, which is a long message by Isaac Schlueter on the nodejs Google Group:

Callbacks will remain the de facto way to implement asynchrony. Generators and Promises are interesting and will remain a userland option.

This is not a democracy. However, there’s plenty of room for everyone’s opinion. If you want to make exciting dramatic breaking changes to node-core, and you can’t find satisfaction by writing userland npm modules, then please fork joyent/node, give it a new name and logo, and go as completely crazy as you want.

It sounds like the Node core developers are focusing on keeping Node maintainable, rather than jumping on whatever new language or API style is currently fashionable. I like this approach, because after working with faddish web frameworks that resulted in unmaintainable projects after a surprisingly short amount of time, the idea of a stable and calm core library is definitely welcome.

There were cries of a lack of innovation in the comments, setting off an interesting discussion about the future of Node. Eventually the comparison with Meteor was brought up, and Isaac talks about how it differs to Node, npm, and even how the Meteor community is managed.

It’s required reading for those of us investing in Node for the next few years.


takeapeek (GitHub: giodamelio / takeapeek, License: MIT, npm: takeapeek) by Gio d’Amelio is a command-line web server in the spirit of python -m SimpleHTTPServer. It supports directory indexes, and allows settings to be saved in .takeapeekrc. You can also use it as a module in Node.

It’s built with connect, and was inspired by glance by Jesse Keane.


subtitler (GitHub: aetheon / node-opensubtitles-client, License: BSD, npm: opensubtitles-client) by Oscar Brito is an open subtitles API client.

It has a command-line tool for downloading subtitle files, and also has an event-based, asynchronous JavaScript API.

jQuery Roundup: jQuery.emphasis.js, Tipue Search

Note: You can send your plugins and articles in for review through our contact form.


jQuery.emphasis.js (GitHub: zmmbreeze / jquery.emphasis, License: MIT, jQuery: emphasis) by “mzhou” is a CSS3 text-emphasis fallback.

The author says it’s useful for East Asian languages because it adds symbols above or below characters to improve the clarity of emphasised sections. The equivalent CSS currently only works in WebKit with a vendor prefix, so this plugin will be useful to those working with these languages.

The source is quite interesting – it’s based on the CSS3 specification, which involves determining if a character is suitable for emphasis, then the insertion of fairly complex styles to simulate the emphasis marks.

Tipue image search

Tipue Search (License: MIT) is a site search plugin. It can search static JSON content, or pages on the same origin using Ajax. It also supports an image search mode, which looks for matches in JSON content that points to image URLs.

Given an index, like this:

var tipuesearch = {"pages": [
  {"title": "Tipue Search, a site search engine jQuery plugin", "text": "Tipue Search is a site search engine jQuery plugin. Tipue Search is open source and released under the MIT License, which means it's free for both commercial and non-commercial use. Tipue Search is responsive and works on all reasonably modern browsers.", "tags": "JavaScript", "loc": "http://www.tipue.com/search"},
  {"title": "Tipue drop, a search suggestion box jQuery plugin", "text": "Tipue drop is a search suggestion box jQuery plugin. Tipue drop is open source and released under the MIT License, which means it's free for both commercial and non-commercial use. Tipue drop is responsive and works on all reasonably modern browsers.", "tags": "JavaScript", "loc": "http://www.tipue.com/drop"},
  {"title": "About Tipue", "text": "Tipue is a small web development studio based in North London. We've been around for over a decade. We like minimalism with the occasional hint of retro.", "tags": "", "loc": "http://www.tipue.com/about"}

Tipue can be enabled using $('#tipue_search_input').tipuesearch(); on a suitable input element.

Auto Iframe Height Plugin Update

Ilker Guller updated his Auto Iframe Height Plugin (GitHub: Sly777 / Iframe-Height-Jquery-Plugin, License: MIT, GPL) to automatically check the iframe height when the contents change.

To enable automatic resizing, you can use the watcher option passed to $.iframeHeight. It also supports several other options, including: defaultHeight, minimumHeight, and watcherTime.

Ground, Generators and Async Patterns in Node, Time Grunt

12 Aug 2013 | By Alex Young | Comments | Tags node modules grunt typescript frameworks async es6


Ground (GitHub: OptimalBits / ground, License: MIT) from OptimalBits is a web framework for Node that is written with TypeScript:

In ground, most of the application logic is moved from the server to the client, whereas the server acts mostly as an scalable, efficient distributed storage and synchronization controller.

It includes also some rather useful features such as a hierarchical routing system, an undo/redo manager, property and declarative bindings, reference counting and automatic synchronization between clients and servers. It is design to always deliver high performance and low memory consumption.

Grunt is used for building the client-side code and deploying it. It uses models in the style of the Mongoose ODM, and most parts of the framework including models have event APIs. Views are implemented using view models.

The documentation at gnd.io includes more examples and demos.

Generators and Async Patterns in Node

Gorgi Kosev sent in his essay, Analysis of generators and other async patterns in node. He looks at how generators work, how the code compares to other implementations (for example, promises), using a complexity measurement, and benchmarks of memory and execution time.

The generator solution suspend is really fast. It incurred minimal overhead of about 50-80% running time. It’s also roughly comparable with streamlinejs (when in raw callbacks mode).

Time Grunt

time-grunt (GitHub: sindresorhus / time-grunt, License: MIT, npm: time-grunt) by Sindre Sorhus displays the elapsed time of Grunt tasks:

// Gruntfile.js
module.exports = function(grunt) {
  // require it at the top and pass in the grunt instance

  grunt.registerTask('default', []);

git-html5.js, TodoMVC 1.2

09 Aug 2013 | By Alex Young | Comments | Tags node modules polymer git apps chrome



git-html5.js (GitHub: ryanackley / git-html5.js, License: MIT) by Ryan Ackley is a Git implementation for JavaScript:

git-html5.js is a pure JavaScript git client library. It implements a complete Git workflow in nothing but JavaScript. It’s meant to run in a browser environment and depends on so-called “html5” APIs. Some example use cases:

Ryan took Adobe’s Brackets app, ported to run as a Chrome packaged app, and then added git-html5.js to create an editor that can read and write to Git repositories. I’ve tried out the basics and it seems to work pretty well.

The project includes tests and build instructions, but you can just run the Tailor app in Chrome if you want to try it out.

TodoMVC 1.2

Sindre Sorhus sent in TodoMVC 1.2, an update to the monster MV asterisk collection:

We released TodoMVC 1.2 yesterday with some new app examples of frameworks from Google (Polymer), Twitter (Flight) and Facebook (React), and other improvements.

If you’re interested in seeing what a small but functional Polymer project looks like, then check it out!

Reactive JavaScript

08 Aug 2013 | By Alex Young | Comments | Tags node modules browser coffee-script reactive

As JavaScript developers, whether server-side, browser-based, or both, two things we love are composition and asynchronous APIs. Once you’ve got the hang of callbacks, promises aren’t too difficult to master, which is when libraries like q and async come into their own.

Reactive programming offers a different approach. It gives us tools that attack composition and asynchronicity head-on by focusing on data flows. This is a declarative paradigm – logic expressed through data flows. We’re entirely familiar with this: you can’t go far with Node or jQuery without thinking in terms of events. The difference, however, is a layer of formality that provides a richer language for expressing logic through change.

If you’ve ever worked with .NET, then you might have seen Reactive Extensions. There’s also RxJS (GitHub: Reactive-Extensions / RxJS, CodePlex: Rx, License: Apache 2.0, npm: rxjs), a Microsoft Open Technologies project designed to help us compose asynchronous and event-based programs using observable collections, drawing on inspiration from LINQ:

One question you may ask yourself, is why RxJS? What about Promises? Promises are good for solving asynchronous operations such as querying a service with an XMLHttpRequest, where the expected behavior is one value and then completion. The Reactive Extensions for JavaScript unifies both the world of Promises, callbacks as well as evented data such as DOM Input, Web Workers, Web Sockets. Once we have unified these concepts, this enables rich composition.

The first example in the RxJS readme demonstrates how composition can be used:

/* Only get the value from each key up */
var keyups = Rx.Observable.fromEvent(input, 'keyup')
    .select(function(e) {
        return e.target.value;
    .where(function(text) {
        return text.length > 2;

/* Throttle/debounce the input for 500ms */
var throttled = keyups.throttle(500 /* ms */);

/* Get only distinct values, so we eliminate the arrows */
var distinct = keyups.distinctUntilChanged();

function searchWikipedia(term) {
    var url = 'http://en.wikipedia.org/w/api.php?action=opensearch'
        + '&format=json' 
        + '&search=' + encodeURI(term);
    return Rx.Observable.getJSONPRequest(url);

Recently, Yang Zhang sent me Introducing reactive.coffee: reactive programming and declarative UIs in CoffeeScript, a blog post about reactive.coffee (GitHub: yang / reactive-coffee, License: MIT, bower: reactive-coffee). This is a library of reactive programming primitives – it’s not AngularJS or Knockout, but something different and more generic. It provides reactive data structures that can be used for many things, including declarative DOM construction.

It’s also designed to work with jQuery, so normal jQuery objects can be manipulated using reactive programming.

There are dozens of reactive programming modules on npm, so check those out if you’re interested in learning more. Also, if like me you’re a Unix-focused web developer, don’t underestimate Microsoft’s resources on the topic because they’ve been doing this for a long time now.

Node Roundup: 0.11.5, nvi, signobj

07 Aug 2013 | By Alex Young | Comments | Tags node modules vim security crypto
You can send in your Node projects for review through our contact form.

Node 0.11.5

Node 0.11.5 was released this week. This unstable version updates v8 and uv. It also includes fixes for buffer, child_process, dgram, fs, https, openssl, os, tls, and util.

The patch for fs by Trevor Norris is interesting (pull request) – rather than writing strings to a buffer and then the disk, it changes fs.js and src/node_file.cc to write directly to the disk instead.


nvi (GitHub: mikesmullin / nvi, License: GPLv3, npm: nvi) by Mike Smullin is a ‘very opinionated Vi clone’. I tried installing it with npm install -g nvi, but it wouldn’t run; I had to check out the repository manually. It doesn’t clone Vi or Vim in a way that I think it’s fair to call ‘clone’ – I can’t seem to get hjkl to move the cursor, and the modes have been changed to include ‘COMBO’ mode instead of Normal mode which makes using it extremely confusing for a seasoned Vim veteran.

Despite all that, and the fact that the name nvi is a bad choice, I find the project interesting because making complex text user interfaces isn’t an easy task. Also, Mike’s nvi is focused on collaborative features, which potentially makes Node a great fit.


Django has a cryptographic API for setting and reading signed cookies, and presumably you can also use this to sign API responses for RESTful JSON APIs. Inspired by this, signobj (GitHub: Submersible / node-signobj, License: MIT, npm: signobj by Ryan Munro allows you to sign JSON data with a SHA-1 HMAC:

signobj() - Signs data with secret, you can also pass in some extra hidden data that is used when hashing. This can be useful if you’re creating an access token, and you want it to become invalid when they change their password, and also don’t want the password with the public data.

Ryan said he’s been using it to sign cookies and localStorage sessions.

jQuery Roundup: spy-js, yadcf

06 Aug 2013 | By Alex Young | Comments | Tags jquery plugins sponsored-content services tables ui
Note: You can send your plugins and articles in for review through our contact form.



spy-js, created by Artem Govorov, is a commercial tool that aims to make JavaScript instrumentation better. You can use it to trace, debug, and profile code that would otherwise be difficult to work with.

Although tools like Chrome DevTools are excellent, the advantage of spy-js is it can work with any browser. It also allows performance between browsers to be compared more easily.

spy-js in action.

There’s a free beta which you can download from spy-js.com, and issues are being tracked on GitHub. The documentation is also on GitHub, at spy-js/spy-js. The project isn’t open source, but the author intends to keep it free while he collects beta feedback.

For more information, take a look at spy-js.com and @SpyDashJs on Twitter.


Yet Another DataTables Column Filter (GitHub: vedmack / yadcf, License: GPL2/BSD, jQuery: yadcf) by Daniel Reznick is a plugin for DataTables that adds filtering components. It can filter based on a select, or the jQuery UI Autocomplete widget. It also parses different data types, like delimited plain text and HTML elements.

    { column_number: 0 },
    { column_number: 1, filter_container_id: 'external_filter_container' },
    { column_number: 2, data:['Yes', 'No'], filter_default_label: 'Select Yes/No' },
    { column_number: 3, text_data_delimiter: ',', enable_auto_complete: true },
    { column_number: 4, column_data_type: 'html', html_data_type: 'text', filter_default_label: 'Select tag' }]);

It also works perfectly well with multiple tables on a page. For more examples, check out the yadcf showcase and the project’s readme.

Signature Pad, Windows 8.1 Apps with Open Source JavaScript

05 Aug 2013 | By Alex Young | Comments | Tags ui windows mobile canvas

Signature Pad

Signature Pad (GitHub: szimek / signature_pad, License: MIT) by Szymon Nowak is a client-side library for drawing smooth signatures. It works with touchscreens and desktop browsers, and was inspired by the Smoother Signatures post on Square’s (excellent) engineering blog.

The problem is that the signer’s finger did not move in straight lines from point to point when tracing out this shape. Rather, our touch points are sampled from a full curve that the signer’s finger traced on the touchscreen. While we can’t know the original shape between the sampled points Android gave us, straight lines are not the best guess.

Szymon’s implementation doesn’t depend on any external libraries, and can draw signatures from DATA URIs.

var canvas = document.querySelector('canvas');
var signaturePad = new SignaturePad(canvas); 
signaturePad.clear();     // Clears the canvas
signaturePad.toDataURL(); // Returns signature image as data URL
signaturePad.fromDataURL('data:image/png;base64,iVBORw0K...') // Draws signature image from data URL

Building a Windows 8.1 App using Typescript and Open Source Libraries


This screencast by Ala Shiban demonstrates how to use some of Microsoft’s technologies with open source projects like AngularJS to create a Windows Store application.

I put together a 17 minute video that gets you started with writing a native Win8.1 app using HTML, CSS, JavaScript, TypeScript, AngularJS, Bootstrap, underscore, BankersBox and jQuery. The goal of the tutorial is to go through the end-to-end experience of developing a win8.1 app as quickly as possible while not developing a random ‘hello world’ app.

It’s a fast screencast that packs a lot in, so if you can’t keep up check out the source at AlaShiban / Ingredimeals. It uses TypeScript, Blend for Visual Studio, NuGet, jQuery, AngularJS, Underscore, and Bootstrap. Custom fonts are used to give the application a Windows 8 feel.

I haven’t used Windows 8 or Visual Studio much before, so I thought it was interesting seeing how it integrated with third-party open source JavaScript libraries through NuGet, and how debugging JavaScript worked.

Something I hadn’t seen before was MSApp.execUnsafeLocalFunction. I noticed Ala had to wrap some calls inside AngularJS (mainly things that wrote to innerHTML) to satisfy Microsoft’s security requirements for Windows Store apps.

Bootstrap 3, Node Web Development, Groc

02 Aug 2013 | By Alex Young | Comments | Tags node books bootstrap documentation

Bootstrap 3

Bootstrap 3's homepage.

Bootstrap 3 RC1 is out, and you’ll see Bootstrap 3 on the front page of getbootstrap.com:

With over ~1,600 commits, ~72,000 additions/deletions, and ~300 files changed, everything has changed. We’ve added features, removed features, and cleaned up a lot more. The v3 pull request on GitHub has all the details you’ll need for a complete list of changes and some helpful migration tips.

Before you get too excited you should know that it’ll take some work to migrate to Bootstrap 3. There’s no magic migration button as far as I know. Grids still scale up to 12 columns, but now use the class prefix .col-. Forms have different classes and tweaked markup, but the newer markup seems better to me. I don’t think we need <div class="controls"> anymore, for example.

Node Web Development - Second Edition

Node Web Development - Second Edition has been released, written by David Herron.

He’s written a post about it on his blog:

The final version of the sample application includes user authentication support, the ability to work with multiple database engines, be deployed on cloud services, and it dynamically sends data back and forth between server and browser to dynamically update the screen when other people edit things, and to support sending little messages between users of the application.


In Rock Your Doc With Groc, Our Favorite Automated Frontend Documentation Tool, a fork of Groc is discussed which adds support for tags:

We just couldn’t find a tool that gave us everything we needed. In the end, we created our own automated documentation tool by forking Docco and adding (hacking) support for Tags.

Groc, by Ian MacLeod, is a fork of docco by Jeremy Ashkenas. The post on Gilt’s blog does a good job of explaining why they need tags and how they use them.