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.

Read On →

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:

Read On →

Safely Passing Ruby Code in a Rake Task

I wanted to make a rake task that would accept something like 1.month or 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.

Read On →

Evaluating Hackerrank for Tech Hiring

We were looking at Hackerrank to see if they can help us with alleviating some of the interview and review load on our senior developers.

Read On →

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.

Read On →

Codility - PermMissingElem

Read On →

Codility - FrogJmp

Read On →

Codility - TapeEquilibrium

Read On →

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.

Read On →

Have Rails.logger Output Sent to the Console (surprise, created_at field is protected from mass-assignment)

While working on a feature, I was wondering why my test is returning 0 records when I’m quite sure the query was written properly (it’s just a very simple query regarding date range).

Read On →