Archive for the 'Howtos' Category

Installing tomcat 6.0 on MediaTemple dedicated server

In the last post, I looked at how Java can be configured on MediaTemple CentOS server. This post will show you how you can install Tomcat on your server.

1. Download and extract tomcat 6.0 binary distribution. Get the URL of the tar.gz file from http://tomcat.apache.org/download-60.cgi. From the ssh console download using wget.

wget http://apache.deathculture.net/tomcat/tomcat-6/v6.0.14/bin/apache-tomcat-6.0.14.tar.gz

Now use the following commands to extract the files.
gunzip -d apache-tomcat-6.0.14.tar.gz
tar -xvf apache-tomcat-6.0.14.tar

2. set JAVA_HOME variable to point to your Java installation.For this you need to login as root. Create or edit a java.sh inside /etc/profile.d. Add the following line in java.sh.

export JAVA_HOME=/usr/java/jdk1.6.0_04

3. Start tomcat from bin folder. Login again to SSH using your non root user id.  The startup script for tomcat is in [tomcatdir]/bin. Change to bin and then execute,

./startup.sh

Voila! You should see the tomcat server running at www.yourdomain.com:8080/

To shutdown you can use ./shutdown.sh, but for some reason I am not able to execute it. So currently the only way to stop is to kill the Java process from SSH. Update: I got shutdown.sh working by adding -Xmx4m as JVM parameter in catalina.sh for “stop” block of code.

Now my next task is to get Struts2 sample application running on this…

Installing Java 1.6 (JDK6.0) on MediaTemple dedicated virtual server (dv)

I recently bought a dedicated virtual hosting service on MediaTemple. The idea was to use this server for all my future projects in J2EE and Ruby on Rails. For $50/month, this service is not exactly cheap, but I am yet to find an alternative VPS host (I am planning to evaluate SliceHost sometime in future)

By default, the server comes with Ruby 1.8.5, but not Java compiler. My first task was to install latest JDK (1.6) on the VPS server.

All dedicated virtual servers hosted by MediaTemple comes with a CentOS installation. You can check that by running the following command on SSH terminal.

cat /etc/redhat-release

I got CentOS release 4.5 (Final) on the console.

Now before you can install Java, you need to know the password of “root” user in your server. For this, create a new support request and ask MediaTemple to set your root password of your choice.

Now comes the second problem. How do you download Java binaries onto your server? One option is to download JDK on to your machine and then upload it to server. Since the file size is more than 60MB, I didn’t want to use this method.

What you need is the ability to download J2SE 1.6 rpm binaries directly to your dedicated server. The Linux command “wget” is the ideal tool for this. But what is the URL to download?

The problem with Java download is that there is no direct link available for download. In order to force license display and acceptance, Sun uses a hidden redirect to the actual download. You need to find this URL.

For MediaTemple installation, select Java download which is “jdk-6u4-linux-i586-rpm.bin” from the list at http://developers.sun.com/downloads/. Using Firefox, start the download. Immediately pause the download and then righ click on the “resume” link to get the actual download link.

Paste the URL in a text editor and then quote it by adding double quotes at the beginning and at the end of the URL.

Now from the SSH terminal, type the following.

wget <quoted url from text editor> -O j.bin

This will download the Java binary as j.bin in the current folder. Now change to super user mode by typing sudo su.

Make the j.bin executable for using the command chmod a+x j.bin and execute it by ./j.bin. Accept license terms and continue. You will get the Java installed on the MediaTemple DV server.

But you are not there yet! Following is the error I got when I ran “java -version” on the command prompt.

Error occurred during initialization of VM
Could not reserve enough space for object heap
*** glibc detected *** free(): invalid pointer: 0xb7e71280 ***
Aborted

On CentOS you need to do something more to get Java installed. You need to set a link to Java. Execute the following from the root privileges. Change jdk1.6.0_04 to your version of JDK download.

/usr/sbin/alternatives –install /usr/bin/java java /usr/java/jdk1.6.0_04/bin/java 1

After this I was able to get a sample Java program running on the MediaTemple dedicated server. Now the next step is to install Tomcat App server. That is for another day….

Build your next pc under $500 (Rs. 20000)

I recently got a brand new pc assembled. Prices have been steadily dropping for pc components and it is possible to assemble a good system under Rs. 20000 ($500) in India. In other places it should be cheaper. Check out the following specifications and price. I am not an ‘expert in bargaining’ and if you are smart enough you should get the components less than the price indicated.

