Saturday, September 21, 2013

Experimenting with Rails 4

I had some time this week and I had to try out the Rails 4 and Ruby 2. That's exactly what I did !

I did not try out Key based Cache Expirations or Etag stuff. But I did try out some Server Sent Events stuff. And it went pretty well.

I started out installing Ruby 2 with rvm (I use rvm and don't use to rbenv for some reason). I got through installing 2.0, but when I tried to use a specific gem_set for a test application, I got an error from Rubinius for some odd reason. It said that rbx was to be installed. Somehow it messed up the whole setup and I had to do away with gem_sets. I also had to remove the rbx* installation directory because it was bursting warnings to the console every time the rvm was set.

You must upgrade RVM :)

This benchmark is a great read for 2.0

I wrote the version to the .ruby-version file and that was the start of the project.

I wanted to do something which had some real time communication. Tic Tac Toe seemed to be a nice choice.

There was then this weird problem with sqlite3. It, for some odd reason, could not find the native binding of sqlite3. The path was correctly set but it just could not find the path. I had to spend some hours of debugging to find this out and a lot of googling !

The error was

/usr/local/share/gems/gems/sqlite3-1.3.7/lib/sqlite3.rb:6:in `require': cannot load such file -- sqlite3/sqlite3_ruby (LoadError)

This post saved me at last. Seems like we have to change the actual file of the gem to get this thing running.

In the case of rvm, the file would be under

~/.rvm/gems/ruby-2.0.0-p247/gems/sqlite3-1.3.8/lib/sqlite3.rb

and you will have to change the loading locations relative like

~/.rvm/gems/ruby-2.0.0-p247/gems/sqlite3-X-X-X/ext/sqlite3/sqlite3_native


Once this is done, rails finds it and loads it. This, I think, is NOT good for a Continous Integration Server.

Server Side Events came next. I went through this excellent post on how to get started with SSE. I managed to add Redis pub/sub with SSE after looking through this post. And ultimately used some Thread Processing to get it less Non Blocking as per this post.

Another problem I had was with the servers. I started with Unicorn which was a bad choice. Unicorn kills connections because it is meant for fast processing. For persistent connections, we need to have Puma or Rainbows!

I started using Puma but I did the mistake of not putting

config.preload_frameworks = true 
config.allow_concurrency = true

in the application.rb file. Only one request was permitted because of this flaw. This is to be removed later (I have no idea why this is not default ?).

But that did not solve my problems. Puma constantly gave me errors like

ThreadError: Attempt to unlock a mutex which is locked by another thread

which is not good. It never called the ensure block (don't know why) and I seriously doubt the sockets to be open :|

Thats when I tried Rainbows! I added the rainbow.rb file for server config and started the server. It worked great for me !

I also understood that attr_accesible is no more for rails and its all about Strong Parameters.

I tried adding rails-api to the project (this was my first time). It was only after some time that I realized that the stack for rails-api removes the Rack for Session handling because it aims for the Processing to be as less as possible

Rack::Session::Cookie

I was working with an existing Rails application and I did not want this feature. I tried adding

config.api_only = false

to the application.rb file. But that did not help me.

I had to add the particular require for the api for this to work in the Gemfile

gem 'rails-api', require: 'rails-api/action_controller/api

I wanted to try my bit with the state machine and I managed to write this inside Concerns.

The POC is still incomplete, but I loved doing this after a long time !



Wednesday, August 28, 2013

Vienna to Innsbruck on Rails

We had a short get away the past weekend to Innsbruck. We had decided to board a train from Vienna to Innsbruck after we landed by plane in Vienna. I had looked up the prices and found it to be reasonable.

We reached from the airport to the railway station on time and had to buy the tickets from the vending machine. The tickets cost me about 58 per person. We hoped on the Rail Jet train, in second class and found the cabins to be almost full. I and Reshma managed to get hold of a seat which was made for children. There was a small screen in front of us where all the animation movies were run. So time flew ! We watched clips of Donald, Mickey, Goofy, UP! including others.

The train stopped at St Polten, Linz, Salzburg to reach Innsbruck. It would be too less if I were to describe the scenic beauty of this route. Mountains on the left and right with luscious green fields, cattle and watch dogs, trees matriculately placed all cut and clean. What a view ! A breath taking treat to the eyes. The houses were all so beautifully placed as though a great painter had portrayed his dreams.

If you are plan to go to Vienna try this route ! You won't be sad.


Friday, June 28, 2013

Trip To Kerala

It took me more than a year to find some time to go to my home place. The wait was worth it. I managed to enjoy the Monsoons to the fullest extend, spend quality time with my Mom and Dad, visit Kumarakom with Friends and meet up some NITC batchmates. At the end, 2 weeks was not enough time.

The next time around I will go for more than 3 weeks. :)