API Documentation with Grape and Swagger

TL;DR Use Swagger and Grape to create self-documenting APIs that automatically update themselves from metadata in the code. It also provides an API explorer to play around with.

During the AngelHack KL event, I (being the backend developer of the team) had to create an API to facilitate communication between the iPhone app and Twilio. Since it was a hackathon, there was not a lot of time to completely hash out API protocols (as well as explaining to my team mates how RESTful APIs work).

I was able to solve this by using Grape and Swagger. I can develop the API at my own time. When a particular endpoint was finished, I can push to production and my team mate is immediately able to see the documentation. He was also able to make use of the API explorer to test out the API’s responses to his queries.

We were able to quickly develop the whole project quickly and easily because of this, and here’s a quick look at using Swagger with Grape.

Read On →

Maker's Schedule, Manager's Schedule

Paul Graham’s (of YCombinator fame) essay on the difference between the Maker’s Schedule and the Manager’s Schedule is a timeless piece of advice that is sadly not as well known as it should be. The essay provides an interesting, if not logical reason behind why programmer’s skip meetings called by managers, while managers often tend to interrupt programmers. Here are some of the important points in his essay: Bosses often run on the manager’s schedule The manager’s schedule is granular to an hour (or half an hour) If there is nothing scheduled in the appointment book for this hour, it’s practically a “free hour” in which you can slot in a new appointment (or a “short” meeting) People on the manager’s schedule always have something coming up in the next hour, so it’s a no-brainer for them to remember or check what they should be doing next The ticket to productivity is to fill in as many slots as possible with quality meetings Many people who make things (like programmers and writers) instead run on the maker’s schedule The granularity is at least half a day This means that if an interruption (such as a “short” meeting) cuts the work unit, that work unit is effectively wasted People on the maker’s schedule need to remember that there is a meeting coming up, which throws a spanner into their workday because you can’t really predict how far down you would be thinking about a problem The ticket to productivity is long stretches of uniterrupted work time Speaking of interruptions (see what I did there? Read On →

Ruby Development in Windows

I’ve done the unthinkable and I have a confession to make.

I’ve switched my development machines to Windows.

Here’s the story of my heresy … and my possible salvation.

Read On →

Ruby and Blocks

One of the most often used and ironically least understood concepts in the Ruby programming language is the block. If you’ve used one of the Enumerable mixed-in objects, you’ve encountered the block syntax.

Read On →

Install ruby-2.0.0-p195 on Ubuntu 12.04

It’s always easier to deal with a ruby binary that’s installed server-wide rather than a local user installation (done via rvm or rbenv). Server initialization scripts don’t need to do path magic and profile sourcing in order to find the correct binary. Here I how to install ruby-2.0.0-p195 in a way that your system administrator will love you for.

Read On →

Rolling Restarts with Capistrano and Linode

Here I show how to perform a rolling restart using Capistrano, and making sure that the load balancer (in this case Linode) properly reroutes traffic to the still-running servers while the others are being restarted.

WARNING I’m still ironing out a few bugs for the rolling deployments. The issue appears to be that Capistrano executes deploy:create_symlink in parallel so the apps still experience downtime before the restart happens. The concept itself is sound but the code is not yet production ready!!

Read On →

Running PrivatePub/Faye Standalone in Heroku for Free

PrivatePub is an awesome gem by the renowned Ryan Bates of Railscast fame. It provides an easy way to use Faye as a pubsub provider. Watch this episode to see it in action.

You don’t have to bundle the gem with a Rails application though; you can deploy PrivatePub standalone as a rack application in Heroku. This allows you to run PrivatePub in a web dyno instead of a worker, allowing for easier maintenance (separation of repositories/codebases) and as a side effect, save on hosting costs.

Read On →

My Development Setup

At Mindvalley employees can have any kind of hardware/software they want, provided that they can prove it is necessary for the work they’re doing, or at least it increases their productivity. In my case, I opted for the setup as seen here (picture courtesy of my colleague):

Look, Ma! Four eyes!!

(the blank monitor on the left was an Ubuntu VM on screensaver mode)

Read On →

Having Fun With Remote Shells

I just bought a VPS (virtual private server) a couple of days ago, and I’m enjoying tinkering with it. It’s not the most powerful beast though; it only has 64MB RAM and 128MB swap. I won’t say the name of the company I’m subscribed to since my box isn’t exactly the bastion of security, but you should be able to discern the shell provider from how I describe my escapades :D Read On →

Recommended Programs

While mucking around my computer and generally getting bored, I found a few neat programs to install. They’re really cool, and your Linux computer shouldn’t be without them :) Firefox AdBlocker - blocks ads from websites. Definitely heaven sent, as browsing becomes faster without all those ads being loaded (the extension dynamically modifies the page to comment out the ads, so they don’t get rendered). You can get to choose which ones to block too. Read On →