1. Motherboard - ASUS M2A-VM HDMI - Rs. 4000 ($100)
This is one of the first motherboards to support HDMI. This means you can play HD-DVD or Blue-rays discs. Comes with integrated ATI Radeon X1250 DDR2 800 graphics.Another important feature is that you get dual monitor support - DVI-D and RGB. You can also with the DVI version (without HDMI) and it is cheaper by about $15.

2. Processor - AMD X2 4800+ - Rs. 3500 ($85)
This is a medium range dual core processor from AMD. Depending on your budget you can choose 4200+, 4400+, 4800+ or 5200+. Price difference among 4xxx range is rather small and hence I prefer 4800+

3. Harddisk - Seagate 80GB SATA - Rs. 1500 ($40)
I normally don’t need even 80GB since I plan to use this PC exclusively for programming and related stuff. Don’t go for higher capacity disks unless you really need it in next one year. Another option is 160GB SATA which costs around Rs.300 ($8) extra.

4. RAM - 1GB DDR2 800 (2 nos) - Rs. 2200 ($55)
These days you need atleast 2GB of RAM. So go for two 1GB DDR2 800 modules. If you are into real multitasking with eclipse in one monitor and radrails in another, you can probably go for four 1GB modules. The motherboard supports it!

5. Cabinet with SMPS - 500W Mini- Rs. 1500 ($40)
Go for a 500W mini cabinet. There are too many in the market. Go with the one which has better warrant terms.

6. LCD Monitor - 19″ WideScreen - Rs. 8000 ($200)
Here your options are between a 17″ and 19″ inch LCD screens. I think it is better to go for 19″ considering the small price difference (around 10% extra). Here some of the choices are samsung, LG, viewsonic etc. Buy it after comparing the lcd monitors since each one has his own preferences. It may be a good idea to go with the one which has integrated speakers (if you not music crazy!)

7. Keyboard,Mouse and DVD Drive - Rs. 2000 ($50)
Again too many choices to list here. Go with a medium model which is good enough for regular use.

So total price = Rs. 22700 ($565). Oops! We started with a budget of Rs. 20000. Now here comes your bargaining skills. When you are buying all these together you might be able to reduce Rs. 700 atleast. Then change your monitor to a 17″ and AMD X2 processor to 4200+. Now you have an excellent desktop pc under $500! :-)

You can get almost all the items in this list from Amazon. Those are listed below. Of course, you cannot bargain with a Website :-)


Reading Malayalam Websites in Ubuntu (non unicode ones)

Unicode fonts are the best for publishing Malayalam (my native language) content on the web. But many of the popular regional sites such as Malayala Manorama and Deepika still use custom fonts which works on ISO encoding.

In Windows, these fonts are automatically supported. When it comes to Ubuntu, what you see is a jumbled set of characters. Following set of instructions will help you reading Deepika in firefox. Follow a similar procedure for other sites.

1. Install the custom font. For Deekipa, Malayalam font can be downloaded from http://www.deepika.com/font.htm. Download this to a folder and then using terminal go to the folder. Now copy the font to /usr/share/fonts,

sudo cp mlkr0ntt_TTF.ttf /usr/share/fonts

2. Refresh the Ubuntu font cache. For that run the following command,

sudo fc-cache -fv

3. Close all firefox sessions and reopen firefox. Go to www.deepika.com. Now from the firefox menu select the following,

View => Character Encoding => Western (ISO-8859-1)

Now you should be able to see some Malayalam characters!

Installing Adobe flash player on Ubuntu 7.10

These days flash player is a must have plugin for browsers. Without it you cannot a lot of video sharing sites such as YouTube. By default Ubuntu doesn’t come with flash player since the Adobe flash player is proprietary. So I did,

jayson@jayson-desktop:~$ sudo apt-get install flashplugin-nonfree

Everything went smooth till the last step where I got,

Download done.
md5sum mismatch install_flash_player_9_linux.tar.gz
The Flash plugin is NOT installed.

It turns out that Ubuntu does a MD5 checksum check on the packages it install. Unfortunately Adobe changed the flash player installer sometime in December. So what to do?

The solution is to manually install flash player. Ensure that you close all the browser windows before doing this.

# get the flash player tar
wget http://fpdownload.macromedia.com/get/flashplayer/current/install_flash_player_9_linux.tar.gz

# extract the tar file
tar xvf install_flash_player_9_linux.tar.gz

