Paper API Client

Don’t put URL string literals in your code. Use my latest “paper” module instead.

It turns this:

request({
    method: 'post',
    url: 'https://host.com/v1/items?api_key=ApiKey',
    json: {
        name: 'foo',
        description: 'bar'
    }
})
.on( 'response', function( res ) {
    console.log( JSON.parse( res.body ).id );
})
.on( 'error', function( err ) {
    console.error( err );
});

Into this:

apiClient.createItem({
    name: 'foo',
    description: 'bar'
}, itemCreated );

function itemCreated( err, data ) {
    if ( err ) {
        console.error( err );
        return;
    }

    console.log( data.id );
};

You can read more about how it works on the GitHub page: https://github.com/tybenz/paper-api-client.

As always, any feedback is appreciated. Give me a shoutout on Twitter.

Paper Profiler

I wrote a small profiling helper for NodeJS apps today.

It's called paper-profiler and you can read more about it here: https://github.com/tybenz/paper-profiler

Example

If you're app looks like this:

var express = require( 'express' );
var profile = require( 'paper-profile' ).create();
var fs = require( 'fs' );
var path = require( 'path' );
var service = require( './service' );

var app = express();

app.get( '/', function( req, res, next ) {
    var reqId = req.get( 'X-request-id' );
    profile( reqId, 'getInfo' );

    server.getInfo( function( err, data ) {
        if ( err ) {
            res.send( 500 );
            return;
        }
        profile( reqId, 'getInfo' );

        profile( reqId, 'writeToFile' );
        fs.writeFileSync( path.join( __dirname, 'path', 'to', 'file' ), JSON.stringify( data ), 'utf8' );
        profile( reqId, 'writeToFile' );

        console.log( profile.getTimes( reqId ) );
        profile.done( reqId );
        res.send( data );
    });

});

app.listen( 8080, function() {
    console.log( 'Server started up' );
});

Profiling might look like:

[
  {
    "name": "getInfo",
    "elapsedTime": "0.51s"
  },
  {
    "name": "writeToFile",
    "elapsedTime": "1.32s"
  }
]

Better ctrl-z for Vim

I stumbled onto “How to boost your Vim productivity” the other day and it’s full of awesome Vim tips. One of them involved improving ctrl-z.

For those of you who don’t know. You can hit ctrl-z from within Vim and it puts Vim in the background and returns you to your shell. You can type in the command fg into your shell to get back into Vim. I use this workflow all the time. It’s much nicer to use an actual console to do file system stuff then many of the other Vim-specific workarounds out there (although I will say that vim-eunuch is awesome).

One huge problem with this approach is typing fg<CR> is annoying. And I never knew it until I read this article. The author has managed to map ctrl-z to not only send Vim into background mode but also return to Vim when you’re ready.

He achieves this through ZSH scripting. I’m a dedicated iTerm2 and BASH user, so I was immediately disappointed that this awesome tip didn’t apply to me.

So I figured out how to do it in BASH and iTerm2. You can take a look here: https://github.com/tybenz/ctrl-z.

It uses iTerm2’s custom key bindings with something called a coprocess. The coprocess itself is just a BASH script. Feel free to check it out. If you follow the steps, you’ll be up-and-running in no time and using ctrl-z up and down the street. Good luck nerds!

Presentation: JS Legos

I've been doing this talk on Reusable UI Components in JavaScript for a while now. I gave the last on at the HTML5 Developer Conference in May (hopefully will have a video soon). The talk is an adaptation from a previous blog post about reusable UI components in JavaScript. I've also given versions of the talk at jQuery Europe, jQuery San Diego and SSDG.

Slides are posted here:

http://tybenz.com/presentation-js-legos

Also, I'm releasing this small open-source UI component library as part of the talk, called lego.js. It's really just meant to be a repository of more in-depth code samples of the kind of components presented in the talk. Feel free to check it out:

http://tybenz.com/legojs

Here's a recording of the talk from jQuery Europe:

Here's a recording of the talk from jQuery San Diego:

List of awesome band names

I've started putting together a list of awesome band names.

Click here to see them: https://github.com/tybenz/band-names

Want to contribute?

Fork and pull request to contribute to the list. Don't know what those terms mean? Never used GitHub before? Keep reading.

How to contribute on github

Sign up for GitHub if you're not already.

Go here to fork the repo.

Go here to edit. Click on "Propose file change"

Then click on "Create pull request"