Codility Cyclic Rotation Challenge in Ruby

I tasked myself to do some Codility challenge and solve it in Ruby. I picked the first at hand and here it is, the Cyclic Rotation, all covered in tests passing in 100%.The task is as follows: Task description An array A consisting of N integers is given. Rotation of the array means that each … Continue reading Codility Cyclic Rotation Challenge in Ruby

How to validate ruby Hash recursively?

Recently, I've tasked myself to write some Ruby code that would validate Hash recursively against an existing template. The idea is that given a template hash validate whether a provided hash matches the template keys and data types. If the hash matches the template keys return true, otherwise raise an error. Here is how approached … Continue reading How to validate ruby Hash recursively?

How to implement your own Struct class in Ruby? Metaprogramming in Ruby, part 2.

You probably already know Ruby class Struct. It allows you to create a simple class with the properties that were passed as arguments to its initializer. Also, it will run a block that was passed to its initializer within the newly created class'es scope thus allowing you to define methods, etc. Let's try to implement … Continue reading How to implement your own Struct class in Ruby? Metaprogramming in Ruby, part 2.

Metaprogramming in Ruby, part 1

I decided to challenge myself to write code similar to what can be found in every Rails application.rb file. TestApp::Application.configure do # Settings specified here will take precedence over those in config/application.rb # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.consider_all_requests_local = … Continue reading Metaprogramming in Ruby, part 1

Dynamically fading flash messages in Vue.js and VueX

We will be creating dynamcally fading flash messages with Vue.js and VueX. Let's say you want to display a flash message on a certain condition and you want that flash to show only for a couple of seconds and disappear afterwords. It is very easy to implement it yourself within a minute without any 3rd … Continue reading Dynamically fading flash messages in Vue.js and VueX

How to implement Rails params from the ground up in Ruby?

Hi guys! This time around I am going to show you how to implement Rails params completely from the ground up. As you probably already know, Rails has something called strong parameters. This is a security practice to prevent accidentally allowing users to update sensitive model attributes, for example "admin" flag in user model in … Continue reading How to implement Rails params from the ground up in Ruby?