Mentoring Sessions Coming!

I blogged about getting a personal mentor before. Well, now you guys will get the opportunity to listen on some of it now that Ben has graciously agreed to let me post our sessions. I won’t be posting the entire session since the sessions contain our personal conversations.

The only issue that I need to resolve is the Skype audio issue with Screenflow. It apparently does not record Ben’s voice. I’ve been exchanging emails back and forth with Vara Software, and hopefully it gets resolved soon. If not, I’ll have to bite the bullet and go back to SnapzPro. If anyone knows how to resolve this issue, please shoot me an email at joon at this domain. I’m using a USB headset and the audio setting is at Skype so it doesn’t change my default system settings. And yes, I would like to keep it that way!

Cell Phone Minute Calculation

Ruby comes with a wonderful method that can be used to calculate your cell phone usage by the minutes. Since every cell providers round to next minute, this little line here is all you need to calculate the billable minutes if the system gives you your usage in seconds.

def usage_in_minutes(usage_in_seconds)
usage_in_seconds.to_f./(60).ceil
end

The key here is “ceil” method. Take a look in the Ruby documentation.

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.

Next Page »