Docker Compose All The Things

After getting the GPD Win Max 2 and using it as my everyday machine bothe for work and for personal use, I’ve started enforcing the philosophy of not installing any project dependencies locally, and instead leverage containerization technology (mostly via docker). I’ve talked about this in a previous post and you can probably think of this post as an improvement on top of that.

I’ve been successfully using this following pattern both for work projects as well as personal ones, and I thought I’d like to share them. This particular blog for example is using this configuration:

Get Workflow Data From CircleCI

I needed to analyze some data regarding the costs of my client’s current CI system, and CircleCI’s insights dashboard–while itself is impressive–isn’t quite up to task.

Sometimes you just need the plain old “spreadsheet analysis technique” to make progress.

Here’s a quick ruby script I’ve written to get data from all the workflows for a particular project, and write them down into a csv for easy importation into a spreadsheet program.

Advantages of Using Docker Compose in Your Projects

It’s that time of the year again when I get a larger drive, refresh my operating system, and back up important files.

Ever since I’ve settled on having my home folder always be on a separated drive, it’s been really easy to change operating systems, and even moving to a different (more powerful) computer isn’t as much of a chore. If I need to upgrade storage capacity, I just copy everything in my home folder onto the new drive (either by imaging or rsync) and then make sure that when I setup the new OS, that new drive is mounted in /home.

One thing that’s been really convenient for me is the ability to even move database data along with my home folder. This has been largely because I’ve been using docker (and docker-compose) more and more on my projects. For example, one of the docker-compose.yml configurations I have for work looks like this:

Vue on Rails

A gentle introduction to modern client-side web frameworks for Rails developers.

Presented at the KL Ruby Brigade.

Featured Pattern: Rescue, Log, Rethrow

Whenever you use a method that you know might throw an exception but shouldn’t, the rescue-log-rethrow pattern is useful to figure out what happened while preserving the contracts implied in the code.

TDD and the Scientific Method

TDD’s mantra is the following: Red, Green, Refactor. In other words: write a failing test, write code to make the test fast, and then make the code better (having the test as a safety net).

A Strange Case of Inheritance Behavior

While working some code to work with the Zuora SOAP API, I got bit by a strange case of inheritance behavior. It would seem that this is related to what self is bound to during the execution of the statement. Here it is, distilled to its essentials:

Javascript Training at Mindvalley Day 2

We’ve commissioned Dekatku to train some developers here at Mindvalley on Javascript, and it’s been a great experience so far! Today is Day 2 of the the training and we’ve covered some really deep topics.

I’ve started wearing my whitebelt again and I thought I’ll put up my thoughts and notes here for future reference. At the start of the session we had one hour to make a TODO application. The caveat being that we’re not allowed to use any libraries or frameworks; just pure javascript.

Answer the Question

The Student was arguing with his Colleague about a piece of code they have written. “Master, please settle our argument,” the student said. “My Colleague insists that the return value of a method should always be an object.” The Master was expressionless. After some a few minutes, he finally replied. “Nil.” The Student’s face contorted into a frown, for he was confused at the Master’s reply. “Master, I don’t understand,” he stammered.

Higher

The Master saw the Student bewildered. Apparently, the Client complained that the temple construction being supervised by the Student is not going according to spec. “I don’t get it,” the Student sighed, “the specs are right here; they are clear, complete, and in black and white. How can he tell me that I’m not following the specs?” The Master replied “I will answer your question, but first you must help me hang a portrait.

The Easy Path

One night during a walk, the Master visited the Student during a project. “Master,” the Student said, “why do we have to write a failing test that exposes a bug before fixing the bug itself? Isn’t it easier to just fix the bug; our Client has complained about it, I’ve tried reproducing it myself, other colleagues can reproduce it too. It’s plain as day that the bug exists.” The Master then asked the Student for a favor.

String Interpolation with Templates Using String#

I was working on a feature for upcloudify that will use Slack notifications instead of email notifications. One of the challenges I faced was how to build-in flexibility for generating messages. I would want that the user be able to provide their own custom notification message, but at the same time be able to provide placeholders for items like the S3 download link.

Opalbox—Run Ruby Code Inside Pages

Opal is a Ruby to JavaScript compiler, and OpalBox is a jQuery plugin to easily create a textarea that can take ruby code and allow it to run.

I just added OpalBox to this blog and it’s been quite interesting. I’ve learned how to resize a textarea based on its content (you need javascript to do that because CSS just doesn’t cut it) and I’ve added in a shortcode.

update:

Exploring Query Objects

A CodeClimate Article gave a number of ways to decompose fat ActiveRecord models, and one of them was: Extract Query Objects. I’ve been trying to explore and get myself familiar with a good standard of how to implement Query Objects, and here is my take.

I’ll be trying out a new format in these articles. I’ll be using something of a Q/A style similar to Socratic Questioning

Using Hash Fetch

I fat-finger my code a lot and produce a lot of typos. I do test driven development so it’s not as bad, but what’s annoying is when I typo a hash key and the test blows up with a failure due to a nil – resulting in a very confusing error message.

ActiveRecord and Forty Two

I was making a gem to have Google Spreadsheets as the backing store for an ActiveRecord adapter when I came upon this interesting method:

Safely Passing Ruby Code in a Rake Task

