Chaotic Musings http://www.alvinloh.com Do you have a circus in your head ? posterous.com Mon, 08 Mar 2010 04:19:33 -0800 Of Stomp Gem and EventMachine http://www.alvinloh.com/of-stomp-gem-and-eventmachine http://www.alvinloh.com/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 ..

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/410776/6320_1180296222874_1092237254_553388_7515717_n.jpg http://posterous.com/people/eGaQVMSRzj Alvin Loh alvinloh Alvin Loh
Sat, 06 Mar 2010 01:29:01 -0800 Weird Startx Issue on FreeBSD 8.0 http://www.alvinloh.com/weird-startx-issue-on-freebsd-80 http://www.alvinloh.com/weird-startx-issue-on-freebsd-80

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.

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/410776/6320_1180296222874_1092237254_553388_7515717_n.jpg http://posterous.com/people/eGaQVMSRzj Alvin Loh alvinloh Alvin Loh
Thu, 18 Feb 2010 17:48:21 -0800 OCBC, IMHO is possibly the worst bank on earth http://www.alvinloh.com/ocbc-imho-is-possibly-the-worst-bank-on-earth http://www.alvinloh.com/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.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/410776/6320_1180296222874_1092237254_553388_7515717_n.jpg http://posterous.com/people/eGaQVMSRzj Alvin Loh alvinloh Alvin Loh
Wed, 17 Feb 2010 22:41:50 -0800 Accepting only POST for controller actions in Rails http://www.alvinloh.com/accepting-only-post-for-controller-actions-in http://www.alvinloh.com/accepting-only-post-for-controller-actions-in

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.

 

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/410776/6320_1180296222874_1092237254_553388_7515717_n.jpg http://posterous.com/people/eGaQVMSRzj Alvin Loh alvinloh Alvin Loh
Sat, 13 Feb 2010 22:27:05 -0800 Well Wishes for the New Lunar Year http://www.alvinloh.com/well-wishes-for-the-new-lunar-year http://www.alvinloh.com/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 ! 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/410776/6320_1180296222874_1092237254_553388_7515717_n.jpg http://posterous.com/people/eGaQVMSRzj Alvin Loh alvinloh Alvin Loh
Wed, 10 Feb 2010 19:18:37 -0800 Of Iconv and FreeBSD http://www.alvinloh.com/of-iconv-and-freebsd http://www.alvinloh.com/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 !

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/410776/6320_1180296222874_1092237254_553388_7515717_n.jpg http://posterous.com/people/eGaQVMSRzj Alvin Loh alvinloh Alvin Loh
Wed, 10 Feb 2010 05:14:21 -0800 On Limits and Ability http://www.alvinloh.com/on-limits-and-ability http://www.alvinloh.com/on-limits-and-ability

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

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/410776/6320_1180296222874_1092237254_553388_7515717_n.jpg http://posterous.com/people/eGaQVMSRzj Alvin Loh alvinloh Alvin Loh
Tue, 09 Feb 2010 02:58:27 -0800 Building Stuff the right way or the fast way? http://www.alvinloh.com/building-stuff-the-right-way-or-the-fast-way http://www.alvinloh.com/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.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/410776/6320_1180296222874_1092237254_553388_7515717_n.jpg http://posterous.com/people/eGaQVMSRzj Alvin Loh alvinloh Alvin Loh
Mon, 08 Feb 2010 06:05:23 -0800 Using Xmpp4r-simple for Superfeedr http://www.alvinloh.com/using-xmpp4r-simple-for-superfeedr http://www.alvinloh.com/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")


 

 

 

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/410776/6320_1180296222874_1092237254_553388_7515717_n.jpg http://posterous.com/people/eGaQVMSRzj Alvin Loh alvinloh Alvin Loh
Mon, 08 Feb 2010 04:07:12 -0800 Building and Install Gems from Gemspec files http://www.alvinloh.com/building-and-install-gems-from-gemspec-files http://www.alvinloh.com/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!

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/410776/6320_1180296222874_1092237254_553388_7515717_n.jpg http://posterous.com/people/eGaQVMSRzj Alvin Loh alvinloh Alvin Loh
Sun, 07 Feb 2010 22:54:34 -0800 Installing RabbitMQ on FreeBSD 8.0 http://www.alvinloh.com/installing-rabbitmq-on-freebsd-80 http://www.alvinloh.com/installing-rabbitmq-on-freebsd-80

I needed to use AMQP for one of the apps which I'm hacking on right now .. so needed to install RabbitMQ. RabbitMQ is the fantastic, open sourced message queue application that is both high performance (I'm coming from SQS which is somewhat slow) and low taxing on your CPU, which is basically great for me since I'm running it in a VPS environment.

So I fired up SSH and installed Erlang first since RabbitMQ is written in Erlang

# cd /usr/ports/lang/erlang

# make clean install

I didn't need have an X environment so can safely uncheck Java apps, X, WX. It will start building .. after you are done .. time to install RabbitMQ.

# cd /usr/ports/net/rabbitmq

# make clean install

After you are done, RabbitMQ will tell you something like this

##############################################################################

Please note:The "rabbitmqctl" command must be run as the rabbitmq user,with a real shell, and

with the ${HOME} environment variable set to thatuser's real home directory.

su users can do

something like this: 

# env HOME=/home/rabbitmq su -m rabbitmq -c 'rabbitmqctl ...'

sudo users can do something like this: # sudo -H -u rabbitmq rabbitmqctl ...##############################################################################

 

Ok, great ! Now we have installed RabbitMQ. Remember to add an entry to your rc.conf so it will start automatically and also to allow you to start it manually now.

# echo 'rabbitmq_enable="YES"' >> /etc/rc.conf

 

If you are in your root directory (because you are su), and you try starting RabbitMQ, you will get some wierd errors .. error_logger, protocol error blah blah blah. Closer inspection seems to indicate that RabbitMQ does not have enough privileges to write to your current directory.

No worries, just go back to root and start it from there.

# cd /

# /usr/local/etc/rc.d/rabbitmq start

 

If all goes well, RabbitMQ will report to you that the node has started and you are ready to start on your MQ apps!

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/410776/6320_1180296222874_1092237254_553388_7515717_n.jpg http://posterous.com/people/eGaQVMSRzj Alvin Loh alvinloh Alvin Loh
Sun, 07 Feb 2010 21:43:49 -0800 Moving In ! http://www.alvinloh.com/moving-in-40 http://www.alvinloh.com/moving-in-40

People who have seen my blog previously knows that I'm pulling my feed from twitter and masquerading it as blog post. I finally gotten around to moving in here (since Posterous have started allowing me to put my own domain name).

So, looking forward to communicating more with you guys in here.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/410776/6320_1180296222874_1092237254_553388_7515717_n.jpg http://posterous.com/people/eGaQVMSRzj Alvin Loh alvinloh Alvin Loh