Timeout::Error

It really sucks that sometimes webservice request just hangs. What’s worse, some methods for some strange reasons returns Timeout::Error. My way of handling such problem is force a timeout. This can be done simply by wrapping the offending method or block within Timeout::timeout method. Here’s an example of what I mean:

require 'timeout'
...
begin
Timeout::timeout(2) do
# request to web for certain value
end
rescue
# put your rescue code here...
end
...

By passing 2, I’m telling the method to wait 2 seconds before raising timeout exception.

VMWare Player on Ubuntu 8.04 LTS

Here’s how I installed VMWare Player 2.0.3 on my Ubuntu 8.04 LTS. I would like to give my thanks to Czarism for help.

1. First thing I did was to install necessary headers.
~$ sudo apt-get install linux-kernel-headers linux-kernel-devel

2. Download VMWare Player tarball from vmware.com

3. Extract the tarball.

4. Here’s extremely important step. It appears that there’s an error on one of the headers in VMWare Player. You need to change line 74 in vcpuset.h from “asm/bittops.h” to “linux/bitops.h”. In order to do this you have to untar vmmon.tar, make the change, and tar it again so that install script can run normally. To do this:
~$ cd vmware-player-distrib
~$ cd lib/modules/source/
~$ tar xvf vmmon.tar
~$ vi vmmon-only/include/vcpuset.h

Notice I use vi, but you can use any text editor you want, make the change and save it.
~$ tar cvf vmmon.tar vmmon-only

5. Run vmware-install.pl using sudo and just follow the instruction. That’s all!

I’m now running Windows XP Pro I created in VMWare Fusion on my Mac and everything runs beautifully, including the VMWare Tools. Since I only use my VM to test webapps on IE, it really doesn’t take much resources and I love the fact that I’m running both Linux and Windows.

Installing Ruby & Rails on Ubuntu 8.04 Hardy Heron

This is what I did to get Ruby and Rails working on my new Ubuntu 8.04 LTS. It appears that nothing really changed from previous version. The basic step is to install the Ruby using apt-get and installing the Gem from the source. I learned my lesson NOT to install Ruby from the source on Ubuntu. Just remember that if any gem installation fails, just get the required library using apt-get and get the ‘dev’ version as well. This is the rule of thumb I’ve been following and has worked out well for me.

Step 1: Install Ruby from apt-get.
~$ sudo apt-get install ruby irb ri rdoc ruby1.8-dev libzlib-ruby libyaml-ruby libreadline-ruby libncurses-ruby libcurses-ruby libruby libruby-extras libfcgi-ruby1.8 build-essential libopenssl-ruby libdbm-ruby libdbi-ruby libdbd-sqlite3-ruby sqlite3 libsqlite3-dev libsqlite3-ruby libxml-ruby libxml2-dev

Step 2: Download and install RubyGems
Just download and extract the latest Gem and run following command.
~$ sudo ruby setup.rb
After successful installation, run this to create the link in /usr/bin
~$ sudo ln -s /usr/bin/gem1.8 /usr/bin/gem

Step 3: Install Rails and Gems
~$ sudo gem install rails
~$ sudo gem install sqlite3-ruby mongrel capistrano

Since I don’t use MySQL anymore, it’s really optional. It’s basically same as before, just make sure you are using following command to get everything you need for MySQL.
~$ sudo apt-get install mysql-server mysql-client libdbd-mysql-ruby libmysqlclient15-dev

** UPDATE **
- “libmysqlclient-dev” is now “libmysqlclient15-dev” => I found this out while installing my new server, but it appears that maurizio de magnis already posted the solution in the comments. Thanks!
- “buildessential” is no longer required when installing Ubuntu Server.

I Hate Daylight Savings Time!!!

I can’t think of anything that disrupts your life like the daylight savings time. First of all, it does NOT save energy. Not these days in age. It might have been beneficial during the times of Ben Franklin when the economy was based on agricultural output. I think we live in different age; people haven’t caught up to the time yet.

Anyways, it presents more problems for me as developer. Because DST is not universally accepted, I have to take DST into account when presenting the users with their local time. There’s a way to take educated guess using browser’s country setting. Then there’s a way to call it from client-side JavaScript using getTimeZoneOffset() method, but it has to be invoked by the client.

