Exploring Thoughtz..

Learnings in Rails

Posted by: Vijay Dev on: January 1, 2010

I have had the chance to work on a Rails project this December and learned quite a lot in the process. My earlier reading and trying out some sample applications surely helped. However, doing a real life project gave more insights and knowledge about the framework. So here I am, trying to document some of those learnings, niceties and weirdos (in no particular order).

Rake is cool! One of the gotchas is that the command “rake -T” displays only those tasks that have descriptions. Also, found a nice way to pass parameters to rake tasks here – the parameters need to be passed are listed next to the task name as below. When this idiom is being used, the usual way of specifying the dependency tasks does not work. We need to use “:needs” explicitly and specify the dependencies. “args” is a hash of all the parameters that are passed to the task.

task :truncate_table, :db_name, :tbl_name, :needs => [:environment, :load_config] do |t, args|

Providing a drop down of time zones is so simple using the time_zone_select helper method. The priority_zones option is a nice way to specify some time zones up front so as to avoid the hassle of going through the entire list.

There is also a country_select plugin that gives a drop down of countries. Seems that this functionality was available earlier in Rails and later extracted out as a plugin.

All files in config/initializers are loaded at server start-up. Application level constants can be written in a file, say, constants.rb and saved in this folder and accessible from anywhere in the application.

One of the things that tripped me early on is the need to restart the server for any changes done in the modules in ‘lib’ to take effect.

Thanks to K, came to know about gotapi and used it extensively!

To be(gin) or not to be(gin)!

Posted by: Vijay Dev on: January 1, 2010

Well, it’s a new year of a new decade!

Here are some of my resolutions:

  • Blog often
  • Read more books, technical or otherwise
  • Learn driving
  • Sleep more

Hoping for a great year ahead!

Busy December!

Posted by: Vijay Dev on: December 26, 2009

Not so much busy to not write a post, but this December was all fast and crazy. A nephew was born and named; work became fun again – delving deep into Ruby on Rails, getting a nice project and much more!

Google Chrome OS – A Review

Posted by: Vijay Dev on: November 24, 2009

With the open sourcing of Google Chrome OS as Chromium OS project, people have started building the OS on their own and a couple of them can be found here and here. I have tried out the build that is available as a torrent mentioned in the TechCrunch article, but could not login to the OS (Network not connected and offline login failed) in neither VMWare nor VirtualBox on a Leopard. However, it logged in fine in VirtualBox on Ubuntu 9.10. The performance though was terribly bad. There is also a USB bootable image available here, which I have not tried out yet.

I have downloaded the Chromium source code and have built the OS image and ran it successfully on both VMWare and VirtualBox. The code is downloaded as a tarball for this build process. If you wish to make changes to the code and contribute, the source should be downloaded using git, in which case, the Chromium depot tools need to be installed as a prerequisite.

What is Chrome OS?

Chrome OS is a lightweight OS designed to be used by netbooks, focused only on the web. It is built on top of the Linux kernel and aims to be faster, simpler and secure.

  • Built on top of Linux kernel
  • Faster boot times
  • Entirely web-based
  • Minimal user interface
  • Encrypted storage of all user data in the cloud
  • Self verification of integrity of OS at every boot

What it is not?

Chrome OS is NOT a replacement for desktop operating systems. You can’t just go and replace your current OS with Chrome OS!

Build Process:

I have done the entire build on my 32 bit Ubuntu 9.10. The image works fine in VirtualBox in the same machine and also on VMWare in a Leopard. The steps in brief are:

  1. Making the local repository
  2. Creating the build environment
  3. Including Chrome browser
  4. Building the platform packages
  5. Building the kernel
  6. Building the final OS image
  7. Converting the image to a VMWare image
  8. Converting the image into a bootable USB disk (optional)

Creating the local repository took about an hour to complete. Other steps are relatively faster; the building of the platform packages and the kernel took 10 minutes each and the final OS image itself took 5 minutes. Conversion into a VMWare image requires qemu. Do a sudo apt-get install qemu-kvm before starting the conversion.

How does it work?

The OS is nothing but a browser, well almost! The OS boots and you have a nice blue screen (no, not the BSOD :P ) asking for the username and password. A Gmail account is required to login to the OS. The build number below the login screen is unique for each build of the Chromium OS image.

Chromium OS Login

On login, the user is directly taken to the Chrome browser and everything the OS has to offer is available right there. It’s all about the web!

Clicking on the Chrome logo on the top left corner gives you a list of web apps (even Yahoo! Mail and Hotmail). Orkut is missing, but Facebook isn’t :-) Almost all the websites that I use regularly worked fine. Flash too works great without any noticeable problems.

On the downside, command line access sucks (Do Ctrl + Alt + T to access the terminal). Typing ‘exit’ at the command line does not take you back to the browser right away. It never did for me, at least! I always ended up typing ‘exit’ about 4-5 times and suddenly the browser will appear. Also the OS becomes unresponsive in both VMWare and VirtualBox if left unused for a few minutes.

The minimalistic UI seems to be a cautious approach. There are two themes available right now – GTK+ and Classic. The look feel at the moment is not at all good. But we can expect Google (and the Open Source community!) to improve on this in the coming months.

