Michael de Silva's Blog

Software Engineer. Rubyist and Roboticist.

Michael de Silva's Blog

Software Engineer. Rubyist and Roboticist.

Got an app in mind?

Since 2010, I have crafted apps for mobile and web for clients around the world via my consultancy — Inertialbox. My specialities include Rails, client-side Javascript frameworks such as Backbone & Ember.js, TDD/BDD, and DevOps — just to name a few.

We should talk.

When that Startup Interviewer cares more about where you're from

For the past couple years, I've been primarily working for a client based in the UK. I'm lucky to work with a fantastic team and I have no complaints there. The only downside, is the sort of work that comes through the doors, although I'm of course grateful that we have work!

The thing is, the client in question is a design firm, and this kind of work is all about work that has been scoped on a project-basis. You basically get an X-number of hours to get the project done and dusted; fall shy of that estimate and things start to get hot under the collar!

While this may not be apparent, there's a different approach to life as a programmer, and that's the startup scene. Rather than hopping around multiple client-projects, hell bent on profit vs. quality, at startups there's typically a single product. Remember 37 Signals, had Highrise, Campfire... and they renamed themselves Basecamp — it's actually one of the best things they did since sharing Rails with ...(continued)

Suits is back, with Season 5 and Under the Dome

Wallpaper suits 34619277 1920 1080

It's great news, Suits is back as Season 5. Can't wait to catch the premier.

Also, Under the Dome Season 3's just started with what looks like an hour long premier.

Improving my Dockerised App stack

Here's a quick update on my app stack — which is saving me a further $20/mo. A previous iteration of this stack, before it was Dockerised, has now been scrubbed off the Digital Ocean servers, and that app — inertialbox.com — is now running on the same 1 GB ten-dollar droplet.

There's ~300MB of RAM free which hasn't affected orchestration via Ansible. The nginx reverse-proxy is also now in place, and it's being treated as an 'app' as well. Since it's running in a container, it's just another service and therfore is fair to consider it in the same vein.

All the following containers are managed by systemd, and I'm quite frankly loving it along with the journald.

CONTAINER ID        IMAGE                                 COMMAND                CREATED             STATUS              PORTS                    NAMES
4f1ba395455e        ...(continued)

Jack Dorsey is CEO at Twitter, so here's a TODO list

I was watching the Bloomberg clip on Verge and the main topic of discussions was why Twitter is stuck at 300M users, and how come they've had a Billion signup & never come back (bounce-adoption rate?).

Here's my TODO list for Jack Dorsey

Simple Signup

Think 'KISS', or better known as 'Keep It Simple Stupid'. It's not rocket science. Signing up right now is far too long-winded, and rather than having users pick those to follow at signup, give them an auto-populated list from the 'verified' accounts list.

Show new users the value of Twitter

Lot of non-techies have no clue what twitter is, or its value. I personally use it as a news-source, and many do. Perhaps give new users an insight into this upon sign up.

Twitter needs Chirps - long tweets.

That 140-char limit will hurt your user base. Something to che ...(continued)

Replace a MySQL table in Production via a Rails 4 Migration

In a recent client project, I've been re-building a Rails 2.x eCommerce site in Rails 4.2, and when this is launched on production, I wanted to be able to drop tarballs of various tables straight into the git repo and have a migration unpack those tarballs and import them into the DB; the drop-table clauses in the SQL will ensure existing tables will be selectively replaced upon import.

The entire unpacking of the compressed tarball is done in memory, and the script looks for the file in the bootstrap folder in the app root. The database.yml file is used to fetch login credentials, and that's how the extracted SQL file is imported into MySQL.

require 'rubygems'
require 'rubygems/package'
require 'zlib'
require 'fileutils'

module Util
  module Tar
    # Creates a tar file in memory recursively
    # from the given path.
    #
    # Returns a StringIO whose underlying String
    # is the contents of the tar file.
    def tar(path)
      ta ...(continued)