# run the installer
cd install_flash_player_9_linux
./flashplayer-installer

# specify the firefox folder during installation
/usr/lib/firefox

Thatz it. Now you can watch flash videos on Ubuntu!
This also shows why it may be better for your grandma to stick with Windows! :-)

Migrating from Windows to Ubuntu

I recently uninstalled Windows from all my machines and installed Ubuntu on them. There are two reasons for this,

1. I don’t want to buy a new Windows license whenever I buy a new machine. I already have spent over Rs. 10K on Windows licenses and is not ready to pay again!

2. Ubuntu supports all my hardware out of the box! Even WiFi cards(NetGear) and WiFi adaptors (Dlink DWL-G122)  are supported when you boot Ubuntu.

It has been a smooth transition. One of the things that I enjoy a lot is the Pidgin IM client. Now I can login to all my IM accounts at once. Hence I got in touch with old friends on some of my old IM accounts!

Here is quick re-cap of what I did,

  • Booted using the latest ubuntu release - 7.10.
  • Deleted all existing partitions on my 80GB disk.
  • Created a root partition of 6.5GB and a swap partition of 1GB. I kept these partitions below 8GB since on M2N-MX motherboard, grub is having problems booting from a partition over 8GB!
  • Installed the following software using apt-get - Java 1.6, Aptana IDE, unrar, Lyx, Ruby1.8.6 and Rails2.

Accessing your Website when DNS servers are down

Recently Dreamhost had DNS problems and my site was not available for almost 12 hours. But I managed to update my site even when the DNS server was down! The trick is to tell your browser that you know the IP address and there is no need to do a DNS lookup. Following example assumes that you use Windows system.

First search for a file named “hosts” inside your windows installation. It is typically located under “c:/SYSROOT/system32/drivers/etc”. Open this file. It looks something like below. Note the entry for “jaysonjc.com”. Substitute your IP and domain name here.

You local DNS cache

There are two ways to find your IP address. One way is to use services such as Host2IP. You can also find your IP address from the Dreamhost panel. Look for IP in panel->manage domain->DNS

My DNS entries in DH

Please note that domain to IP adress translation is not static. This means your IP address can change! So use this technique only when you know that DNS server is down. Once it is back online, delete the entry from hosts file.
 

Enabling single sign on - Web applications in WebSphere 6.0

Recently I came across a requirement to enable single sign on between two different Web applications running on different machines but on the same domain. WebSphere does provide out of the box support of single sign on, but figuring it out took a lot of time for me. So I have written this step by step guide so that you don’t have to go through the torture again!

All the screenshots in this guide are taking from Rational Application Developer (RAD). I could configure everything except “roles to groups mapping” directly from RAD’s console. For configuring “roles to group mapping” I had to export and deploy the application from an EAR file.

1. Enabling WebSphere security

Check out the following screenshot which shows the settings I have selected under Security->Global Security.

Global security settings

a) LTPA is required when the Web applications are on the different machines but on same domain.

b) I used a custom user registry which checked the users against a database. A more common approach is to use LDAP.

2. Click on the “custom” link under user registries in Security->Global Security. Following settings were selected on this page.

a) userid and password given is a valid user id in the database.

b) MyUserRegistry implements com.ibm.websphere.security.UserRegistry interface and is copied to the “classes” folder inside WAS home folder.

3. Click on “LTPA” under authentication mechanisms. Single sign on can be enabled by clicking on the “Single Sign On” link on the right.

The above three steps completes the “Global Security” setup on WAS. Now we will configure JAAS for applying this security at the Web application level.

1. Configure web.xml of the application. This involves protecting Web resources using security-constraint entry. Following is a sample entry,

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Protected Area</web-resource-name>
            <url-pattern>*.do</url-pattern>
            <http-method>DELETE</http-method>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
            <http-method>PUT</http-method>
        </web-resource-collection>
        <auth-constraint>
            <role-name>operator</role-name>
        </auth-constraint>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>     
    <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>MyApp</realm-name>
        <form-login-config>
            <form-login-page>/logon.jsp</form-login-page>
            <form-error-page>/logonError.jsp</form-error-page>
        </form-login-config>
    </login-config>

2. Implement a login page for application which conforms to WAS standards. Following is a sample page,

<html>
  <title>Login</title>
  <body>
  <form method=”post” action=”j_security_check”>
     Enter user ID and password:
     User ID: <input type=”text” size=”20″ name=”j_username”>
     Password: <input type=”password” size=”20″ name=”j_password”>
     <input type=”submit” name=”login” value=”Login”>
    </form>
