There is trouble brewing, or: Openssl issues on Ruby with Homebrew

This post is to describe an issue I’ve run into using < 2.3 versions of Ruby on OSX with rvm and brew.

Don’t even get me started on working with older versions of Ruby — we have some maintenance projects running in ruby-1.8.3! Even modern Rubies may give you a hard time, however, and this is one of the times. Actually, I am writing this post as a reminder for me because I ran into the same problem twice now, and what is worse, the second time it took me nearly the same amount of fruitless googling to solve it as it took the first. And the solution was the same! So, let us proceed with order.

Continue reading “There is trouble brewing, or: Openssl issues on Ruby with Homebrew”

asdf the “easy to write and hard to read” version manager

As a Rubyist one of the first thing you end up doing is to manage many different Ruby versions on the same machine. As a matter of fact, one of the first steps in setting up a new workstation is to install some kind of version manager like RVM or rbenv.

Unfortunately it doesn’t end up simply like this…

Continue reading “asdf the “easy to write and hard to read” version manager”

Wrap and iterate with the power of yield

Iterating over a collection isn’t rocket science. Obviously if you need to iterate over a really big collection you may need to adjust your strategy but it is something that in the vast majority of programming languages you get quite for free.

In Ruby for example you can just send the each message to your collection together with a block of code. The block will be executed for each element of the collection itself.

But what if you need “something more” from the objects you’re iterating on? If, for example, each element of your initial collection is an array and you want to abstract away how you access each of its elements? What options do you have?

Continue reading “Wrap and iterate with the power of yield”

Euruko 2016 – Ruby is dead, long live Ruby!

It has almost been three weeks since we (me and two colleagues) came back from a wonderful trip to Sofia. Thanks to Mikamai (and I will never stop to be thankful for this! 🤗) we had the opportunity to attend the 2016 Euruko conference.

Euruko2016

Considering the list of speakers, all well known for their accomplishments in and out the Ruby community, I was overexcited by the time we had the confirmation of our trip.
Personally I was particularly thrilled to listen to the two keynotes. It doesn’t happen everyday to listen to Matz and José live! 😉
Anyway, enough fangirling!

Continue reading “Euruko 2016 – Ruby is dead, long live Ruby!”

Calculate an approximation of a server response time with Rails and Apache

This post was born from the need of calculating some kind of server response time during a page request. Although this is not perfect, because doesn’t account for the time that the response takes to reach the user, it’s pretty accurate on the server side.

In order to have the request start time I added this header in the Apache configuration server:

RequestHeader append Request-Started "%t"

I didn’t use a simple before_filter because it would have not considered the time spent in rack middlewares, for example.

Now in my action I can count on a request header like this:

Request-Started: t=1460473552166899

Note that this timestamp is in microseconds.

Now in the page view template I can get the total request time doing some simple math:


server_response_time = current_time - time_from_header

def current_time
  Time.now.utc
end

def time_from_header
  Time.at(request.headers['Request-Started'].split("=").last.to_i / 1_000_000).utc
end

Improve your developer skills with Codewars

Some weeks ago in Mikamai we started using codewars, a website that aims to improve your programming skills via gamification with code challenges.
Since I’m a junior developer willing to improve my Ruby knowledge I have used it a lot lately, so let’s see how it works.

After signing up and completing a simple code problem, you can start browsing some kata and boost your programming skills.

Why kata? Codewars has this oriental, martial arts flavor so you’ll find words like kata and train for quizzes, kyu and dan to classify user rankings.

Personally I’m really enjoying the site and the learning process.
The number of Ruby katas is huge, and I find expecially nice the chance to see other users solutions after you complete a kata, so you can see super-compact solutions such as:

def anagrams(word, words)
  words.select { |w| w.chars.sort == word.chars.sort }
end

or regular expressions usage to solve a wide range of problems:

def pig_it text
  text.gsub(/(w)(w+)*/, '21ay')
end

and you can write your own tests while you’re training a kata.

You can choose among many programming languages (I’m looking forward to see Elixir or Rust in the future).

Ruby builtin Hash

Today I was really debated whether to publish another post about SQL (it was a reflective post on how ORM may have ruined us) and a post about the introspection of a ruby builtin feature.

I hate to be repetitive (the SQL post would have been my third post in a row) and I always find enlightening to study language internals because there you can see the real programming magic. So, why not to post on the Ruby Hash and its lookup complexity of O(1)?

Then I realized there’s plenty of blog posts about the Hash object. And one of these is written so well that I could never compete.

What I really liked of this post is that the author is not only explaining the theory behind Hash, but he also try to reimplement it.