September 29, 2010

fixing cannot open shared object file: Permission denied

Filed under: Uncategorized — Tags: , — yasi8h @ 1:22 am

Got this error when trying to start up apache. My config was as follows.

ruby 1.9
centos 5.3
rails 3

How i got around this is by switching off selinux on the system! Not ideal but it works.

look at on how to disable selinux on your system.


September 28, 2010

Installing rvm/ruby 1.9/mysql2/passenger on CentOS 5.3

Filed under: Uncategorized — Tags: , — yasi8h @ 2:40 am

Things will get a lot easier if you add some custom repos to your installation like

* Install git (sudo yum install git)
* Install curl (sudo yum install curl)
* If you want to install ruby 1.9 through rvm (meaning if you want to compile it by source) you need to install a newer version of autoconf (something thats higher than 2.6 where as CentOS 5.3 comes with 2.59).

tar xvzf autoconf-2.63.tar.gz
cd autoconf-2.63
./configure –prefix=/usr
sudo make install
cd ..


* Install rvm (follow their official instructions).
* Install 1.8.7 first. Then go on to installing 1.9 (or whatever you want to. But additional rubies might have additional dependencies like jruby -> java).

* Installing mysql (sudo yum install mysql-server mysql mysql-devel ruby-mysql)

* Install chkconfig (sudo yum install chkconfig)

* start msql on startup (sudo /sbin/chkconfig –levels 235 mysqld on from:

* Install the mysql2 gem (gem install mysql2)

* Install apache2 (sudo yum install httpd)

* Start apache on start up (sudo /sbin/chkconfig –levels 235 httpd on)

* Start apache and mysql (sudo /etc/init.d/mysql start, sudo /etc/init.d/httpd start)

* Install the needed deps for passenger (sudo yum install httpd-devel apr-devel )

* Note that you don’t actually need to install Apache Portable Runtime (APR) development headers its already there.

* Install passenger (follow the instructions on how to install passagner with rvm).

* I got a error while running apache with passenger. So to make it work i turned off selinux (look at this link on how to do that). Not ideal but it works :P.

* Done!

September 25, 2010

reCAPTCHA with Rails 3 without plugins

Filed under: Uncategorized — yasi8h @ 8:14 am

I needed to get some sort of a captcha solution up and running with the rails project that i am working on. Looked around and sure enough there is a easy solution. reCAPTCHA! its popular and its seems solid. there were some plugins for rails that would making integrating it a breeze too!. But oh well usually things aren’t that easy for me :P. Turns out all of the plugins that i came across don’t directly support rails 3. They are not either updated or maintained. See this is the problem with plugins. You got a ton of them for rails but rails updates so fast that most of the plugins are not up-to-date. Specially if its not one of the super star plugins. Anyways having plugins is good. Having ones that are not updated is much better than having none.

I could have got one of the available plugins and hacked it to work with rails. But me being lazy and all that. I figured i would just implement things my self, like reinventing the wheel 😉 Its pretty simple though. Heres how i did it.

BTW look here for a list of available plugins.

1. First of all head to and get your self registered. It should be straight forward. Obtain and remember your private and public keys.

2. Although i am not using a plugin i don’t want go against DRY completely. So add this piece of reusable code to your ApplicationController. In this set the RECAPTCHA_PRIVATE_KEY to your private key.

class ApplicationController < ActionController::Base


  #try and verify the captcha response. Then give out a message to flash
  def verify_recaptcha(remote_ip, params)

      responce = Net::HTTP.post_form(URI.parse(''),
                                    {'privatekey'=>RECAPTCHA_PRIVATE_KEY, 'remoteip'=>remote_ip, 'challenge'=>params[:recaptcha_challenge_field], 'response'=> params[:recaptcha_response_field]})
      result = {:status => responce.body.split("\n")[0], :error_code => responce.body.split("\n")[1]}

      if result[:error_code] == "incorrect-captcha-sol"
        flash[:alert] = "The CAPTCHA solution was incorrect. Please re-try"
        flash[:alert] = "There has been a unexpected error with the application. Please contact the administrator. error code: #{result[:error_code]}"


3. Add a new partial to views/share and name it as _recaptcha.erb (or as whatever template type you use). This will contain the stuff that goes in to a view where you wants to actually put the captcha in. For ex if you wants to use captcha where users are posting comments. You would render this partial in that view. Put the following code in to it. in this user your public key in place of PUBLIC_KEY.

<%= javascript_include_tag "" %>

	<iframe src="" height="300" width="500" frameborder="0"></iframe>
	<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
	<input type="hidden" name="recaptcha_response_field" value="manual_challenge">
<div id="captcha">
	<%= render '/share/recaptcha' %>

4. In the controller action that handles the post request for the comment creation (continuing the above example) you can use the following helper method to see if the user was able to solve the captcha accurately or not. If not you can get a error message and display that to the user or do something else.

# POST /comments
  # POST /comments.xml
  def create
    @comment =[:comment])

    if verify_recaptcha(request.remote_ip, params)[:status] == 'false'
      @notice = "captcha incorrect"
      respond_to do |format|
        format.html { render :action => "new" }
        format.xml  { render :xml => @comment.errors, :status => :unprocessable_entity }
      respond_to do |format|
          format.html { redirect_to(@comment, :notice => 'Comment was successfully created.') }
          format.xml  { render :xml => @comment, :status => :created, :location => @comment }
          format.html { render :action => "new" }
          format.xml  { render :xml => @comment.errors, :status => :unprocessable_entity }
