Some of my recent posts and ramblings.

Setting up Nodejs micro services with Docker, Compose, Nginx and Rethinkdb

There is a lot of excitement around Docker and how incredibly easy it makes deployments. The Docker website is a little lacking in making this clear, besides there are a lot of other blogs which talk about how Docker is not for small apps and it's only for large scale applications which is not at all true. Docker is perfect when you are starting out, it enforces best practices and at the same time makes it so much easier to deploy your services.

I will walk through a simple example, which will provide a good foundation and also allow scaling out as you grow. Our example service has two services, an accounts service which needs to connect to a database(rethinkdb in this case, but you can use any other) and a service which connects to the pagerduty api. Rethinkdb has a very good web interface which we want to be able to access, but protect it via http basic authentication. Since there are multiple services, we will use nginx to proxy the requests through port 80.

You will need to install two things, Docker and Compose,

Here is the setup, there are some comments in the files themselves and a more detailed explanation at the end.

So, there you go. If you haven't noticed, the only thing you have to install on your server is Docker and Compose, every thing else after that is taken care of by docker.  This is incredibly powerful. One limitation here is of course, all of these containers run on the same host. But with Machine and Swarm, this will be resolved very soon.

Replacing Jade and Stylus with Handlebars and Less in Express

Jade and Stylus are two of the most annoying things to work with in Node. I was setting up a new Expressjs project and it was a pain to work with those two. Maintaining the right indentations and writing html and css with indentation and it's language was confusing to say the least. Surprisingly, it is actually very easy to replace them. I don't know why most articles which go through setting up an Expressjs do not mention this more.

We will be replacing Jade with Handlebars and Stylus with Less and here is the code to make it happen

var handlebars = require('express-handlebars'),
    lessMiddleware = require("less-middleware"),
 app.set('views', path.join(__dirname, 'views'));
 app.engine('hbs', handlebars({extname:'.hbs', defaultLayout:'main'}));
 app.set('view engine', 'hbs');

 app.use(lessMiddleware(path.join(__dirname, 'public')));
 app.use(express.static(path.join(__dirname, 'public')));

A simple jQuery plugin pattern

A simple jQuery plugin pattern. I had seen so many different patterns, Addy Osmani has a github repository full of them. This one works best for plugins which don't have a lot of instances created for them. Like it's not a good idea to use it for tooltips, etc (the basic jQuery plugin pattern is great for that) but its a great pattern for layout engines or slideshows which are usually called once or twice. I wrote this to avoid using so many 'this' and 'that' in the code.

The code layout is quite simple. An options and a state variable to keep track of the state and expose that and options, so they can be used for testing. We also expose out all the methods which we want to test or trigger manually in the return block. The 'create' method has all the initialization logic, all your event handlers go in the 'setupEventHandlers' method, the 'destroy' method implementation is optional, its useful to have it for testing which unbinds all the event handlers and clears timeouts.

A Presentation on JavaScript Testing Frameworks

This is a presentation I gave on JavaScript Unit and Integration Testing frameworks at Aol. It covers some, but not all the projects and progress in JavaScript testing. I skipped headless browsers and a few other stuff. I'll be doing a follow up presentation when I've got some test code up and running. I think QUnit and Jasmine are good choices. I like Jasmine's syntax a little more, but QUnit is used by jQuery. I'll probably try both, see which fits best for our needs and report back here.

Feynman lectures on physics

I have been doing a lot of commuting for my new job at (Need to find something closer). Anyway, so I discovered Feynman's lectures on physics. He is such an AMAZING speaker, talks with a lot of passion, you can feel how much he loves his work. The videos are apparently recommended listening for all physics majors, I wish they showed these to us in school. Here are links to a few. See the videos

Visualization of US State birds on a map

An interesting visualization of the US State birds. I got interested after seeing the Virginia Cardinal and the American Goldfinch at the regional park. It was surprising to see that a lot of states share the same state bird. The Cardinal seems to be the most popular followed by the Meadowlark and the Mockingbird.

See the interactive map here

John Cleese on Creativity

John Cleese (Monty Python) gives a talk about how to be creative. Really worth watching!

A compilation of Douglas Crockford videos on youtube

I am ashamed to say that I discovered these videos by Doug Crockford so recently. It is a must watch for any web developer. Only a few of the videos are technical, but he explains the history and evolution of the web over the years, the development of javascript and the Microsoft-Netscape browser wars. Very interesting and Crockford makes it very entertaining. more

CCValidator – A simple client side credit card validator

A jQuery plugin which highlights the credit card issuer and performs Luhn algorithm validation for credit cards. Try it out below (Nothing is posted or saved, it is all client side). It validates on change now, but it can be set to on blur, so its not showing an error message as the user is typing (that might drive a few customers away :) )

After reading the Steve Jobs biography