</body>
</html>

3. While deploying bind web.xml roles with groups from UserRegistry. For simplicity you could also attach the entire role to “any authenticated user”.

Some common errors and their solution,

1. When I start RAD after enabling Global Security, it is in “starting” mode forever!

Open soap.client.props in base_v6\profiles\default\properties folder and add the userid and password fields as shown below. The userid/password must be the same as the one given on “custom user registry” page.

com.ibm.SOAP.loginUserid=test
com.ibm.SOAP.loginPassword=test

Run the following command on the command as shown. Replace the cell name and node name with the values on your machine. This reconfigures FileTransfer application with authentication.

D:\Rational\runtimes\base_v6\bin>wsadmin wsadmin.bat -profile redeployFileTransf
er.jacl -c “fileTransferAuthenticationOn machine97622Node01Cell machine97622Node01
 server1″ -user test -password test

2. I am getting the following error,

Authentication failed for user: com.ibm.ws.console.security.ConnectToRuntimeException: null nested exception is com.ibm.websphere.security.CustomRegistryException

This means that custom user registry is not loaded. Ensure that you restart RAD after copying custom user registry class. Also ensure that custom user registry class is under classes folder (base_v6\classes on RAD)

3. I have an error which is not listed above?

Check the trace.log inside base_v6\profiles\default\logs\server1 folder. This should give a lot of information about the underlying problem. If you are still unable to resolve the issue, contact me!

Pagination in DB2 database

Pagination is required when you develop a listing screen which has thousands of records. The best way to implement pagination is to leverage features available on the database. In an Oracle database you can use RANK() function. On a DB2 database you can use ROW_NUMBER() function. Following example shows how to implement pagination on a DB2 database,

SELECT * FROM
  (SELECT a.customer_name, ROW_NUMBER() OVER
    (ORDER BY a.customer_name) AS RN FROM customer a
    WHERE a.customer_status=’ACTIVE’
  )
X WHERE X.RN BETWEEN 0 AND 100

This method won’t work if you are using AS400. On AS400, the only way seems to be iterating through the entire result set and then picking up records needed for the screen. For example, if you want to show records 100 to 200, start from 0, ignore upto 100 and then populate records from 100 to 200 and then stop. Obviously this means that if the resultset is huge and if you navigate to the last page, it might take a lot of time.

Top 5 ways to love your wife

Blogging guru Darren Browse is currently running a group writing project called “Top 5“. He is offering $1001 for the best blog post on “Top 5″. With the rise in the value of rupee, $1001 is not worth much, but still will fetch a decent laptop. So I decided to give it a try.

Top 5 ways to love your wife

1. Listen to her - This is one of the most important things that husbands normally miss. Listen to your wife and it is something guaranteed to improve your family life! Here is a tip - don’t pretend to be listening, trust me, it won’t work.

2. Express your love - It is something which is easily overlooked in our busy life. But expressing your love is so much important for the warmth and closeness of a married life. You know, sex is good for your health and mind :-)

3. Share responsibilities - There is a saying that “a man is incomplete until he is married”*.  Giving your wife responsibilities is an effective way to show that you trust her. Also help her in taking care of babies or in kitchen work.

4. Respect her - “Respect” has an unique property. You give it, you will get it back. So if you expect respect from your wife, first show it to her!

5. Surprise her - There are a lot of ways to surprise her. Throw a surprise party, go on an unplanned vacation or just buy her a simple gift. The smile on her face is worth a million bucks!

After writing this I have decided to change what I planned to buy with Darren’s gift. I would probably buy an all paid family trip to singapore ;-)

*- the complete quote is “A man is incomplete until he is married. After that, he is finished.”

Running Debian on your Windows PC

In this article I will show you how you can convert your Windows XP machine to run linux distributions such as Debian without risking your partition table! You would be wondering what I mean by “risking your partition table!”. Well, last week I had installed Ubuntu on my Windows PC and it had replaced Windows boot loader with Grub. After a while I decided to remove Ubuntu. I opened up the disk administration tool in Windows and re-partitioned the disk to free up the space used by Ubuntu. Then I realized that my Windows system won’t boot anymore! I had use the “Windows recovery disk” and then issue a “fixmbr” to fix my system.