The OS is targeted at those who use computers almost solely for accessing the Internet. It is simple and nicely done. But the performance of the Chrome OS is not satisfactory on a virtual machine. The user interface also needs to improve quite a bit.

Keeping all the data in the cloud could be a double-edged sword with potential paranoid users trying to avoid Chrome OS just for that reason. Google is betting on the fact that the market for net-books will increase in the future and that users who want to connect to the Internet fast would prefer an OS which lets them do that without much difficulties.

Change in behavior in Timestamp.valueOf() in JDK 6

Posted by: Vijay Dev on: October 21, 2009

Recently, when looking at a bug related to Timestamp, I found out that the valueOf() method in java.sql.Timestamp works differently in JDK 6 than the earlier versions.

Timestamp.valueOf(), when provided with a timestamp which contains a date or a month with a single digit. eg. 2009-9-20, 2009-9-3, 2009-12-4 etc., behaves differently in JDK 6 – it throws an IllegalArgumentException saying that the timestamp is not properly formatted. Whereas JDK 5 (and earlier versions) works just fine providing the proper values with ‘0′ prefixed to those single digit numbers. However JDK 6 is fine with hours, minutes, seconds being single digits. As usual, got curious and started exploring why this happens by looking at the source code for the Timestamp class in JDK 5 and 6.

Here’s the JDK 6 Timestamp.valueOf() snippet:

int counterD = 0;
int intDate[] = {4,2,2};

int counterT = 0;
int intTime[] = {2,2,12};

while(stringTokeninzerDate.hasMoreTokens()) {
String tokenDate = stringTokeninzerDate.nextToken();
if(tokenDate.length() != intDate[counterD] ) {
throw new java.lang.IllegalArgumentException(formatError);
}
counterD++;
}

/*
//Commenting this portion out for checking of time

while(stringTokeninzerTime.hasMoreTokens()) {
String tokenTime = stringTokeninzerTime.nextToken();

if (counterT < 2 && tokenTime.length() != intTime[counterT] ) {
throw new java.lang.IllegalArgumentException(formatError);
}
counterT++;
}
*/

The code in bold shows that there is a strict check on the length of the digits that constitute the datepart of the timestamp. The commented out source is the reason why the format of the digits in the time part is not strictly enforced.

I thought it’s good to dig more into this and asked in Stack Overflow and people helped out in identifying more details: The behaviour is already filed as a bug and more info about the bug was found here. A workaround for this problem is available here.

What is debian-sys-maint?

Posted by: Vijay Dev on: October 11, 2009

Recently, when we were moving our staging applications and databases to a different server (from Win 2003 to Ubuntu 9.04), we had two problems with the MySQL server.

One, easy to fix, was the case-sensitive nature of table names. Using lower_case_table_names=1 in /etc/mysql/my.cnf fixed the problem.

The other problem riddled the server startup and shutdown (even server status) with errors, even while keeping the server functional. When looking into the error messages, I found out that there is a special MySQL user named ‘debian-sys-maint’ which has admin privileges. This account is used to shut down the server gracefully, to check for corrupt tables etc. The password for this account is stored in plaintext in the file /etc/mysql/debian.cnf.

Error message obtained:

/usr/bin/mysqladmin: connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘debian-sys-maint’@'localhost’ (using password: YES)’

Fix:

GRANT ALL PRIVILEGES ON *.* TO ‘debian-sys-maint’@'localhost’ IDENTIFIED BY ‘<password>’ WITH GRANT OPTION;

where <password> is the plain text password found in /etc/mysql/debian.cnf. Found the fix here.

Two Months

Posted by: Vijay Dev on: September 13, 2009

Been inexplicably away from blogging for a long time (except for the birthday post) – it had been a tough month and a half in various aspects. Meanwhile, Ananth went to SA for a project implementation and those two weeks were boring without him to chit-chat with. He returned to India on my birth day and we had good fun that day with a late lunch at Woodlands, watching “Up” and what not !

On the technical side, I have got bitten by the Flex bug which is quite dangerously spreading in my team!! I am also starting to learn Ruby on Rails. I like Rails more than Flex and I might work on both these technologies in the coming months. Top Secret :P

Work is otherwise monotone for sometime now with nothing interesting/challenging coming on the way. Anyway, enjoying what I do and trying to learn something out of whatever I do.

Last two months also saw an Increase (note the caps) in watching movies. Watched several films for the first time in life – Matrix, Lord of the Rings, Enemy at the Gates, Up, Dark Knight, Shrek to name a few.. Thanks to Manu and Karan.

Lord of the Rings – I must write about this magnum opus. Manu told me that it’s the best movie adaptation of a book ever and refused to give me the movies until I read the book and he bought me one (thanks dude!). By the time I finished the book, I was already blown away at the fantasy and the imagination. And the movies did not fail the expectations. All three were magnificent, especially the last one – Return of the King !!

I have been searching for a book for long (which I read in a local library at the age of 10 or 11) and finally got it yesterday at a book shop in T Nagar. “Thiruvarangan Ula” – a fascinating historical novel – is one of my most favourites and glad that I got hold of a copy of this 4-part book and have already finished the first part :)

As always, would love to get back soon :)

Blog Stats

  • 24,266 Visitors

My Tweets

About Me

Journey so far…

Email Subscription

Enter your email address to subscribe to this blog and receive notifications of new posts by email.