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
has_many + scope + counter cache
I wrote this blog post partly for myself so I can have a reference for the future and also for other people who might jump into a similar problem and need a solution for it. In my current project I needed to display Users's Questions that have been answered by other users. My set up … Continue reading has_many + scope + counter cache
Scraping: Codewars Top 500 Users
Today I decided to practice my coding skills and took the time to solve one of the Kata challenges "Scraping: Codewars Top 500 Users". So here's my solution. Let me know your comments or thoughts. Note, that Codewars wanted a 1 based index array of Users. I have no clue why. I think this adds … Continue reading Scraping: Codewars Top 500 Users
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
Ruby detective #1 – Singleton Class
I decided to challenge myself with a series of topic about Ruby. The first series is "method lookup". Let's look at an example class. Here I define a simple class Robot which has an instance method 'say_hello' and a class method 'droids' which finds all robots of type 'droid'. Obviously '.droids' method is not there … Continue reading Ruby detective #1 – Singleton Class
How to setup a Rails app with Sendgrid
In order to setup your Rails app with Sendgrid, this is the necessary configuration you need. Store username and password in environment variables. Create initializers/environment_variables.rb Create config/environment_variables.yml In config/environments/#{Rails.env}.rb In config/environment.rb Restart the server and you are good to go.
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?