Thursday, June 22, 2017

At the libray

I was tired of programming (Yes, sometimes it happens to me!) and then decided I needed to read a bit to relax.

Libraries are like Paradise to me. Or, better saying, if there is a Paradise, and by any chance I go ther someday, it will be like a library to me.

And there I was, with my noble computer and a few books, trying to decide what would suit me better, when a few teenagers, boys and girls, sat close to me and started studying Math.

Now, if there is something that appeals to me, maybe even more than programming and books, is Math, my old passion. I've been in love with Math since my early childhood.

I was listening and trying not to interfere in their study. Young people must be allowed to make their onw discoveries. Don't meddle with them when they are doing this. Besides, they were doing pretty well. One of the boys was the leader of the pack and this reminded me of myself, 35 years ago, at National Libray in Rio the Janeiro, leading my own team and preparing to enter college with no money to pay for a prep school.

They were suddenly discussing permutations. And they had an insteresting problem related to the permutations of the Portuguese word CONQUISTA (meaning CONQUER in English).

They wanted to know, first, how many permutations this word has. Then how many of these permutations started with a vowel. Then how many would start and end with a consonant. Finally, how many of them would have the letter "C" before the letter "A".

And using Ruby I could give the answers in a few seconds, by using ths program.

Of course I haven't given them the answers. As I said above, I just don't like to interfere with young people learning. They can learn by themselves. But you may notice some interesting uses of Ruby idioms.

Sunday, June 18, 2017

Downloading eBooks with Ruby

I found an excellent resource with books about Artificial Intelligence here.

It happens that nobody wants to download these books one by one, then I decided to create a ruby script to do this.

I'm posting this here just to tell you Ruby is really a general purpose language. You may use it to many different tasks in your system.

Monday, June 5, 2017

JRuby saved my project

Nobody here ignores I am creating my own full-stack web development framework, the Emerald. And this week, during the first tests, I faced a serious problem.

Emerald is ReactJS-based and uses fetch API to get data from the back-end to the front-end. Of course, there are lots of web requests when you are creating a big (and meaningful) page. And it was then that I started getting lots of Error 500.

My logic was flawless! I tested the backed exhaustively, using both RSpec and command line with curl. 100% of requests working fine in both, but lots of failures when testing with the browser.

After one whole day fighting these errors I remembered a discussiong in a StackOverflow question, when a fellow developer with the name Myst pointed me a big problem when serving static files with Ruby: the GIL.

I won't try to explain the GIL here. Better giving you this link, where you may find more information.

Just to summarize, this is a problem related with threads. Threads in Ruby are an illusion, as this article correctly points out. And this problem turns out to be very obvious when a piece of code is receiving lots of web requests per second. Things will break!

But do not despair, 'cause JRuby is here to help!

As you all know, JRuby is a Ruby implementation written in Java. And Java does multithreading in an easy (not really, but hey... it works!) way.

Then, when I installed JRuby and moved my project to it, everything worked really fine!

This is another example of how discussing things with many people may enlighten your work and save your sanity.