Archive for May, 2008

Parse operating system commands from ruby.

Sunday, May 25th, 2008

If you want to execute operating system level commands from ruby the solution is below. it’s quite easy and interesting. What would i say about the beauty of ruby here, Just thanks to ruby creators.

irb(main):001:0> system('ls -l')
total 2240
drwxr-xr-x 15 tarun tarun   24576 2008-05-21 01:33 git-1.5.5.1
-rw-r--r--  1 tarun tarun 2002900 2008-04-21 03:47 git-1.5.5.1.tar.gz
-rw-r--r--  1 tarun tarun  252308 2008-04-21 04:05 git-manpages-1.5.5.1.tar.gz
drwxr-xr-x  3 tarun tarun    4096 2008-05-21 09:42 ruby
=> true
irb(main):002:0>

Radiant on ubuntu 7.10 box

Tuesday, May 20th, 2008

Today i found an excellent CMS based upon RubyOnRails, It’s radiant. I installed it on my ubuntu 7.10 box successfully. It was really great experience for me. I am learning ruby yet but would like to contribute for radiant development soon. Anyway will let you know when i’ll be able to release some thing useful in the favour of radiant. I would like to assist if you have any issue with radiant installation. I may help you.

One more behaviour of ruby

Sunday, May 18th, 2008

Today while working with ruby i noticed one more surprising behaviour of ruby.

1
2
arg1="Ruby", arg2="On", arg3="Rails" 
puts "#{arg1},#{arg2},#{arg3}"

What should be the results?
Well i was expecting to be printed like “Ruby”,”On”,”Rails” but the result was “RubyonRails”, “On”, “Rails”
To understand this behaviour i did some more experiments in “irb”

1
2
3
puts arg1.class.to_s    # result  Array 
puts arg2.class.to_s    # result String 
puts arg3.class.to_s    # result String

Now the question is, Why arg1 is interpreted as an array? and why not the arg2 ?

Ubuntu 7.10 server mod_rewrite not working even enabled.

Thursday, May 15th, 2008

Step 1
Check if mod_rewrite and mod_proxy modules are enabled for apache. To do so put following command:

1
2
a2enmod rewrite
a2enmod proxy

this will enable the required modules if they are not enabled yet.

Step 2
Go to “/etc/apache2/sites-enabled/”. Open the corresponding file for which domain you want to activate rewrite module. In my case that is local server and i checked in 000-default file.
Find the following entry corresponding to your root directory

AllowOverride None

Replace this with:

AllowOverride all

With above steps i found my mod_rewrite module enabled and working sucessfully.

Behaviour of ‘%’ modulus

Monday, May 5th, 2008

Since my ruby learning process, I was really surprised with POLS (Principle of least surprise). I have experience of so many langs but i never use ‘%’ operator for Strings, Arrays.
Evaluate the following expression:

1
puts sprintf('%0.3f' % 3.351)

results: 3.5
well i am fine with this result but what’s about single ‘%’ sign in above expression.
After some R & D, that is basically interpolating the second operand on first one. like if i do some thing.

1
2
str_exp = "%s is going to his %s"
puts sprintf(str_exp % ["Terry","office"])

Results: Terry is going to his office!
Amazing now ‘%’ is operating on string and array. That’s really cool.

One more point is making me surprise about ruby.
Evaluating the following expression:

1
puts -5 % 3

well i was expecting -2. But ruby evaluated to “1″
why?
Will do more research on that.