This week I decided to try out Debian and this time I decided to install it on a virtual PC running on top of Windows. This has many advantages. First, there is no risk of corrupting your partition table. Secondly, you can easily add or remove more distributions. Thirdly, your WiFi may not be recognized by Debian net-install, but NAT translation by VMware ensures that WiFi is accessible as ethernet! Another advantage is that you can easily switch to Windows if you want to watch TV on your “Windows only” TV tuner card! :-)

There two leading virtual pc softwares in the market. Microsoft virtual pc and VMware server. Both these are free! I prefer VMware since almost any OS works on it.

Download Debian

You can download Debian ISOs which range from 30MB to 12GB! I decided to download 30MB network install ISO, which is a very minimal ISO.  If you use this, the components required for a base system will be downloaded during installation through an ethernet network available for your virtual machine. Also ensure that you download an ISO suitable for your hardware. For me it was an amd64 version(64 bit AMD processor).

Installing VMware

You can download latest version of VMware server from here (about 150MB).  You would also need to register to get your free serial key.  VMware asks for this key at the last step of configuring a new OS!

When you startup VMware, first you get “connect to host screen”. Select “localhost” since you are not trying out remote hosts.

From the File->New Click on “Virtual Machine”. This is used to configure a new virtual machine to run a different operating system.

1. Select “custom” for virtual machine configuration.

2. Select “Other linux 2.6.x kernel 64-bit” as the guest operating system. If you are not using a 64-bit system,use “Other linux 2.6.x kernel”.

3. Now select the file and directory for the new OS. Ensure that you select a disk which has enough space for the new OS.

4. For access rights, you can decide to make it private (accessible only for your userid) and accept defaults for the startup/shutdown options. You will need to change it if your account doesn’t have administrator privileges.

5. Allocate 50% of your total RAM for the new OS. I have 2GB total RAM and allocated 1GB for Debian.

6. Use NAT for networking and create a new virtual disk and accept defaults (SCSI). Allocate enough space of the virtual disk. I have 8GB for Debian.

Now you need to configure the downloaded Debian ISO as a CD Drive so that Debian installer will start when you boot up your new virtual PC. For this edit the new virtual PC and change the CD configuration as shown below,

vmware-new-pc3.png

Now start your new virtual PC from VMware. Now you should see the following Debian boot console.

 VMware and Debian

Follow the prompts and complete the Debian installation. Debian will download the required components by connecting to internet. If you don’t want this, you can use the complete Debian ISOs (instead of the 30MB business card version).

After installation, the first package I installed was the command line internet browser “lynx” by issuing the command,

apt-get install lynx
 

Google Hack - Running more than one Google Talk

Here is a cool trick which allows you to run more than one instance of Google Talk. I found it quite useful since I could keep my wife’s ID also logged on all the time.

Right click on the Google Talk shortcut and then add “-nomutex” as a parameter in the target field. The diagram on the right should clear any doubts you have! Voila! now everytime you click on Google Talk you get another session.

Google Talk trick

Twitter tricks, tips and tools

Twitter!These days Twitter is everywhere and there seems to be a global conspiracy to promote it. In case you don’t know what Twitter is, welcome back to earth!

Twitter is a global community of people answering just one question - “What are you doing”? You can create an account and then start sending your current status using either mobile, instant messengers such as Google talk or direct from http://twitter.com/.

This process of sending “what you are doing right now” is called twittering! If you want to see what someone else is doing, you can add him as a friend and you will get updates on what he is doing right now!

Another interesting feature is the ability to embed your current twitter status on your Website or blog. For example, in my site on the right side bottom you can see my current status!

I usually update my twitter status from Google talk. But these days twitter bot is down most of the time. Using SMS on mobile is ruled out since it costs around Rs. 5 per message! So the only option left is to use the Website which obviously is cumbersome.

It is probably one of the most addictive, useless and time wasting concept man has invented! But I have put together a list of twitter tips, tricks and tools for all the Twitter maniacs out there :)

Twitter based Websites

Twitter badges - Twitter provides a set of Javascript and Flash badges using which you can display your or your friend’s current status.

Twitter timeline - Official Twitter where all the latest public updates are available.

Twitter commands - Official list of all Twitter commands you can use.

Twitter API - Want to build something based on Twitter? Try the Twitter API.

Twittervision - This is a combination of Google maps and Twitter. You can see live twittering which will popup on the map. Very addictive! They have added a digg type “like” and “dislike” buttons for each twitter that is shown.