Converting SVG to PNG via Linux CLI

I normally reach for imagemagick but its SVG to PNG rendering is reputedly not that great. Here's a tip from a colleague of mine, noting that -z forces non-gui usage,

$ apt-get install inkscape
$ inkscape -z -e hexagons.png -w 1024 -h 1024 ./hexagons.svg

You can also checkout its man page.

Getting Resque, Rails 4.2, and Unicorn to play nice

Having read Deploying Rails Applications with Unicorn this hit me as a surprise when I traced this issue all the way to my app's Unicorn error log, where it complained that Resque.redis did not implement the method #quit — a simple NoMethodError.

I consulted the Resque 2.0.0.pre.1 source for clues and found that the Resque module only had a reader defined Resque.redis= and the actual Redis instance was stored in its Config module.

Thanks to a convenience reader method, this is easily fixed by calling Resque.config.redis.quit instead.

My favourite Docker productivity tips

Here are some of my favourite Docker related short-cuts and productivity hacks

Attach to an already running container, with an Interactive TTY

The most handy command that's been added to the Docker CLI is exec, which means that we no longer need to fuss with things like ns-enter. This also means that one doesn't have to bother much about containers running with an entrypoint script, as getting to a bash prompt is effortless

docker exec -it b5cc04781384 /bin/bash

Loopback IP inside a container, isn't always what you think it is!

If you try to access your host via 127.0.0.1, you'll be in for a rude surprise. Docker adds a new network interface, docker0, to your iptables with the IP 172.17.42.1.

Should you ever need to access ports on your host system, you'll need to reference that IP instead, and here's some further reading on the subject.

Remove all stopped conta ...(continued)

Now with Resque & Redis for hooking up with Mailchimp

Screen shot 2015 06 07 at 03.14.19

You'll now find this site has a 'Sign up' box on the homepage — add your email, hit enter (that 'return' key) or click 'away' from the input field. I sprinkled some Javascript magic on that, and it'll hand over your email via XHR (simply, AJAX), to a background job on Redis via Resque.

The background job, fires off that email over to Mailchimp. How's that for amazeballs?

Just built a Ruby 2.2.1 compatible Mailchimp wrapper

Screen shot 2015 06 06 at 18.32.17

It's the weekend, so obviously it's time to roll up my sleeves and get some serious work done. Last night, I felt that it was time that I put some effort into building a newsletter group, at least starting via my blog.

I want this to be reusable too — and having looked at the most popular Mailchimp library's latest efforts in upgrading to Mailchimp's API v3.0, I just said 'screw it' — I'm going to build it from scratch.

My favourite libcurl Ruby wrapper is Curb, so this is used within my API's base. This simple DSL isn't ready for public prime time consumption, but it'll give you a rough idea of the approach I've taken

module Mailchimp
  class Member < Api::Base

    def initialize(list)
      super()

      # FIXME: Check that `list` is an instance of `Mailchimp::List`
      @list_id = list.id
      @ ...(continued)

Upgraded Docker platform, this time with more bells!

Three tier webapp inertialbox

Before the DNS switch, I last posted

The DNS has been switched once more, and while they propagate globally, traffic will be routed to a pair of droplets, rather than this single instance.

Hang tight, and I'll share all the gory details...

During my initial efforts, since I wanted to adhere to the KISS principle (Keep It Simple Stupid), I decided to setup MySQL — via Ansible — onto the bare metal directly. This meant, there was going to be a single app container, per app that would run.

This is something I knew I'd have to deal with a while back, but I was hoping that I wouldn't need to destroy and re-create droplets, but then again, that isn't such a bad thing. Similar to git branches, spawning a new droplet is cheap. Trouble is, I can't take down the droplet with my data sitting on it (and assets too!).

Therefore, it was rather obvious, that it was time to isolate DB hosts from the apps themselves.

Development: Separation

I ...(continued)

Post Archive