Ruby Regexp Unescape

May not be a big deal to write it yourself…but I wrote this and was quite useful, where I had to do un-escaping of a Regex Pattern for some reasons…

class Regexp
def unescape
source = self.source.split('')
escape_on = false
unescaped_string = source.inject([]) {|r, char|
if char == "\\" and escape_on == false
escape_on = !escape_on
r << char
escape_on = false

Enable Disable Touchpad in Ubuntu with a Hot key

I have got this new Dell Vostro n3500 Laptop, which is really a solid machine. I am very happy to have made this choice.

As a hardcore UBUNTU User, I always liked to have any feature available in Windows to be made available in Ubuntu as well :)…

Recently, I realized that the “Fn+F6” shortcut to disable the Touchpad does not work… I am sure many of you would have encountered the annoying behavior of touchpad moving your cursor to some place while you are typing something…

The most ideal solution I would have liked is that, when I connect an external mouse, the touchpad should automatically be disabled. Apparently, I did not find any solution for this in the current version of Ubuntu 10.04(Lucid Lynx). Google did not help me either.

So, the next thing is, is there any way I can tell Ubuntu to disable touchpad when I start typing. Yes, there is such an option in the “Mouse Preferences”. But that is not working consistently atleast for me.

So, now this is what I did. I wrote a small Ruby script(I am a big big fan of Ruby) that can toggle the Touchpad ON and OFF.

Now, the next thing is to make it hooked to a keyboard shortcut like the one in Windows…Fn+F6. Apparently, I also found that I cannot assign the combination of “Fn” Key and “F6” to the Keyboard shortcut in Ubuntu. So for now, I have simply assigned “F6” key for this toggle switch tool.

The script is not a big deal, but in any case, its here…

touch_pad_setting = `synclient -l | grep TouchpadOff`
new_touch_pad_setting = touch_pad_setting =~ /1/ ? "0" : "1"
`synclient TouchpadOff=#{new_touch_pad_setting}`

Enforce JRuby to use gems inside the JRuby complete and ignore the local gem repository

Most of us are aware that Gems can be bundled as part of JRuby Complete, and Jruby will automatically load these gems from the jruby-complete.jar happily.

But do you know that, if you had a local gem repository set, jruby will ALWAYS attempt load the gems ONLY from your local gem repository? And ignore the gems bundled inside the jruby-complete.jar?

Well, we are aware of that, but it was quite annoying when we find that some code that worked happily in our development environment does not work in production, bcos the codes were referring to some gems that were available only in our development environment.

To ensure JRuby completes ignores our local gem repository, we used to add the following line in our deployment scripts before launching JRuby.

unset GEM_HOME

We are trying to understand the principle behind using the local gem repository even though certain gems are bundled inside the Jruby Complete.

Some thoughts on how Jruby should choose the gem repository
1. Whenever jruby is launched from the jar file with embedded ruby home, then always assume to use the embedded gem home and ignore the local gem repository?


2. If atleast one gem is bundled in jruby-complete, then can jruby assume the developer wants to use the particular gem in his application and hence ignore the local gem repo and set the gem repo as the embedded gems location inside jar?

We are unable to come to a conclusion on what is the sane approach to handle the situation.

For now, we have patched jruby to go thru first approach. This way, I am completely sure that when jruby is launched from jar, my local gem repository is not coming in the way. And I dont have to remember to “unset GEM_HOME” in all my deployment scripts to tell Jruby to look for gems embedded in the jar file.

Hope this may be of some help for people who have had faced this issue.

JOpenSSL gem inside JRuby Complete

We had faced quite a lot of issues trying to embed JOpenSSL inside jruby-complete.jar.

We used to get an error “Uninitialized constant OpenSSL::Digest::OPENSSL_VERSION_NUMBER” with the following stack trace :

