Ruby Journal

Testing Whirlwind Tour in Crystal Lang

| Comments

TDD has been part of my development career thanks to Ruby. It is in my nature to try to figure out how to test code with a new language that I learn before picking up other concepts.

Part of my learning of Crystal lang, I am going to walk you through how to write test in build in testing DSL.

How to Consolidate Module Functions?

| Comments

If you have touched module before, you would know that function can be called with module as receiver or as instance method when mixed in class. Today I am going to show you a nitfy trick to consolidate your module function so it can be used for both purposes at same time by using Module#module_function.

How to Add Basic Authentication Into Lotus App

| Comments

Today Lotus Framework officially release its 0.2.0 milestone with many new features. One is the standardised container architecture app generator. What does that mean? That means you could seriously make app with Lotus now.

I know that one of the frequently asked question is how to add basic HTTP authentication for an app. In this tutorial, I’ll show you how.

Quick Guide to ActiveSupport::HashWithIndifferentAccess

| Comments

Hash is beautiful. It is one of many things why I love Ruby. As you might have known, Hash is identified by a key, this key could be either a String or a Symbol. For most of cases, people tend to go for symbol because it would take up less memory (though it might come with a side effect that is Symbol is not GC-colletable (Ruby 2.2.0 does clean it up though)).

There are access usecases that requires our hash key to be interchangable between String and Symbol key. For example, web application request parameter processing.

We could typecast the key to either String or Symbol but it would soon emerge an annoying pattern. Instead, with the help of ActiveSupport, you can create a hash with no differences if accessing using String or Symbol key. Introducing ActiveSupport::HashWithIndifferentAccess.

How to Integrate Sidekiq With ActiveJob

| Comments

One of the hot thing in Rails 4.2 is the brand new ActiveJob gem, this gem consolidate the API for background job gems on the market such as DelayedJob, Resque, etc. Today I am going to guide you through how to integrate Sidekiq with ActiveJob, and you will learn:

  • Set up Sidekiq adapter for ActiveJob
  • Basic of ActiveJob class
  • Advanced usage of multiple queues
  • ActiveJob callback
  • ActiveJob exception catch
  • ActiveJob mailer API

How to Solve Silicon Straits Saigon Hiring Challenge

| Comments

Hello folks

For whom who might have not heard of Silicon Straits Saigon (SSS), this company is one cool company in Vietnam with strong focus in tech such as iOS and Web. When I use the word cool, I did not mean it before I touch base with their hiring challenge.

SSS is known to have a quite unique way to challenge potential employees. They give you a very cryptic page and asks you to hack them.

Well, today I am going to show you how to solve this problem step by step. I hope Mr. An (Director of SSS) won’t hate me for this.

Spoiler alert! Go give the challange a go yourself before reading!