Archive

Archive for April, 2008

RubyOnRails Plugin: Auto Tags

April 29th, 2008

Announcing the release of this tiny useful plugin AutoTags.
A couple of weeks ago I travelled to Mumbai in train which was a long 17hrs journey… and I utilized that by coding down the idea while travelling. So here it comes…

AutoTags, an open source project, is a plugin for RubyOnRails applications to automatically generate the relevant tags for the provided content. Its quite simple to use and provide easy integration with ActiveRecord. The plugin is very useful for social applications, community websites and all those networking applications where there is a scope of user generate content to be tagged. No more heck for the admin to sit and add the tags to the content or waiting for the users to add the tags to their content.

For installation and usage read here.

If you liked the plugin then please recommend me on workingwithrails.

sur auto_tags, networking, open_source, plugin, rubyonrails

New in Ruby 1.9: Threads

April 26th, 2008

The ruby is getting changed and improved a lot with every release. No doubt the existing demerits of rails are soon going to be history.

Currently for my rails applications I am running Ruby1.8… and exploring 1.9 to get ready as we are heading with nice speed in the rails developments. Modrails has already started making waves all around.
Soon I would be publishing a couple of posts on threads, processes and sockets in ruby… here is a bit on how they are going to be different in Ruby1.9.

In Ruby1.9 the threads implementation is going to be really different than what we all know/do in Ruby1.8. The Ruby1.8 uses a single native thread and runs all Ruby threads within that… which certainly protects the Ruby threads to take on much responsibilities and to completely leverage the hardware with multiple processors.

Now, the good news, the Ruby1.9 allocates a separate native thread for every Ruby thread. But at this very moment it is not fully functional… as because of some C libraries, used here, are not thread-safe that it will not allow Ruby1.9 to take control on multiple native threads. Still, great signs of improvements in these directions… It has been mentioned that this restriction will be removed in the upcoming versions of Ruby1.9 and there will be full fledged implementation of multithreading in Ruby with multiple native threads, and the charm of parallel execution… means a lot more scope of improvements for all related libraries, frameworks built on the top of Ruby.

sur ruby, ruby1.9, threads

Avoiding the Distractions

April 21st, 2008

I was reading something about how to avoid the distractions and the article exemplified it using a scene from the Indian mythology ‘Mahabharata’ where the Guru Dronacharya asked all the students to aim at the bird’s eye sitting at a branch of the tree, then he asked what you can see… most students replied they can clearly see the branch, tree and the bird… only Arjuna said he can only see the bird’s eye… At that very young age he had learned the willingness of how to avoid the distractions which are joyful to you.

Here in this post I admit that gaming, especially playing ‘Tekken3′ is one of the biggest distraction for me. As whenever I spend continuous hours on work, I get the time out and start playing ‘Tekken3′ which surely very much joyful. But, actually I know I make reason to myself to play that game and not actually to take some time off to have rest. Playing game certainly gives some enjoyment but not exactly the rest, I still be in the same position on my desk, sitting on my chair, and playing the game instead of doing the work… so its almost that I am doing work and not giving rest to my body. So, basically I was not willing enough to say that the game is a distraction for me… instead I kept on saying that I am playing it to take a time out of the work, But its for sure a wastage of time. And now I am sure enough to say its purely a wastage of time as I have made a resolution to say NO TO GAMES. I am in my 20s and need to conquer many of my dreams and need to work really hard to do so… which will certainly require killing of all these distractions in my life. And I’ve started very well by signing off from games… Though its true that I have a dream to run a Gaming company… and if I would be able to do so… the Gaming will also be my work ;)
So, to take time out from my work I would rather now read my newspaper and I can now allocate the time I used to spend in reading newspaper back to work. Reading newspaper is a required task to be accomplished and would not be a reason to take a forced time out from the work… moreover I can relax while reading newspaper that I couldn’t do while gaming. I must say I have dumped a biggest distraction of mine.

sur distractions

Acts as solr: Logical Search

April 15th, 2008

There are a couple of ways described in acts_as_solr documentation for the logical search, with AND or OR operations. But I needed to dig a bit into the code as the documentation is not complete and doesn’t suggest all the possible implementations of making the complex Logic Gates for searching.
Here I am consolidating various possibilities of Logical Search…

Find all blogs with category ruby or rails


  Blog.find_by_solr("category:rails category:ruby", :operator => :or)

another way


  Blog.find_by_solr("category:rails OR category:ruby")

Find all blogs with categories ruby and rails

  Blog.find_by_solr("category:rails category:ruby", :operator => :and)

another way

  Blog.find_by_solr("category:rails AND category:ruby")

Grouping for more precision

NOTE: mind the grouping using parenthesis, you might get unexpected results without proper grouping.

Find all blogs with categories ruby or rails with author Sur

  Blog.find_by_solr("(category:rails OR category:ruby) author:sur")

Find all blogs with categories ruby AND rails with author Sur

  Blog.find_by_solr("(category:rails AND category:ruby) author:sur")

Find all blogs with categories ruby or rails with author Sur or David

  Blog.find_by_solr("(category:rails OR category:ruby) (author:sur OR author:David)")

Find all blogs with categories ruby and rails with author Sur or David

  Blog.find_by_solr("(category:rails AND category:ruby) (author:sur OR author:David)")

sur acts_as_solr, logical_search

Mongrel to THIN

April 14th, 2008

For Rails applications I am using THIN on my local machine since a couple of weeks and found it better than Mongrel. I’ve started replacing mongrel with THIN on servers as well. THIN leverages the best of the available resources… It uses mongrel’s parser along with the Eventmachine and the Rack Ruby libraries which together provide better speed, greater requests/sec and certainly consumes lesser memory.

Install THIN by issuing

  sudo gem install thin

THIN accepts more or less similar switches as that of mongrel. You start THIN by issuing

  thin start -p 9090 -d -e production

-p — port, defaults to 3000
-e — environment, defaults to development
-d — daemonize mode

THIN provides an in built support for clustering and running multiple servers for the same applications. You can start say 3 servers for the single application by providing the -s switch as…

  thin start -p 9090 -d -e production -s 3

And similar to mongrel it will start three servers on the ports 9090, 9091 and 9092.

sur mongrel, thin