Twitter search - Search Twitter for stuff. Looking for links? Try searching “tinyurl”.

Twitterholic - Catch the most popular Twitters based on followers, friends, updates or favorites!

Twitter Tools

Twitterrific - This is a Mac client for publishing and reading twitters.

Twitteroo - This is a Windows client. The main advantage is the automatic shortening of URLs.

Twapper - This is a mobile client for Twitter. Use it if you don’t want to be flooded with SMS messages.

Twitter Firefox Search Plugin -  Post updates to Twitter right from your Firefox search bar!

Tweetbar - This is a Twitter sidebar for Firefox and Flock.

Twitter tools - Twitter tools plugin for Wordpress if you are too lazy to create badges.

Twitter hacks

Binny has written a shell script for twittering. This is based on Twitter API.

RSS to Twitter - Here is a PHP script to feed RSS to Twitter!

Is there anything I missed? Let me know, I will add it here.

Top 10 traits of a good programmer

As I have written in one of my earlier posts, this is the 9th year of professional programming for me. In this post I will summarize my thoughts on what makes a good programmer (master programmer or chief programmer as called by some). I wouldn’t call myself a master programmer yet, but I am pretty sure I know the traits that define a good programmer.

Now before I go into the details, let me first clarify what the term “programmer” means to me. A programmer is not someone who blindly implements whatever design is given to them. Many software service companies in India are under this impression. This myth is purposefully floated around mainly because 90% of the programmers in these companies have less than a year of programming experience. So  coding/programming has to be projected as a mechanical activity!

So who is a programmer? A programmer is someone who has fairly good understanding of computer systems, can write good code, is intelligent and can visualize a software solution for a particular software requirement. He looks at the software requirement and starts thinking - How do I build this thing? How I can design the interface so that it is most user friendly? What happens when there is huge data volume? How do I ensure that no one hacks into my program (especially for Web applications)? How do I reduce coding effort? How do I ensure future additions have minimum overhead?

So as you can see it is much more than just mechanical coding.

Ok no more preaching! Here is my top 10 traits for a good programmer.

1. Think! -  This is the most important trait of a good programmer. He never jumps into anything. Given a problem, he first thinks over it. The more he thinks, the more ideas, questions and alternate solutions come to his mind. I see the lack of thinking as the primary source of all problems a novice programmer face. When he comes across a problem, he doesn’t think. Instead he bangs his head on it or asks for help from another guy. Sometimes you need to ask for help, but think on the problem or bug before you run across to your technical lead!

I will give an example of the importance of this “Think” factor. Sometime back we had a requirement to build around 40 interfaces. This basically required scripts to be written to transform data from a set of tables in one database to another. The estimates were done like this,

1 interface = 5 days and hence 40 interfaces = 40×5 = 200 days of build effort.

When I started on the project, everything was in place. The team, the effort of 200 days and the schedule. Then I thought over it. I saw that if a generic framework is written for the transformation, I could externalize the transformation rules into an XML file. The generic framework took me about 10 days to build. Then for all the 40 interfaces, the time taken was 5 days (since only tranformation rules were to be written). So my team got a lot of free time! :)

2. Learn! - Learn Baby, learn! A good programmer has a burning desire to learn new things every day. It is almost 15 years since I started programming. And even today, I spent a lot of time learning new things. When it comes to programming, every program you write teaches you something. I have fairly good knowledge of Java, C, C++, C# and Qbasic (yes qbasic is my first love!). Just recently I have started learning PHP.

Nowadays learning trait is something which I see less and less in my professional life. The learning itself is so formalized and force fed that people are bored with it.

By learning, I am not talking about taking professional certification. Sorry to say this, but I have nothing but contempt for many of the professional certifications (for example the Sun certifications). In India, it is very easy to manipulate the system and there is a lot of fraud happening on the certification front.

3. Help others! - This to me is the golden rule of programming. “Help other as you would want others to help you”. In my case, I think much of the programming wisdom I possess has come from helping others solve their problems! I used to sit till late hours and help others solve their programming problems or bugs. The advantage was,
 a) Immense experience in solving programming problems.
 b) Various ways people see a particular problem. Also you come across interesting/weird/strange ideas!
 c) Empathy towards programmers. The difficulty they face in their day to day job.

Unfortunately as I grew older and came in touch with extremely process centric enviornments, I realized that “Help others” is not something officially appreciated.

