• Convert ID Properties Back to BSON from JSON

    Recently, I started using Backbone with MongoDB to build an app. As I started integrating an “edit” feature I ran into a rather vexing problem: my $oid fields kept getting converted to strings whenever I updated a document. This caused all manor of havoc with my queries: Data wasn’t getting returned properly, results sets were empty, pages crashed because of null values, etc. Unfortunately, after doing a bunch of research, the best advice I found related to modifying toJSON and parse methods to convert ID fields back to their original values when posting. This really wasn’t an option for me since I had a number of nested documents in my data structure that also had $oid fields that needed to be converted. For example:
    Read more

  • Autocomplete Awesomeness: Why You Should Prefix Your Media Query Variables

    I’ve read multiple blog posts about what to name your media queries and I doubt there will ever be a consensus on which way is best. That being said, I would like to offer some advice when it comes to naming your media query variables: Give every media query a common prefix (e.g., $mq- or $bp-). That way, when you use your autocomplete / intellisense in your IDE, you see this:

    Screen Shot 2014-12-22 at 6.48.01 PM

    Every single breakpoint, accessible and ready to use.

  • Using Handlebars Templates With Backbone and Browserify


    While working on a recent side-project, I ran into some trouble implementing Handlebars templates for my use in my backbone views when using Browserify for my dependency management. If you’ve run into similar issues, here’s a quick breakdown of what you’ll need to do to get up and running again:

    1. Install Hbsfy

    In order to precompile the templates for use in your app, you’ll need to install hbsfy and include it in your gulpfile. For the record, I have no idea what the hell that’s supposed to stand for but I like to imagine it being short for “Handlebars Sci-Fi” but spelled in the same way as the terrible TV network. Here’s a snippet from my gulpfile for you to use as a starting point.

        var gulp,
        gulp = require('gulp'); // Include gulp
        // Include our plugins
        browserify      = require('browserify');
        del             = require('del');
        hbsfy           = require("hbsfy"); // <---- THIS RIGHT HERE
        sass            = require('gulp-sass');
        source          = require('vinyl-source-stream');
        sourcemaps      = require('gulp-sourcemaps');

    Apply Hbsfy During the Bundle Process

    Once you’ve included Hbsfy, you’ll need to apply it as a transformation during the bundle() process:

        gulp.task('compile', function () {
            var options;
            options = {
                debug: true,
                paths: [
                extensions: ['hbs']
            browserify('./src/main.js', options)

    The one thing to note in the above snippet is the call to hbsfy.configure where I am simply telling hbsfy (I seriously want to know what that stands for) that my template files will all end in .hbs. You can substitute in whatever file format you’re using for your templates.

    3. Include the Template in the Same File As Your Backbone View

    Once you’ve got your gruntfile configured properly, you can safely start using Handlebars templates in your Backbone views…almost. You still need to include them. It’s rather straightforward:

    (function () {
        'use strict';
        var User,
        Backbone = require('backbone');
        User = require('entities/user');
        Users = require('collections/users');
        Handlebars = require('handlebars');
        template = require('./search-full.hbs'); // <!-- RIGHT HERE

    4. Override the Render Method of Your View and Call the Template

        module.exports = Backbone.View.extend({
            className: '.form',
            el: '#app',
            events: {
                'keypress .search .field': 'submitSearch'
            initialize: function () {
            render: function () { // <!-- OVERRIDDEN
                return this;

    For the record, I’m not sure if this is the way to do this. However, I tried simply setting the value of the template property on the view and it didn’t work. If you know of a better way, feel free to leave a comment.

    Wrapping Up

    Well, I hope this eased someone’s frustrations out there. If it did or if you know of a better approach to this problem, please let me know in the comments below.

  • 5 Questions to Ask Yourself When Using Recursion


    Recursion can be a tough concept to grasp regardless of the language you decided to program in. In order to help developers who find themselves struggling with the concept (myself included), I’ve broken down the concept into five simple questions you’ll need to answer in order to write solid recursive functions (inspired by the folks over at CodeCademy).
    Read more

  • How to Make Gulp Copy a Directory AND Its Contents


    I just got done switching one of my side-projects over to Gulp for the build process and I kept struggling with how to copy multiple folders from the src directory to the build directory in such a way that the directory’s contents and its original folder structure are preserved. Basically, I was trying to achieve this:
    Read more

  • How to Exclude Layout Files When Rendering Templates With Node.js and Express

    I struggled with this for a good half-hour and I figured I’d share in case anyone else ran into this issue. Long story short, I needed to return an HTML fragment for a particular ajax request from the app (in this case, search results) but the response always included the layout file I configured for the app:

        hbsEngine = expressHbs.create({
            extname: 'hbs',
            defaultLayout: 'layout.hbs',
            helpers: {
                formatDate: function (date, format) {
                    return moment(date).format(format);

    Read more

  • How to Parse Responses From the StackExchange API Using Node.js

    Currently, I’m working on a small side project that involves parsing the wiki entries for given tags on StackOverflow. Without going into a ton of boring detail, the task I was trying to complete can be broken down thusly:

    1. Make a request for the wiki entries of one or more tags from the SE API.
    2. Show that data in a Handlebars template
    3. Profit

    Read more

  • Formatting Dates Using Moment.js, Handlebars, Express, and Node.js

    For those of you out there that may be struggling with this, here’s a quick breakdown of how to format dates using moment.js, handlebars, express, and node.js. This post assumes you have the following packages installed in your express app:

    1. Express3 Handlebars (link)
    2. Moment.js (link)

    Once you’ve included these packages in your app.js file, you’ll need to set up handlebars like so:

    app = express();
    hbsEngine = expressHbs.create({
        extname: 'hbs',
        defaultLayout: 'layout.hbs',
        helpers: {
            formatDate: function (date, format) {
                return moment(date).format(format);
    // view engine setup
    app.set('views', path.join(__dirname, 'views'));
    app.engine('hbs', hbsEngine.engine);
    app.set('view engine', 'hbs');

    You can ignore the extname and defaultLayout configs incase you want to use the default values that handlebars sets for you for the extension and layout file name. The important thing to note is the helpers object. Basically, it’s the equivalent of the registerHelpers method in the JS version of Handlebars. In this example, I’m create a formatDate method that takes in a date and “format“ string and returns a formatted date via moment.js.

  • Helpful Tools For Web Developers: CodeWars.com


    The ability to solve new problems efficiently is the hallmark of a good developer. When interviewing dev candidates, I don’t necessarily look for their experience with a particular framework or API. Most of the time, I’m looking at how they go about approaching a problem they’ve (most likely) never seen before. You’ve probably encountered questions like “write a function that finds x number in the Fibonacci sequence” or the ubiquitous “FizzBuzz” puzzle. These questions and others like it are designed to give the interviewer insight into how you think about a problem and the kinds of solutions you’ll come up with.
    Read more

  • Helpful Tools for Web Developers: CSS Arrow, Please


    Recently, I’ve discovered that making css arrows (see image above) is a huge pain in the ass. Luckily, there’s a tool to make it easy for you: CSS Arrow, Please (I added the comma because it was driving me nuts). I highly recommend you check it out if you need an arrow for UI elements such as speech bubbles, tooltips, or popovers.