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.

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 :) )

Prevent multiple registrations by same email in mura

This was a request from one of the site visitors (my first request :)).

It was easy enough, the code is in the validate() method in userBean.cfc. You just need to add the highlighted lines in. Instead of modifying the … more

Building and hosting a free website

This is about a fun and very enlightening experience I had building the website for DC Diaper Bank, a non-profit organization that collects baby diapers for needy families in the Washington DC metro area.  The existing site was built … more

Add user to a mailing list in the sign up form in Mura

I’m not sure if this functionality is already in mura, but I couldn’t find anything after browsing the forums. All I found was ability to add to mailing list from a custom form with 2 hidden fields, mlid = {mailing … more

Send account activation emails to users on sign up in Mura

This is a very simple way to send account activation emails and activate the user account once they click the link in their emails in mura. It uses encrypted usernames as the passphrase in the activation emails. You can set … more

Login with email address in Mura

This seems to be a highly requested feature, to allow logins with Email instead of username. The solution, I found is quite simple. The login method is in /requirements/mura/user/userUtility.cfc. Need to override that to check the email column as well. … more