Arabs who are interested in Merb and Merb-book

So many developers from various countries had corresponded to Matt Aimonetti’s article on open merb book, and an early version of the book is out there.

However lot’s of work is still needed in both directions: contribution and translation ,so: dear Arabic developers wherever you are, if you are interested in Merb framework, have the ability to write in native Arabic, and willing to help contributing or translating the merb-book , then please don’t hesitate to send me an email. Your efforts is gonna be highly appreciated by Merb community, and you personally gonna gain lot’s of knowledge in Merb framework, how to contribute to open source, and how to write a book.

Waiting to here from you…..

What i liked most about rails 2.2

Well, finally it’s there, many important improvements were added to rails 2.2, and yet new things are on the way, you can check this blog post to check what’s new, while i’m gonna list here what i really liked about the new version of rails 2.2:

Thread safe

If you really don’t know what it means, then most probably you want to check this post by Charles Nutter, however in short terms: threaded rails with a native threaded implementation of ruby (jruby in our case) will save your memory , make your app more scalable, and most importantly it will make the app deployment very easy, specially when glassfish gem or even with jetty-rails gem is used.

And you Just have to make sure your app is thread safe, follow this post by Pratik Naik.

Well documented

So many people complained about this point before, but this a fact is from past now 🙂 , just fire your terminal , go to ur app path, and run :

This will create doc/guides in your project root , with a comprehensive rails guide to learn from.

Internationalization or I18n

A support for i18n is there now, so  you don’t have to install any extra gem or plugin, a comprehensive demo is put there, just be aware that you don’t need to install the plugin when following the demo, cause it’s already there in rails 2.2 .

Also check the I18n screencast by Ryan Bates.

Performance + JRuby compatibility

  • Connection pooling is added in this version of rails , which will save the time of opening(open connection with the db server +authentication) and closing the connection for each http request, so now a pool of connections will be used to serve incomming http requests, instead of opening a new connection for each request.
  • There were efforts to enhance the erb system , which will affect the rendering process time.
  • Rails 2.2 is fully compatible with JRuby which is the fastest ruby implementation at the current moment, and that will give you better performance when JRuby is used ,specially that the JRuby team is continually and actively(a release every 3-4 weeks) working on optimizing the overall performance and for rails usage as well.
  • Memoization term was introduced to cache values, check this screencast by Ryan Bates.
  • ETags and saving your server the hassle : if u don’t know about ETags then it’s time for that , check this post by  Ryan Daigle.What matters here is that the new support from rails to ETags  will give you 2 enhancements :
    1. Frontend enhancement: the client browser will use it’s cache to render the needed data and thus won’t need to issue a new request to your server to bring the data, thus a faster rendering on client side.
    2. Backend enhancement: your ror servers won’t need to handle some logic to respond back to your client browser requests, thus free the processor to handle other logic.
  • Template views will be cached now for production mode.

Caching actions without their layouts

Now it’s possible to cache an action without it’s corresponding layout:

This is really cool, cause in many cases our layout will contain some info related to user status in the website.

More additions might be very interseting for you

As for me, those enhancements and additions listed above , where the most benifitical for my work, other things might attract your attention, for more information about what’s new, i strongly urge you to look at Ruby on Rails 2.2 PDF by By Carlos Brando.

Ruby introspection 2

I wanted to start blogging on ruby reflection api, but i just realized that i have to give a second part of my previous article on ruby introspection .
So here we go:

Also i strongly recommend that you look at the ObjectSpace module which contains a number of routines that interact with the garbage collection facility and allow you to traverse all living objects with an iterator, however this is a little example taken from the official api documentation :

Also if you feel like you are eager to see low level introspection , then check this great post.

In my next article, am going to blog on ruby reflection api , hope to finish it soon 😉

Changing database encoding from latin1 to UTF8

Now a days, UTF-8 is the most used data encoding format, and the fact that your database is not using UTF8 encoding is really annoying, specially additionally when it comes to integrating different systems, that has no one unified encoding format.
So if you think it’s time to change your data encoding to utf8 format, then here what this post is all about.
I’ll list here the steps to do so, i just have to clarify that the main data encoding here is windows-1256 (which is the main Arabic encoding used in web applications), but it’s saved in latin1 encoding in the database (mydata ->windows-1256 -> latin1) ,also note that i’m using Mysql database.
Here are the steps:

  1. Export (only) the schema of the db,without “set Names” phrase in the outputted sql file, this will bring you back the data in the original encoding (windows-1256)
  2. Export the data of the db without “set Names” phrase in the outputted sql file, this will bring you back the data in the original encoding (windows-1256):
  3. Change the encoding of both files from arabic to utf8 -check the notes if you r using windows
  4. Open the file ‘db_name_schema.sql’ with any editor and replace each “DEFAULT CHARSET=latin1” phrase with “DEFAULT CHARSET=utf8” one
  5. Make a new db ,encoded in utf8:
  6. Import the schema and data in utf8 encoding:


  • If you are wondering why to separate schema from data upon exporting , then the answer is that the operation of replacing “DEFAULT CHARSET=latin1” phrase with “DEFAULT CHARSET=utf8” one , is taking place only on schema files, so it’s recommended to separate them so that you dont stuck when loading the big data files.
  • If you are a windows user and can’t use iconv , then u can use any editor to do the job for u, try scite or note++ or even dreamweaver


Grails and Arabic localization

A little problem that i faced with grails , was setting the locale dynamically, i followed this nice article , and here is how i could manage it :

  1. I made a new file called that contains the arabic localization under the i18n folder.
  2. I made a simple beforeinterceptor:

Of course you can use grails/Filters to save yourself repeating the same code in every controller.

However what i want to mention is the locale object, which in case of Arabic localization, was seeking the country argument ( “JO” in our case) :

While for other localizations like German one it doesn’t seek this second argument, so this snippet of code will work for them 🙂

Also you can change this country argument value to match this rule :

The country argument is a valid ISO Country Code. These codes are the upper-case, two-letter codes as defined by ISO-3166. You can find a full list of these codes at a number of sites, such as:

I hope that was helpful 🙂 , enjoy!

Ruby dynamic method calling

I’m pretty sure that you have heard lots about ruby, specially as being a dynamic language, you can create methods on the fly, add instance variables, define constants and invoke existing methods dynamically , and that’s what this post is all about :

As you know in ruby you can call a public instance method directly ,ex :

One way to invoke a method dynamically in ruby is to send a message to the object :

A second way is instantiate a method object and then call it:

And the third way is to use the eval method:

Well, when to use what?

look at this script, it will be used to benchmark the 3 ways of calling :

Well as you can see, instantiating a method object is the fastest dynamic way in calling a method, also notice how slow using eval is.

Also when sending a message to an object , or when instantiating a method object , u can call private methods of that object :

Ruby introspection

Hi, this is my first blog post!, i’m already done of reading this artilce on groovy’s lang introspection , and i wanted to submit the equivalent one for ruby, so all you need now is to fire your irb and follow me 🙂 :

As for the Dynamic method calling introduced in that article , check this post 😉

*Update : Check the second part article of ruby introspection, for more info on this topic.