4. Lead by example! - Another important trait if you are a senior programmer or architect. Many times I have come across senior technical architects who say - “It is simple, you just do this and do that”. I am 100% sure that many of them can’t code what they so confidently say as “simple”!

If you are a technical lead or a lead programmer, lead by example. Write code in front of your team members. You will get more trust, respect and support from your team!

5. Know everything! - Ok, that doesn’t sound right. I will rewrite it - Know a bit about everything. For example, If you are a core Java programmer, you should also know about SQL programming. It also helps if you know a bit of regular expressions or a scripting language. For example, I have recently gone through XML specification twice even though I have no professional need right now. But someday I will need it.

6. Know basics of computer science! - There are many programmers out there who doesn’t have the basic knowledge of computers or their inner workings. This is very essential. Many of the programming difficulties that people face is due to the lack of knowledge of how computers work! If needed take a computer science course.

7. Perfect it as much as you can! - Nobody is perfect. You can’t write perfect code in the first iteration. Refactoring is the mantra. Analyse your code, find code fragments that can be reused and refactored.

8. Use tools! - Many programming tasks can simplied if you use appropriate tools. For example, in all my projects I use Ant to automate build and deployment process. You will be surprized at the time you save!

9. Explore code! - If you want to improve your coding skills quickly, one thing I recommend is exploring code written by others. If I would have said this 10 years back, you would ask me- “Where can I find good code?”  But now the scene is completely different. Open source movement has revolutionized everything.  There is so much good open source code out there that I feel overwhelmed by it!

10. Be Humble! - Humility is the last of the top 10 traits a good programmer should have. But it is not the least! As you get more and more experience, it is very natural to feel arrogant. The moment you become arrogant, you loose the trust and respect of your fellow programmers.

I have come across many who are intelligent and technically quite good. But again I have no respect for them simply because they are arrogant. Being arrogant also shows how ignorant you are!

Remember, no one is perfect. You can also make mistakes. If someone points it out, thank him and accept his valid comments.

Closing thoughts

Now you might be thinking - Why is this guy not talking about “design patterns”? Why is he not talking about “Ruby on Rails”? What about extreme programming? What about open source contribution? Linux? and so on.

My dear friends, In my opinion talking about design patterns or practising pair programming(as in XP) etc. are not one of the top 10 traits. Being aware of design patterns definitely helps, but I think you will anyway come across it yourself if you are a regular programmer or if you explore code written by others!

Again I want to stress my first point. A good programmer is someone who can build a “good” software system given a software requirement. The “good” here means - correct, optimized, reusable, extensible and elegant. Everything else (tools, language, methodology) are just tools to achieve it.

Programming is not for everyone. If you don’t have the passion for it, quit and find another job. If your company doesn’t recognize your talent, quit the company.

Further Reading

Here are a couple of good books for exploring further on this subject. If you know a good one do let me know by commenting below.

The Mythical Man-Month: Essays on Software Engineering, 20th Anniversary Edition - The good old classic by Frederick P. Brooks.

Code Complete, Second Edition by Steve Mcconnell - A must read.

The Pragmatic Programmer: From Journeyman to Master by Andrew Hunt and David Thomas - I endorse the apprentice method

Expert One-on-One J2EE Design and Development (Programmer to Programmer) by Rod Johnson - A must read if you are a J2EE guy.

Your thoughts are welcome!

Hiding sub categories in Wordpress - a quick hack

Here is a quick hack to hide sub categories in Wordpress. This has the added advantage that even though sub categories are not visible, they will still get crawled by search engines. For example, the categories you see on the right are only the root categories.

All you have to do is to add the following line to the Wordpress stylesheet.

.children { display: none; }

This works because the secondary level categories have “children” as the style class.

Backing up your Wordpress installation on Dreamhost

I did a complete backup of this Wordpress blog yesterday. There isn’t much written, but loosing my blog entries is not something I am looking forward to! It is very important to backup your blog. I will give some reasons if you are not convinced.

First, this blog is hosted on Dreamhost. Recently many problems have been cropping up with dreamhost such as router disaster or network disaster or something like that. You never know when they will have a disk failure and it turns out that their backup tape/disk is unusable!

Secondly, Wordpress is not very secure if the recent events are any indication. The Wordpress 2.1.1 was modified by some deranged cracker. So it is quite possible that there are problems in Wordpress 2.1.2 also and if some nutcase decides to hack your site? Boom!!! - all your posts are gone..

How to backup my Wordpress blog hosted on Dreamhost?