The solution? Have the users define it.

It sounds stupid, but this is probably the most accurate way to do it. Once you capture it, save it to the user’s information. However, be extremely careful not to store GMT + or - value. Yes, I have seen this. This is because cities like Phoenix, AZ and Tucson, AZ do not practice DST.

Once you have it, use tzinfo GEM. It’s extremely easy to use and best of all, it automatically adjusts to DST. All you have to do is pass the date/time stamp in UTC format and you’re good to go.

You can simply install it by sudo gem install tzinfo. Just make sure you install it on the server as even the tzinfo plugin requires it.

no such file to load — libxml_so

“no such file to load — libxml_so” is the lovely error message I got when I upgraded/installed 0.5.3 version of libxml-ruby using gem. Now that I only use Leopard, I’m not sure if this applies to Tiger. My guess is that this is Leopard issue. The solution to this problem is relatively quick. I just removed 0.5.3 version and went back to older version.

sudo gem uninstall libxml-ruby -v 0.5.3

You’ll also have this problem on Ubuntu if you installed Ruby by compiling it yourself. It’s pain in the ass, but you can go through the code and install the components yourself. Let me know if anyone wants the steps.

By the way, libxml is about 100 times faster than REXML that comes with Ruby. If you don’t believe me, try it for yourself. I didn’t believe it either, but I was SHOCKED when I saw how much faster it was.

Hosting Rails Apps On My Home Servers

When I heard that Markus Frind of plentyoffish.com actually started hosting his website from home, I thought it would be interesting to post my recipe for hosting websites and Rails apps from home servers. However, it’s not as easy just plugging it in. There are interesting constraints I have to overcome, and I expect that others are having the same problem.

Problems

Although I have plenty of bandwidth from my FiOS, any incoming traffic to port 80 and 8080 are blocked by Verizon. I found this to be true when I had both DSL and cable modem. What this means is that the only way for the visitors to view my site, it has to point to some obscure port. I just don’t think this will work.

Another issue is that my IP address is from DHCP. Although it hasn’t changed since I got it, you never know. I also don’t want to pay more for a fixed IP address and certainly don’t want to be a subject to the interrogation of “why do you need a static IP?” from Verizon.

My Recipe

As you can see by the diagram, I got a basic VPS that functions as the proxy and a stripped down load balancer. You can get a cheap VPS for as little as $9.99 per month. Since it’s not doing much, you don’t need cPanel/Plesk or any other software, just Apache or my favorite, nginx.

hosting_at_home.png

Next thing I have is a dynamic DNS provider such as dyndns.org. The host name specified here will be the address of my home server. This solves the issue with changing IP address. My server also updates the IP address by running a small daemon.

The Apache server running on the VPS, which comes with a static IP address and the access to port 80, sends the request from client to my server at home using obscure port. My home server sends the response back and the user can’t tell the difference. You can also host many sites this way. Below is a bit of sample configuration on Apache:

Apache config:

 <Proxy balancer://cluster_name>
       BalancerMember http://home_server_address:8000
       BalancerMember http://home_server_address:8001
 </Proxy>

Virtual directive:

	ProxyPass / balancer://cluster_name/
	ProxyPassReverse / balancer://cluster_name/

Discussion

If you’d like to get more details or have questions, just send me an email at my name at this domain.

uninitialized constant Gem::GemRunner (NameError) - Ubuntu

I mentioned that I now use Ubuntu 7.10 on my Dell. After installing Ruby and RubyGems using apt-get, I got this nasty error AFTER doing ’sudo gem update –system’.

It appears that similar problems have occurred with Mac OS X as well. For one thing, you can try adding following to the gem file:

require ‘rubygems/gem_runner’

However, it was irritating me that along with this problem, I had to install irb separately and ruby sitting in /usr/bin directory.

My solution? Just install using the source. It always works for me without any problem and any subsequent stuff I add works without any issues. What I also like is that some of my scripts explicitly points to the location of ruby. Although I can correct this using env, why bother?

« Previous PageNext Page »