C S Shyam Sundar's Weblog

the blog officially closes down …

Posted by: Shyam Sundar on: November 3, 2009

Subdomains and Rails

Posted by: Shyam Sundar on: October 15, 2008

Rails framework has many plugins for handling subdomains. One of the recommended plugins to achieve the same is Subdomain-fu.

Subdomain-fu uses Rails’s URL Writing mechanisms to provide an easy and seamless way to link and otherwise understand cross-subdomain routing.

Before attempting to know, I suggest to read a write up by Jamis Buck on understanding how rails routing works here.

Palani, my peer in Thoughtworks and I worked on implementing subdomains in our current project.

In our opinion, subdomain-fu works well as advertised, but, we had to patch up lib/subdomain_fu/routing_extensions.rb and changed the recognition_conditions_with_subdomain routine.

By default, it was taking conditions hash and we changed it to use requirements hash. The effect is that we can now pass :subdomain symbol as another parameter in map keyword of routes.rb.

The recognition_conditions_with_subdomain routine becomes like this:

def recognition_conditions_with_subdomain
result = recognition_conditions_without_subdomain
result << "requirements[:subdomain] === env[:subdomain]" if requirements[:subdomain] && requirements[:subdomain] != true && requirements[:subdomain] != false
result << "SubdomainFu.has_subdomain?(env[:subdomain])" if requirements[:subdomain] == true
result << "!SubdomainFu.has_subdomain?(env[:subdomain])" if requirements[:subdomain] == false
result
end

Routing works amazing!

Its true!

I tried parsing a 15MB, proper XML file with nearly 20 sub nodes for a parent node.

Being newbie to Ruby, I came across the default option of REXML. I instrumented the code using the Ruby benchmark API.

A Single simple XPath query for one node to traverse thro’ the entire XML file using REXML takes 2043 seconds.

The same using LibXML takes 2 seconds.,

This shows the power of a native C library and a wrapper!

Tags: , , , ,

the rails way of ordering models

Posted by: Shyam Sundar on: August 5, 2008

Being a newbie to rails, I find many interesting things to do a certain operation. They call it the ruby or the rails way of doing things.

The Fine Print:

The find method, supports passing o a parameter to order based on table columns in ascending or descending order.

Example:

@users = User.find(:all)

Here @users, will have all the users in user table ordered by id.

Suppose, if we want to order by ID in reverse order., the statement becomes.,

@users = User.find(:all, :o rder => “id DESC”)

Suppose, if we want to order by AGE in reverse order, the statement becomes.,

@users = User.find(:all, :o rder => “age DESC”)

Thats it folks!

Tags: , ,

making WordPress CAS plugin work …

Posted by: Shyam Sundar on: July 30, 2008

This article assumes that the reader has knowledge on WordPress and Central Authentication Service.

Today I was trying wordpress to authenticate itself from a CAS server. I found out that wordpress has a CAS plugin which is built upon the phpCAS library.

My CAS server is a Ruby CAS server., and I have an AMP setup up with the wordpress (ver. 2.6), phpCAS (ver. 0.60-1), WordPress CAS plugin (ver. 2.2 ) and latest version of Pear::DB. ( I know … I have filled it up in one line, but its easy if you follow the docs! )

After activating the CAS plugin, I had a huge number of warnings and errors on my browser. Most of them were solved after giving them appropriate permissions. And resolving the libraries the respective components needs.

Then, depending on your CAS Server’s SSL configuration, you need to edit “client.php” of phpCAS to allow https or http alone.

Then it worked fine, but wordpress would not login as it did create the cookie for the user. I went through the previous versions of the same plugin and found that wordpress has a function called wp_setcookie which can be called to set the cookie for a user.

The patch created by me modifies the wordpress plugin to explitcity set a cookie, if a user is granted a ticket from the CAS server. Note that, the older versions of the same plugin had the set_cookie code, but I could not find a changelog for the same.

If any one else have anyother experieces with WordPress and CAS, I’d love to hear their experiences as well.

Tags: , ,