5.  Thats it!. I did a example project while writing this post. You can get it from
Hope this helps.

September 23, 2010

Evaluating Redcar

Filed under: Uncategorized — yasi8h @ 2:58 pm

Recently i wrote a blog post in our company blog about a editor called Redcar. This is a CC of that. You can find the original artical here .

Intro and Background

It has been about 2 weeks since I started developing RoR and Ruby apps in general at Favorite Medium. When I got started I had an OS X environment that I was new to and Textmate as my editor. I choose Textmate because (let’s be honest…) it seems to be very popular with rails developers. But I had already used and developed in ruby using IDEs such as NetBeans and Rubymine. And I still tend to prefer an IDE over a text editor.

However, now I feel more comfortable with Textmate as I have used it for over two weeks. I will be evaluating Redcar and will be comparing it (well yes, my attitude towards Redcar is that it is really inspired by Textmate) with the experience I had with Textmate. To be fair, I haven’t used Textmate extensively and I am for sure missing out on some great features it may have. So forgive me if I make any inaccurate assumptions in this post.

I am doing this evaluation as a ruby developer. So developers of other languages might look at this editor under a different light.

What is Redcar

Redcar is a free and open source text editor written in ruby (but runs on jruby. You don’t need to have jruby installed in order to install Redcar though. It will auto-magically download a version of jruby and other needed libs for its use). It has a Textmate-like feel to it. It also supports Textmate bundles (one of the strong points of Textmate)! Right now it has an active, healthy community around it. But it’s a very young project that is still under heavy development (ex:- it doesn’t have a save all function 😦 ).

Let’s break it down to pros and cons.


  • It’s Open Source (thus free as in free beer and freedom!)
  • Has a good momentum behind it (at the time of this writing).
  • Supports Textmate bundles (This means a lot. If you have used Textmate you would know that a lot of nice features of Textmate come through bundles) and themes.
  • Written in pure ruby and runs on jruby (this is good news if you are a ruby developer – it will be easy to extend and write plugins in ruby).
  • Cross platform (I think I know more than 10 people who wanted to find ‘the Textmate for Linux/Windows’).
  • Extensible (no editor in this world will ever behave and do everything just like you would want it to. You will have to customize it at some point. And the author can’t implement every feature under the sun. A good plugin system is very important).
  • Easy learning curve if you are coming from Textmate (Redcar supports most Textmate shortcuts although it’s not a one to one mapping. It also has a lot of functionality that can be found in Textmate, where they are identified by the same names).
  • Last but not least, Redcar comes with the ‘cool-latest-greatest’ feeling attached. So you can always feel good using and hacking it.


  • Uncertainty about future support and longevity of the project (Redcar is great. And it’s very promising. But we don’t know where it will stand in another two years. Editors are things that people choose, learn, and live with. If I am to commit my self to an editor I need to be sure that it will be supported and actively developed for the near future. If the development stalls I can’t afford to take it over and carry it on. But then Redcar is so similar to Textmate, so in the event of Redcar suffering a early death one could always go back to Textmate or to one of its many clones out there.)
  • Lack of features – For its age Redcar definitely supports a ton of features! But if you want a full and complete product Redcar is not that (at least at the time of writing it’s not. But I hope it will be able to come to that level in the near future). But with the active development community and the passion behind it. I hope that it can reach a level where it has a healthy set of complete features pretty soon.
  • Lack of maturity – You will see it in the UI sometimes, and everywhere else. This is perfectly natural for a new project.Requirement of Java – I am not sure whether this is even a con. But some people might not feel very comfortable having to install java if they don’t already have it (you already have Java pre-installed in OS X for example…).

