Of Stomp Gem and EventMachine

While hacking at my little project this afternoon, I found out that when I started an EM.run thread running the main listener program while spawning another stompclient.join in the main EM.run .. the callback methods in the main EM methods were not getting called ..

I started to panic a little, because this code was working fine while using AMQP .. (maybe they were using another threading model?) ..

After a little research, I found out that the Stomp Gem join method is also using Eventmachine behind? ..

So if you are in the main EM.run loop for another process and you need to use STOMP to subscribe to other queues, you can remove the .join method from your stomp clients ..

 

Comments (0)

Weird Startx Issue on FreeBSD 8.0

I was trying to install FreeBSD on my IBM ThinkPad T40 last night and I had finished pulling all the Xorg and Fluxbox stuff after a looonng while .. so I added a shortcut to the xinitrc to start everything up .. and the funny thing was, the numlock key kept turning on by itself .. 

Of course, since this is a laptop, turning on the NumLock keys means that some of the important keys cannot be used .. and I can't turn the numlock off !! 

So, did a little searching and found a utility called numlockx to turn off the numlock (yes, a utility to turn off the numlock .. go figure). Anyway, if anyone is having the same issue .. here's what you do

In your ~/.xinitrc file

numlockx off

exec /usr/local/bin/fluxbox

Numlockx can be found in the ports under /usr/ports/X11.

 

Comments (0)
Posted 2 days ago

OCBC, IMHO is possibly the worst bank on earth

Everyone who knows me knows that I have an extreme dissatisfaction with OCBC bank. I've cancelled all the accounts with them one year back .. and surprise surprise, they sent me a bill yesterday for annual fees for the credit cards. I called them up today and this is how the conversation went

ME: Good morning, I'm calling to enquire about a bill I got from you yesterday. This is my account number. Due to my extreme dissatisfaction with your bank, I have already cancelled this account one year back !

Bank : Oh .. have you used the credit card in the past 3 days?

ME : What ?? The bank has already cut the card one year back !

Bank : OH in that case, ignore the bill and I will terminate the account.

Me : In that case, can you please check if I have any other cards that are linked to this account and cancel them also !

Bank : You mean you want to cancel all the cards ?

Me : Yes !! The account doesn't exist anymore !

 

I don't know is it me or something .. but shouldn't banks have better CRM systems or ERP systems or billing systems that tracks customer accounts? oh yeah .. I forgot .. their billing systems are tuned to give high priority to calculating customers with overdue accounts .. and probably the "DELETE CLOSED ACCOUNTS" job has no time to run in their system.

Comments (0)
Posted 18 days ago

Accepting only POST for controller actions in Rails

While hammering code out for my new project, I needed to code up a controller which are to be called by external services. Since GET has its own inherent troubles, I decided to only limit POST request to the controller actions.

I started using request.post? check in all my controller actions. Pretty tedious and its not DRY at all.

I digged a little more and found out that there's a verification mechanism that is built into Rails. Cool !

 

First, you will have to put the verify chunk right after your controller, like this

  verify :method => :post,

         :render => {:action => :error},

         :except => :error

What I am doing here is that, I want all my controllers to handle only POST request. And when a GET request comes in, Rails will render the action called error. You will then have to put an error page in your views for this controller. Finally, I'm telling Rails to run this rule for all the controller actions except the error action (which makes sense since you will probably be doing a GET to the error page)

 

Oh yeah, you will need to an extra route to your routes.rb file so that Rails can find your controller actions.

 

 

Comments (0)
Posted 19 days ago

Well Wishes for the New Lunar Year

Here's wishing all chinese a Very Happy Chinese New Year ! And to everyone, Happy Valentine's Day ! So what's everyone doing this evening?

For me its an important day to mark some significant milestone in my life, I finally found my purpose! 

Now to kick some butt ! 

Comments (0)
Posted 23 days ago

Of Iconv and FreeBSD

Ok, since I'm new to FreeBSD for a production environment for hosting Rails (I've used it for testing previously and for small firewall projects) .. I have no idea what FreeBSD was asking when I was running my rake command.

It said :-

rake aborted!
no such file to load -- iconv

Oops .. after some Googling, found that you have to

# su yourself to root

# cd /usr/ports/converters/ruby-iconv

# make clean install

FreeBSD sprouts some magical spells ... and rake runs !

 

Comments (0)
Posted 26 days ago

On Limits and Ability

Ability is one thing .. but the only limitations you have are the ones that you placed on yourself. 

Comments (0)
Posted 26 days ago

Building Stuff the right way or the fast way?

Do you do things the way you have always known and you know you may get it done .. or do you want to learn a new way of doing things, which may take longer and properly give you better output in the future? 

Of course the usual decision would be to choose option 2. But people being people, tend to have a trait of impatience ... If we could just be a little bit more patient and open our minds to learn new stuff ... we may see something we have not seen before.

Comments (0)
Posted 27 days ago

Using Xmpp4r-simple for Superfeedr

I was looking for a simple way to integrate feeds subscriptions and unsubscriptions into my application and most of the wrappers that were on Superfeedr were sort of designed to be run as a daemon service, which really wasn't what I needed .. so I Googled around a little and found this nifty Ruby library called xmpp4r-simple .. and there were patches added to it to enable it talk pubsub .. 

But seems like the author has hardcoded the pubsub JID which starts with "pubsub." .. which doesn't work with Superfeedr.

So I changed the main library file a little to add another parameters so you can specify which JID it should talk to .. Here's what you need to do

  • Download my patched xmpp4r-simple.rb
  • Replace it with the same file on your downloaded xmpp4r-simple source (should be cloned from git as shown previously)
  • Build it into a gem and install it (Also shown in my previous posting)

 

Now that you have gotten the patched gem installed into your gem store, you can pass in the new default service JID in the new constructor. Sample code below :

require 'rubygems' 

require 'xmpp4r-simple'

Jabber::debug = true

im1 = Jabber::Simple.new "account@superfeedr.com" , "yourpassword" , nil , "Available" , nil , 5222 , "firehoser.superfeedr.com"

im1.pubsubscribe_to("http://somerssfeed.xml")


 

 

 

 

Comments (0)
Posted 28 days ago

Building and Install Gems from Gemspec files

I downloaded Xmpp4r-simple with the pubsub patches inside but since I'm a greenhorn in Ruby .. I had no idea how to install it because it wasn't in a Gem. 

Yeah, I know... I got too spoilt from all those gem install this, gem install that. 

So after some digging, I realized that I can build the gem from the gemspec file included in the package. 

So if there someone who downloaded such packages, hope I saved you some time.

 

First, we want to clone the entire git directory first.

# git clone git://github.com/spectra/xmpp4r-simple.git

# cd xmpp4r-simple

# gem build xmpp4r-simple.gemspec

 

At this time you should have gotten a gem in the same directory! Woohoo! And so to install the glorious gem into our gem store.

# sudo gem install xmpp4r-simple-0.8.8.gem

 

Check that its installed

gem list --local | grep xmpp4r

 

You should see

xmpp4r (0.5)

xmpp4r-simple (0.8.8)

I think xmpp4r-simple install xmpp4r as a dependency. If you got both of them, you're done!

Comments (0)
Posted 28 days ago