The Hitchhiker’s Guide to Ruby On Rails Galaxy

Records of my voyage through RoR Galaxy

Archive for March, 2009

How to parse a tweet text from Twitter using Ruby to parse-out ‘@’ and ‘#’

Posted by arjunghosh on March 5, 2009

Well lot of us love @twitter and also Ruby, and some time work on both 🙂

And often we need to do the folowing with a tweet

Well I had to do the following quite often:-

Take out the ‘@’ (i.e. @replies )and ‘#’ (i.e. hashtags ) from a tweet and separate it from the text part.

For example, we have a tweet:

@myfriend1 @myfriend2 this is a sample text #link #text

Now I want this tweet to be seperated into the following Array:



and the text only – [“this is a sample text “]

So first had to build a RegE, and then using the ever useful .gsub method of Ruby, created the following:

parsed_text = tweet.text.gsub(/ ?(@\w+)| ?(#\w+)/) { |a| ((a.include?(‘#’)) ? tags : replies) << a.strip.gsub(/#|@/,”); ” }

So the parsed_text has the final text only.  tags is an Array which will contain the hashtags and replies is an Array which will contain the @replies.

The RegEx / ?(@\w+)| ?(#\w+)/ extracts and seperates the hashtags & the @replies and place them in two seperate arrays.

The RegEx /#|@/,” only reples the ‘@’ and ‘#’ symbols in the extracted array elements.

And you can download it from Gist here

Also while working on creating the above regular expressions, I found this interesting RegEx testing site called which will help you write regular expressions very easily.

Posted in Uncategorized | Tagged: , , , , , , | 8 Comments »

A very hip & cool parenting site called lil’grams which is built on RubyOnRails!

Posted by arjunghosh on March 3, 2009

Just wanted to do a very quick post on this very new hip & cool site on parenting – lil’grams


And do you know what, its has been made in RubyOnRails!

Do check out this site. It the brain child of Greg Narain who is a well know serial entrepreneur & social media expert.

Already people are talking about it and when its yet to be launched!!

Actually people like NYTime, CNET, Mashable have been talking about lil’grams for sometime. Even KillerStartups has a mention.

There is also a buzz on twitter too 🙂

Yes, some would say its been in making for quite sometime. But as they say patience has its virtue. Ultimately its a labour of love.

It been really a long journey for me personally too. Have been working on it for quite some time. I still  remember those days of sleepless night, long meeting, etc. 

Though I am yet to be a dad 🙂 (a.k.a am un-married), I too  feel like a proud parent my self on the birth of lil’grams  which I feel is literally my baby! 

If you like (and also dont 🙂 ) do tell us about it here which I assure will be promptly replied to 🙂

Posted in Uncategorized | Tagged: , , , , , , | 9 Comments »