All in all I feel I will give this a try and see how things go. I have just gone through the documentation and installed and used Redcar for like 2 hours. You can’t tell what’s working and what’s not during such a small amount of time. Issues with stability and performance might pop up during prolonged usage. But I have a positive outlook about this. There is an upcoming rails project and I am going to use Redcar for it. Let’s see how things go.

If you are excited by new tech and if you are in to ruby/rails and Textmate definitely do check out this new editor. Its worth the while.

Official Site –

Source –

September 19, 2010

Notes from my First Rails 3 App

Filed under: Uncategorized — Tags: , , — yasi8h @ 12:52 pm

I just got stated with rails 3. Got in to some “not too hard to solve but takes a bit of a time to figure out a fix” type of issues. This post is a account of the problems and the solutions/work arounds i applied.

Notes on installing/using Mysql2

undefined method `errno’ for #Mysql2::Error:0x00000100ff0c98

On running rake db:create if you get a error such as:

undefined method `errno' for #Mysql2::Error:0x00000100ff0c98

this is a bug. Use the latest version of mysql2 adapter by adding this line to your Gemfile

gem 'mysql2', :git => ''

then it should be fine.


“Can’t connect to local MySQL server through socket ‘/opt/local/var/run/mysql5/mysqld.sock’ (2)”

If you get “Can’t connect to local MySQL server through socket ‘/opt/local/var/run/mysql5/mysqld.sock’ (2)” execute: locate mysql.sock and use the result in place of “socket: /Applications/MAMP/tmp/mysql/mysql.sock” which was where mysql.sock was located in my mac

socket: /Applications/MAMP/tmp/mysql/mysql.sock

Notes on installing Paperclip

make sure you have imagemagick installed

Notes on Using rails-ckeditor with rails3

If you get a error such as

NameError (uninitialized constant Ckeditor::Utils):

Then you need to patch rails-ckeditor


September 17, 2010

Running a Groovy Script as a Linux Daemon

Filed under: Uncategorized — Tags: — yasi8h @ 9:54 am

So you have a groovy script and you want to write a little bash script to run it as a linux damon (urr… well the script will only try and start stop your program. It doesn’t make just any program a daemon.. duh..).

Note that this was tested on a Ubuntu 10.04 LTS system. And it should most probably work on any morden redhat/debain biased distro.

This script is heavily biased on a script written by Joshua Davis.

Get it here. Don’t be lazy. Read the script and how it works should be self explanatory.

September 7, 2010

Sinatra and Padrino

Filed under: Uncategorized — Tags: , — yasi8h @ 4:16 am

I am doing some R&D on Sinatra and Padrino at work. As a part of that i am going to write this blog post about Sinatra and Padrino. I always wanted to learn about these neat libraries and frameworks in the ruby world. And now i am getting paid to do it ;).

My main focus would be on Padrino. However i would give a basic introduction in to Sinatra (so that i can learn about it in the process). But please keep in mind that i am no expert in Sinatra or Padrino. So if you are just getting started with these you should read the official documentation that can be found on their official sites (Sinatra and Padrino).


Sinatra is basically a DSL for creating web applications easily (you can create a web app that outputs hello world in approx 6 lines!).

# myapp.rb
  require 'rubygems'
  require 'sinatra'
  get '/' do
    'Hello world!'

Sinatra is not a full fledged feature rich web application framework like Ruby on Rails. It is not meant to be anything like that. But its light weight and it suites for certain types of web applications. For example if you want to build  a web app that ‘tries to guess who your real friends on twitter are and who is not’, Sinatra would be a good choice. As this application is a ‘tiny web app’.

Sinatra can also be used to write Rack middleware, Rack Applications and Rails metals (read the Sinatra::Base – Middleware, Libraries, and Modular Apps section in Sinatra: README).

Main Features of Sinatra