I wanted to make a rake task that would accept something like 1.month or 1.day as one of it’s arguments. The immediate tool I reached for was eval and it worked like a charm. However, Code Climate (the tool we use to check for static analysis) complains about eval and understandably so; the use of eval is a practice full of danger and security vulnerabilities.

I’m using it inside a rake task that is never exposed to third parties, and anyone malicious enough to run the rake task with a bad parameter to be eval’d would already have had access to the system anyway, and able to wreak even greater havoc than by running the malicious code through the rake task. I believe this is an accepted risk scenario, and Crystal (one of my colleagues who was reviewing my code) suggested that since I had a valid point, I can just turn off the Code Climate check for this particular instance.

I thought that was justified, but I also thought it was a slippery slope. I’m sure there are ways to pass in a string and have it dynamically interpreted, without having to expose the system to a security vulnerability.

Ruby Development in Windows Revisited

Some time ago I wrote about how I set up my machine so I can program hassle-free in ruby while running Windows. It was more of a reminder to myself than anything, if I ever needed to set things up the same way again.

Fast forward to 2015. When a colleague saw my workstation and realized I was running Windows, he was quite surprised and asked me how I was doing it. I thought of pointing him to my old blog post, but I felt that:

  • It was outdated (the setup described was from 2012, written in 2014)
  • It was incomplete (it’s just a checklist of what I’ve installed)

I’ve improved on the whole setup since, and I thought it’s time to share the whole updated setup so that anyone else interested can benefit.

Using Dependency Injection and yield to Refactor a Legacy App

I had to create an automated report for finance and accounting that will send particular columns and their data in a csv once a month.

Being the lazy developer that I am, I tried looking for code that already existed. I was planning to wrap up that code in a rake task and use whenever to schedule a cron job to send the report monthly.

While I was able to find pre-existing code that did what finance wanted (I checked with them as well if the output showed what they needed), the code itself wasn’t easily convertible to a rake task.

Preparing for a Hackathon: Choosing Your Platform

One of the best things you can do during your hackathon presentation is to have your hack available on a publicly accessible platform. You can definitely just host your app in your local machine for the demo, but it is more powerful and impressive if you can involve everyone else in a room and get them to play with your hack during your demo.

Setting Up and Automating my Hugo Blog Deployment to Github Pages

Update

This is largely obsolete. I have setup a new process to deploy to Amazon S3 amd I recommend it over Github Pages.

I’m currently moving my blog posts (and collecting all my blog entries from various blogging platforms) and putting them into Hugo. In case you’re wondering how I’ve set mine up, here’s a guide of what I’ve done.

Redoing my Blogs

Yet again I’ve ported my blog into yet another blogging platform - Hugo. I feel so strongly that I’d be staying for quite some time on this platform that I’ve been porting over all my other posts in all my other various blogs over here. It’s quite an interesting blogging platform. It outputs static files, which means hosting options are very cheap with a wide variety of providers.

About Me

Hi, I’m Tristan! I’m a software developer currently living and working in Kuala Lumpur. You can find me on facebook and github @parasquid. Like many of you, I was a self-taught programmer. It all started many years ago when I was around 9 or 10; my father had an Apple ][+ clone called Minta ][ and I spent many nights typing in programs in BASIC from Byte magazine. After that, came QBasic in high school (I was fortunate to have studied in a more technical school that taught programming and Wordstar, among other things) as well as C/C++ and dBase/Clipper.

How I Hire Developers

I was invited to pressent at the KL Ruby Brigade and I thought I shuld mix things around by talking about something not very technical but still very much relevant to the audience. Since I’m in charge (but saying “in-charge” is a bit of a misnomer since in Mindvalley we don’t really have predefined job descriptions) of the internship program for new tech hires, I figures I should share some of the things I consider when interviewing and hiring people.

Getting Data From a Join Table in Rails

A friend asked in my Ruby Facebook group about a problem he was having that I feel I’ve encountered before (or will be encountering in the future). It’s about having to retrieve data that is associated with a join table.

Here’s the question:

I have set ActiveRecords models like these

I want to do something like current_user.boards.first.role which I expect to load the membership details of current_user AND the first board. Do you have any idea how can I achieve this? Do you suggest another approach?

Setup and Configuration of my Machines

Work In Progress

I’m still in the middle of writing this article, and I probably will be always updating this.

I’ve just recently (re)installed Linux on my Acer V5 122p. Had to fiddle around with UEFI settings thinking to preserve my Windows 8.1 partition, but eventually I had to bite the bullet. I wiped the whole partition clean and turned off UEFI so my installation would be a lot simpler.

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.

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:

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.

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.

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.

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!!

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.

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

View this post on Instagram

@parasquid's #workstation #mindvalley

A post shared by Wu Han Ngeow (@ngeow) on

Look, Ma! Four eyes!!

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

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

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.

Reinstalling Kubuntu

My data drive had some corruption as regards its file system tree, and i was forced to rebuild it. I figured I’ll just reinstall Kubuntu too since I inadverdently installed Ubuntu Desktop, which kinda doubled the applications I have on the menu. Here are some of the things I did in order to remind myself in case my system crashes again: Make a dos partition writable - the options in fstab for the partition should be: user,exec,rw,umask=000 0 0 Get Automatix and install some of the necessary non-free software Install packages used for compiling source code: sudo apt-get install build-essential I’ll add to the list as I walk through the rebuilding of my settings.