NameError: uninitialized constant OpenSSL::Digest::OPENSSL_VERSION_NUMBER
from file:/home/msuser1/jruby-complete-1.3.1.jar!/META-INF/jruby.home/lib/ruby/gems/1.8/gems/jruby-openssl-0.6/lib/openssl/cipher.rb:28:in `const_missing’
from file:/home/msuser1/jruby-complete-1.3.1.jar!/META-INF/jruby.home/lib/ruby/gems/1.8/gems/jruby-openssl-0.6/lib/openssl/digest.rb:23
from file:/home/msuser1/jruby-complete-1.3.1.jar!/META-INF/jruby.home/lib/ruby/gems/1.8/gems/jruby-openssl-0.6/lib/openssl/digest.rb:31:in `require’
from file:/home/msuser1/jruby-complete-1.3.1.jar!/META-INF/jruby.home/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require’
from file:/home/msuser1/jruby-complete-1.3.1.jar!/META-INF/jruby.home/lib/ruby/gems/1.8/gems/jruby-openssl-0.6/lib/openssl.rb:24
from file:/home/msuser1/jruby-complete-1.3.1.jar!/META-INF/jruby.home/lib/ruby/gems/1.8/gems/jruby-openssl-0.6/lib/openssl.rb:31:in `require’
from file:/home/msuser1/jruby-complete-1.3.1.jar!/META-INF/jruby.home/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require’

You can find Charles’ explanation here

What we did is the following :

1. Add the Jruby-openssl gem inside the jruby-complete.jar bundle like adding any other gems(rspec, rake etc.)
2. Extract the JRuby Complete Jar in a fresh folder
3. In addition to this, extract the contents of jopenssl.jar directly under the root folder. (jopenssl.jar is located inside the lib folder of the jruby-openssl gem).
4. Re-create the jruby-complete.jar from this exploded folder.

Thats about it, you are all set to use openssl inside jruby without any issue.

Please note, at the time of writing this post, I was using JRuby 1.3.1 and Jopenssl 0.6.

Another iPhone App on the pipeline – Tarabalam

After developing an iPhone app called Panchangam Lite and seeing its success rate in terms of increasing number of downloads day after day and receiving positive feedback for the app, we were motivated quite a lot and it made us realize that there are lots of people around the world looking for such cool and useful tools in their iPhone…And we thought lets develop another app for such people in the similar lines…hence an app named “Perfect Day (Tarabalam)” is born.  The app should be available in AppStore very soon 🙂

Ok, then here goes some notes about “What is Tarabalam ?” and why and how should it be used?

Importance of Muhurtha (Quoted from the well known astrologer BV Raman)

The value of Time is inestimable. All objects in nature are produced in Time, developed in Time and destroyed in Time. The truth of these statements requires no further proof. It stands unchallenged.

Each moment has got its own potency and as Carl Jung says “whatever is born or done this moment of time has the qualities of this moment of time”. Hence the moment of birth or the moment at which we elect to do an important act is not certainly an insignificant epoch. Cosmic radiations pouring at the moment on the earth from outer space and coming from various stars and planets act on our brain cells which take up these cosmic radiations which are transformed into vital electricity. It must be noted that in all undertakings invisible energies are set in motion by our words, deeds, thoughts and of course by our actions. You may call these invisible forces as electric, ethereal or electro-magnetic or cosmic radiations. As man himself is an electrical body discharging different kinds of electrical energies, his success and failure are simply matters of attraction and repulsion between himself and the objects with which he has to deal in his day-to-day activities.

Muhurtha could therefore be defined as that precious moment when the vibrations radiated by man are altered to a specific wavelength capable of entering resonance with the radiations of the same vibratory rate coming from other planets and stars.

What is Tarabalam?

Various strengths are checked for muhurtham. Tarabalam, Chandrabalam, Gurubalam, Suryabalam, Lagnam shuddhi, etc… As outlined in following mantra. When we worship lakshmipati sri narayana, he will make everything right. He is tithi, vaara, nakshatra, yoga, karana. Hence, worshipping him will make everything right, remove all dosha.

तदेव लग्नं सुदिनं तदेव ताराबलं चंद्रबलं तदेव। विद्या बलं दैवबलं तदेव लक्ष्मीपतेः तेंघ्रिऽयुगं स्मरामि॥

tadeva lagnaṁ sudinaṁ tadeva tārābalaṁ caṁdrabalaṁ tadeva | vidyā balaṁ daivabalaṁ tadeva lakṣmīpateḥ teṁghri’yugaṁ smarāmi

Tarabalam is a strength provided by stars to your Janma / Birth star. Nakshatra/Star of moon at the time of your birth is known as Birth star. Moon’s daily star / Nakshatra position needs to be favourable for casting any muhurtha. Moon takes roughly 27 days to circle around earth and passes through 27 nakshatras. Daily motion of moon from your janma nakshatra decides this strength.

What does this mobile app do?

In order to increase the chances of success in any endeavor, this mobile app helps the user to pick days / times to perform the endeavor when Tarabalam is very strong. It calculates Tarabalam for 400 cities around the world for the year 2010. The timings are daylight adjusted where-ever applicable. You can also keep a list of your family / friends with their birth star and easily select Tarabalam for the person with just a click of the button.

Tarabalam is available for year 2010.

Ruby Conference 2010 – Bangalore

Feels good to be part of the first Ruby Conference of India, which was held in Bangalore on 20th & 21st March, 2010.

And it feels all the more glad to see our company being one of the sponsors to this event. Having got so much from Ruby and the Open source world, this was a fantastic opportunity for us to give back something to the community.
Got to meet and spend time with some special people whom I was looking forward to meet for quite some time now. Got a chance to meet some of the top developers of the JRuby world – Ola Bini, Nick Sieger and not to mention Arun Gupta – lead developer of Glassfish.
Being one of the developers who have used the combination of Glassfish, JRuby and Rails in our enterprise applications, Arun Gupta captured a short little video about our experiences on working on this platform combination. Check out the video here.
The highlight of this event was the talk from the father of the Ruby Language Matz, who gave a wonderful talk via video conference from Japan. It was very special for Ruby developers like me.

Getting MINA 2.0 to work peacefully in Glassfish

This weekend, I had some good opportunities to work on some cool things, one of which is build a Socket Server using Apache Mina 2.0(Release Candidate Version)…
Apparently, my project requires running two Socket Servers inside Glassfish v2, one to receive incoming client requests and the other as a simulator to receive what my application churns out.

I was happy to simply write a ServletContextListener which starts the Incoming Requests Socket Server in a separate Thread :). No Problems, I could connect to the Socket Server and communicate happily.

However, when I repeated the above steps to start the Simulator Socket Server(obviously listening in different port not conflicting with the previous Socket Server), server starts up fine. However, the minute I try to start communicating from a Socket Client to this Socket Server, the socket server started throwing a whole bunch of NullPointerException in NioSocketAcceptor.accept() method.

Why did this behavior not happen when I was running my first Socket Server but only happens with my second Socket Server. As usual Google came to my rescue at the wee hours too 😉

I was told to add the following property to my Glassfish JVM

Check this forum thread that helped me. Apparently this seems to be a bug in Glassfish v2 and has been fixed in V3. For Glassfish v2, the above property should help.

Glassfish Bug Database links related to this issue
Bug Id 3027
Bug Id 5321
I am still unable to understand why I did not have this problem when running first Socket Server inside Glassfish!!! One of those questions that still remains unanswered !

Glassfish Clustering – NullPointerException while creating JMS RA

Didn’t I tell you that we had an exciting experience enabling cluster support for our applications using Glassfish.

Even though the entire setup worked fine in our local environment, life was not the same when trying to deploy our application on Amazon EC2 Cloud. We were greedy enough to pick a large machine with 8GB RAM and quad-core processors…and attempted to deploy our applications on the Glassfish Cluster there…
Our Server Instances would never start, failing with a whole bunch of NullPointerExceptions while creating JMS RA. I gave up after googling for couple of hours. And as usual, Venkat came to my rescue. He took over from me and spent some midnight oil and figured out the trick…
We had to add an unsupported property to the JVM…


Check out this link from Ramesh Parthasarathy for more useful information related to this issue

Glassfish v2.1.1 Cluster Session Replication inconsistent behavior

Everytime I take up a task on adding Cluster Support to my j2ee application, the whole experience gets quite exciting with new kinds of challenges 🙂

In the past, it was with Weblogic, Websphere etc…and this time it was Glassfish 🙂
Ok, like many of you, I managed to setup the cluster environment in glassfish and deployed “ClusterJsp” application to check out Session Failover, Load balancing etc…
What I found was that, if I keep refreshing the ClusterJsp page 5 to 10 times, my Session Id keeps changing…going to say that Glassfish lost my session somewhere in between these requests.
After googling and bing’ing a lots, I managed to find this link, which explained the issue in detail.
Basically, we should add the following snippet in sun-web.xml
After adding the above entry, Glassfish started behaving as expected.
Now what I donot quite understand is, why was this behavior not made a default behavior !!!
I am sure there is a good reason for it, will update If I get to know.

Our First iPhone App

After being an user of iPhone for past one year, we got inspired to write an app for iPhone 🙂

We were thinking if we should write a simple Game or Puzzle Application, and then came this idea of publishing a Panchangam data for 2010. Venkat came up with the data for all the days for year 2010 and we put together an application called “Panchangam Lite 2010”. The reason for this “Lite” is the fact that this Panchangam provides data (timings) specific to Bangalore. We have plans to make a Panchangam Pro (?!) which allows you to choose the city and lookup the panchangam data…and even further, automatically figure out the location of the iPhone using the “Location service” of iPhone.

And guess what, within 5 days of our launch of this app, we have found more than 300 downloads of this application. We are all the more motivated to come out with more such useful apps in the near future 🙂

Want to check out countries from where our app was downloaded till date…go to Venkat’s blog post here