These are some of the main features that you’ll get with Sinatra.

  • Routes
    • You can use routes to capture HTTP requests from clients and respond to them. A typical Sinatra application would consists of many such routes. You can use http verbs such as get, put, delete…etc in these.
    • They can include named parameters such as the example (taken from the official readme). The Routes are matched/prioritized according to the order they are defined in source code.
    • get '/hello/:name' do
          # matches "GET /hello/foo" and "GET /hello/bar"
          # params[:name] is 'foo' or 'bar'
          "Hello #{params[:name]}!"

  • Views
    • You can use views with Sinatra. It supports static files (ex: example.html, style.css…etc) and rendering engins like haml. You can put your views in separate files or write them inline.
    • And just like in rails whatever instance variable you set in the context of your routes can be accessed in your views.
  • Helpers
    • You can define and use helpers in your routes and views.
  • Filters
    • You have before and after filters. They would run before a request is sent to the appropriate route and after a response is sent by a route. You can access and modify the request and the response object in before and after filters respectively. You can set instance variables in filters that can be accessed by other filters and routes. And whatever instance variables you set in routes can be accessed in after fileters.
  • Error Handeling
    • Sinatra have error handlers that lets you handel exceptions (things like NotFound a.k.a. 404 or your own custom exceptions.

Sinatra is a grate tool to get something done without having to put up with fat web frameworks like Ruby on Rails. But it might not be a very practical choice if you want to do a complete web application with all the bells and whistles. This is where Padrino comes in. It is build on top of Sinatra and adds a significant amount of features to Sinatra.


When learning about this framework i took most sensible approach a person could take. To follow the official guide and try creating a sample blog! Every web application framework has a tutorial on ‘how to create a blog with framework X in 5 minutes’ these days :).

I managed to follow the tutorial without much problems and create the application with little time. I did ran in to a small problem on the way though. So let me tell you that if you ever try to run something like $ padrino rake ar:seed. There is no such task. You should instead try running $padrino rake seed (this generates some authentication data for your admin application, there by letting you log in to the admin application, in your project. This is of course assuming you generated a admin application).

Comparing with Sinatra, i definitely liked the generators that Padrino provides. I don’t think generators would add a lot of overhead to a application. As long as they don’t generate too much bloat (like rails did sometime back). Padrino will definitely remind you of rails if you have ever used it. But its a bit different.

Padrino is framework agnostic (at least they claim to be). Wich is really nice because that mean you can use any (almost) framework you want with it. It can be very modular this way as you can choose and build your application with all your favorite frameworks. So the generator lets you choose what frameworks you want to use for testing/ORM/templating/jscripting…etc. I Initially used the options used in the guide. Then I tried using a different ORM (I used ActiveRecord initially) which is DataMapper (which was new to me).

Ramaze is a another web framework (there are so many frameworks in the ruby world… i guess its a good thing) that is both agnostic and modular some what similar to Padrino.

The file structure in Padrino is much simpler when comparing with rails. Its easier to work with. But i didn’t like having to write explicit statements to render views inside my routes. In rails this would not be needed (usually). The reason given by the Padrino team for this that its more clean and concise. They do have a point but i would prefere learning about some conventions over having to explicitly write statements to render my views every time i want to render a view.

Padrino supports something called ‘Mountable Apps’. Just like Rails Engines. It basically lets you have a app(s) inside a app. Although i am not exactly sure where (some sample usages are given in the Mountable Application section in i would use this functionality, it sound pretty cool.


September 6, 2010

Fixing: ERROR: While executing gem … (Errno::ENOENT) No such file or directory

Filed under: Uncategorized — Tags: — yasi8h @ 7:03 am

This is a very specific (can occur with rvm, but i am not exactly sure what caused it) error that i encountered while trying to install rails + ruby 1.9.2 + rvm + OS X Snow Leopard. If you get a error like the following try creating a directory called cache inside your rvm gems folder. For me the error was occurring because i didn’t have a cache directory.


boxdundu:~ y8h$ gem install sqlite3-ruby
ERROR:  While executing gem … (Errno::ENOENT)
No such file or directory – /Users/y8h/.rvm/gems/ruby-1.9.2-p0@rails3/cache/sqlite3-ruby-1.3.1.gem
boxdundu:~ y8h$ gem install sqlite3-rubyERROR:  While executing gem … (Errno::ENOENT)    No such file or directory – /Users/y8h/.rvm/gems/ruby-1.9.2-p0@rails3/cache/sqlite3-ruby-1.3.1.gem


boxdundu:~ y8h$ mkdir .rvm/gems/cache

About OS X and MacBookPro…

Filed under: Uncategorized — Tags: , — yasi8h @ 6:16 am

I was asked to read up on Mac OS X by my new employer as i am going to be using it for the first time, starting next week. I’ve always wanted to get a Mac for its polished design rich UX, but felt its way overpriced.

The following is a summery of what i learned from my reading, about OS X and macs in general. I haven’t really used one yet so there will be a lot more things that i have to learn. And some of my opinions and attitudes might change after I actually use a mac for sometime.

Linux and OS X

I am familiar with Linux, Ubuntu to be more specific. I love this Debain based distro. It seems that OS X is basically Drawin with some frameworks and layers of code (a windowing system like X, and a file manager, set of APIs…etc) on top of it. Drawin is a open source (have some proprietary drivers in the Apple’s distribution) *nix OS that is developed and maintained by apple. Its based on the hybrid (monolithic + micro) XNU (X is Not Unix, sounds a bit familiar ugh? ;)) kernel. Darwin is POSIX compliant hence  it should be easy for me to get used to it since i am coming from a Linux background. Almost all the command line tools that you expect from a standard Unix system should be there. But what worries me the most is the lack of something like APT in Darwin. There seems to be several other package management systems for Darwin such as MacPorts, Fink…etc. But from what i read i don’t think they can match APT. After all APT have super cow powers ;). But the fact that i should be able to compile most open source apps that runs on Linux (or POSIX compliant Unix systems to be specific) on Darwin makes me feels good.  But then again, OS X shouldn’t be Linux, its a different OS with different pros and cons. I shouldn’t try to make it something that it is not.