The backup process involves two things. Backing up your blog database and backing Wordpress files which includes theme files modified by you. You must backup both.

Backing up Wordpress database - Backing up Wordpress database is very simple in Wordpress 2.1+. In earlier versions you need to install backup plugin. In Wordpress 2.1+ you can find export option under manage as shown below,

Backing up Wordpress 2.1+

Backing up Wordpress files including customized theme files - My host is dreamhost and I will explain how the Wordpress file backup can be done very quickly. If you use Windows explorer and try to copy everything, it can even take hours! This is because the dreamhost installation contains hundreds of themes you don’t use and also transferring thousands of files over FTP is very slow.

Here is a quick backup solution. Connect to the Dreamhost shell using Putty (A secure shell client). Go to your Wordpress installation folder and type the following command.

zip -r backupall.zip *

This will create a single zip named backupall.zip which contains everything. Now this can be quickly copied to your system!

Limiting query results in DB2. Replacing ROWID in Oracle

While working with DB2 tables, many times we may need to limit query results. This is especially true when we just want to test out our queries. If the data volume is huge, the queries can take hell lot of time.

In oracle, the solution is to use ROWID in WHERE clause. In DB2, you can use the construct FETCH FIRST 10 ROWS ONLY. For example,

SELECT * FROM CUSTOMER FETCH FIRST 10 ROWS ONLY;

Error in RAD 6.0: Resolve against non-hierarchical or relative base error

RAD error due datasource configurationWhile changing the datasource configuration in Rational Application Developer 6.0, I across the following error.

java.lang.IllegalArgumentException: resolve against non-hierarchical or relative base

This turned out to be a very nasty problem. I first tried removing the datasource configuration and reconfiguring it. When that didn’t work tried deleting the server configuration. No luck!

On googling, I came across this solution.
http://www-1.ibm.com/support/docview.wss?uid=swg21218587

Solution
Open the resources.xml and find:
<cmpDatasource href=”tempworkarea.xmi#DataSource_1125683336050″ mce_href=”tempworkarea.xmi#DataSource_1125683336050″/>

The only way to fix this error is to manually edit the resources.xml. On searching under runtimes folder, I came across multiple resources.xml files. Edited all of them and removed cmpDataSource references completely.

The steps are,

1. Shutdown RAD.
2. Remove cmpDataSource entries completely from resource.xml files under “runtimes” folder.
3. Start RAD and reconfigure datasources.

It worked!

Configuring DB2 connectivity in Rational Application Developer (RAD)

Rational Application Developer (RAD 6)When you start Web application in RAD 6.0 (Rational Application Developer 6.0), the first thing you need to configure is the database access. In this article, I will show you how to configure DB2 database access in RAD. I assume that DB2 is hosted on a Windows machine.

First thing you need to configure DB2 is the DB2 universal JDBC driver. These can be taken from DB2 server installation or from DB2 connect installation. The files you need are,

db2jcc.jar
db2jcc_license_cu.jar
db2jcc_license_cisuz.jar

Copy these files to a folder. This can be anywhere(I would suggest that you keep this under Rational root folder).

I assume you have already created a server configuration in RAD. Now right click on the server (from server window) and click on “Run administrative console”. This will open up the administrative interface. Typically it runs at “http://localhost:9060/ibm/console/“.

Login by giving any userId. Click on “JDBC providers” under “Resources”. On the right side you will see JDBC providers listed. Click on “New”. Now select values as shown below.

RAD JDBC Provider Settings

Click on Next. Now fill the driver paths in the Class path as shown below. You need to change this to point to the folder where JDBC jars are stored.

 RAD JDBC settings

Click on Apply button. Once you have pressed apply button, you will see a Save link above. Click on Save and then click on “Data sources” link on the right side. Fill in as shown below. Please substitute your DB2 server configuration (IP address, DB name and port etc.). Also note the JNDI name, which you will use in your application.

 RAD Datasource configuration

RAD Datasource settings
Click on “J2C authentication entries” on the right and fill in as shown below. This should be the DB2 userid/password. After completing this, press apply and return to Datasource screen.

RAD Datasource settings
Now you need to select the userid alias you have created from “J2C authentication entries” under component managed authentication alias as shown below. Please note that this is in Datasource screen.

RAD Datasource settings

Now you can apply and save the settings. Click on “Test Connection” to verify the settings. If you see a successful message, you are all set for DB2 access from your Web application!

Any problems? Mail me!