An overview of the OS X architecture (from Wikipedia).

I think the Classic API (the one which was used in older versions of Mac OS) is not supported any more in the latest versions of Mac OS X. A more up to date diagram can be found here on Apple’s developer portal.

I wrote this part after actually receiving a MacBook Pro

Package Management Systems

I don’t think os x have anything as good as apt-get :). But there are some package management systems like MacPorts and fink. I installed MacPorts and used it to get some utilities installed. It was a bit slow, after all it have to downloaded the sources and COMPILE them. But it managed to install the utilities without me having to interfere in any manner.

You can install software for Mac by downloading and running a “dmg” file. When you open a dmg file it gets ‘mounted’, and the OS asks you whether you want to run the software or install it. If you want to install it you need to drag the software icon to the application folder icon, on screen. Which is a bit confusing for me. I mean why not just give two buttons saying run and install?


Coming from gnome/windows background i find the OS X GUI a bit different. There are some fundamental differences in the GUI. But i think i am getting used to it pretty fast. As long as you have google there should be no reason for worry. I miss the maximise button that you have in windows/gnome…etc. Here you get the ‘+’ button but it doesn’t always maximise the window.

I find the dock annoying at times because it takes a lot of screen real estate. Hence i hide it and made its size smaller. I think i will feel comfortable with my new Mac with time. I need to use it, and tune it to my own needs. Just like any good system.

Keyboard and Mouse

The keyboard is a bit different from the PC keyboard. There is a additional command button. There is no more ctl + C and ctl + V but there is command + C and command + V :). I am using a MacBook Pro and the touch pad here took me a few minutes get used to. You can use some multi touch hand gestures to do things like scrolling, rotating, zooming…etc. It actually took me a while to find out (from a coworker) that you can do a click with two fingers to get the same effect of a control click. I like these features.

Availability of Software

Unlike for Linux you get most of the popular software for OS X. Its the second platform most software products choose to support. Which is sad (as a Linux user). I got all my favorite browsers, IDEs, VCSs …etc and IM clients installed on the Mac today and it was more or less pain less.

Getting ruby on rails up and running was a bit of a problem though. Ruby comes installed in OS X. But its a older version (1.8.7). I wanted to get the latest working with RVM. Which i did without much problems (to install RVM: bash < <( curl There were some problems when trying to install rails, sadly. I am still trying to figure out how to get it to work.

The Apple Factor

Everything about the MacBookPro is ‘cool’ :). Apple have thought a lot of design and UX. When designing their hardware and their software. Sometimes i find the UX has to much eye candy (for a example the dock). But all together they have done a fair job.

All in all i find it to be a please experience. Its not that hard for someone who was in Ubuntu/Windows to switch to Mac. Specially if you are coming from a *nix background you have all your unix tools (or at least most of them) available to you. Most of the free software out there that runs on Linux can be run on OS X.

I am thinking of getting some more software installed (like Textmate, RubyMine). I will be blogging about my experiences with time. So far it have been fun!

Blog at