Saturday, March 28, 2009


Ever wanted to post your c code on your web page just as colorful as it looks in your vi editor? Well, I used to do this very often in the past. But then one fine day my (free) web hosting provider vanished and I lost all that. Then I stopped it for a long time. Recently I wanted to post some C codes that way, but could not remember how to do that. It took me 15-20 minutes of google search to get that command. Well its simple:

source $VIMRUNTIME/syntax/2html.vim
When you do this from vi, the window will split into two and one will show the corresponding html code generated (Ok, I hope its understood that this needs to be done when syntax highlighting is enabled). The new file generated will have the name . Save this new html file and you are ready to publish your code in its colorful glory.

Wednesday, March 25, 2009

Linux worms!

I was always with the group which argued that the Linux does not have worms and virus since it is not popular. Someone who is bent on paining the maximum number of people can easily do it on Windows OS family since it is the most widely used desktop OS. If tomorrow Linux replaces Windows, I feel, the same fate awaits Linux also.

I feel, it is a clear indication that if economy of volumes justifies, black hat hackers will find a way into your Linux system. All that talk about weak passwords etc is impractical since when you reach masses, a number of them will still have vulnerable passwords. In a way Linux has an advantage over windows since the people are more knowledgeable today than in the past as many of them have learned their lessons the hard way using Windows. Even today, I usually find many a edge device with default password. All I can say is, I see a good market for SELinux and related technologies.

Tuesday, March 24, 2009


I started learning this on Fedora 10 machine. The first thing that I noticed is qmake is named qmake-qt4. The following are my learnings yesterday.

1. Qt uses concepts of widgets (Which is very common and hence it was easily understandable)
2. Qt has built in layout classes which can be used to decide how you place your widgets in parent window
3. Qt has an assistant called assistant-qt4. This is used for searching and displaying Qt reference documents.
On F10, I found that assistant-qt4 is not able to search any docs as the docs were not installed. I have started installing them. This rpm is 85MB!
4. Qt works on "signals" and "slots"
5. Signals are the events such as mouse clicks
6. Slots are the functions that will be executed when a signal is received

Monday, March 23, 2009


For a while I was thinking about making some GUI programs. I have been looking at Java for that. But, for some reason I was not able to get into the details. May be because Java is still a mystery for me. It is only recently I looked at Qt. Since it is cpp, I feel closer to Qt :) I am going to try my luck with Qt. Will keep posting my progress here.

Compiling a Qt app:

0. Ensure that you have qt and qt-devel (yum -y install qt qt-devel)
1. Create a Qt source file first.cpp
2. Create a project with the command
qmake -project
3. Create a makefile
4. Make the app

Saturday, March 21, 2009

Remote console monitoring using screen

I wanted something like VNC for console. Had no clue whether such software did exist at all. In fact I did not expect to find any. I made a post at LQ and found not just one, but a bunch of them

It was really shocking to discover that such a common application like screen had this feature and I never knew. I did help my client. Now I found a better use. I am running rtorrent session on one of my computer. Usually, I go upstairs and check the status. Now, I can run it in a screen session, ssh to the machine, connect to the running screen session using screen -x and view the status. Just makes me think how many such unexplored features will be there in each of the programs that we use daily!

Intel Vs. AMD

Recently I had an argument with my friend about Intel Vs. AMD. Who has the best processor?

I remember the time when the AMD was pushing its processors very hard in India. They had some numbers like 1600 and 2000 etc to claim their processors are as powerful as intel 1.6GHz or 2.0GHz. Though I don't remember the details, I do remember working on one of them. The experience was worse compared to working on a 800MHz celeron in our labs. Whatever it may be, the argument is that they were only trying to make the people understand that the processors are not to be judged by clock frequency alone. But, I feel, AMD eventually confused some poor customers who were not that tech savy and AMD made money out of it.

My friend was of the opinion that AMD has processors that are comparable to intels. The following site contains some data which says otherwise.

Let me just look at two ends of the spectrum. I will take the high end first. Intel's Core i7 is sitting there unchallenged. AMD is yet to produce a comparable chip. But they are a bit costly and work with DDR3 only (I recently checked DDR3 price in market. It was about Rs. 2700 (~$54) for 2GB). But, its simply the best.

Now come to the lowest end of the spectrum. I am just looking at Core 2 Duo 8400 and Athlon X2 6400+. Just look at the amount of L2 Cache. You can also see the cinebench graph there. Again Intel processor simple out performs the counterpart from AMD. Now the price. Intel is about $75 more than AMD. Is this a real difference?

The answer to the above question is a simple 'No'. Why? Assume that you use the computer for 3 hours a day (I use it for hours together and I don't know what is the average home usage. But, I am assuming it will be close to ~3 hours/day on a normal shared home computer.) The power consumed by AMD processor is 60W more than the Intel processor. Result? 60 * 3 * 30 = 5400 Wh. In my state, excess power usage causes electricity board to levy you a charge of Rs. 7 per unit (1 unit = 1kWh). This is about Rs. 450 ($9) per year loss. Eventually, if a home user sticks to his computer for 3 years, he will spent extra $30 on this processor through the power bill. In an office, the computers run from 8-9 in the morning till 6 in the evening. And, thanks to our enlighted employees, some of them run 24 hours. If you assume only 9 hour usage per day, you will lose ~$90 in three years.

So, my humble conclusion is to stick to Intel for the time being :)

Wednesday, March 18, 2009

Write only space in Alfresco

Ok, I needed a write-only space for the Alfresco that we were managing for a client. This is what I did. Before you read further, read this

Go to your Alfresco install folder
1. Edit tomcat/webapps/alfresco/WEB-INF/classes/alfresco/model/permissionDefinitions.xml
2. Look for permission group Contributor
3. Remove Consumer and ReadPermissions
4. Save file and quit
5. Restart Alfresco (I did this. May be not needed)
6. Create two users: user1 and user2
7. Create a folder in user1 and remove inheriting access. Make user2 a contributor to it and user1 a collaborator
8. Create another folder in user2 and add a workflow to move content to the folder created in last step

Thats it. Done!

Wednesday, March 4, 2009

mysql commands (1)

Following are some useful mysql commands that I learned today

1. Reset mysql root password

1.1 Stop mysql service

service mysqld stop
1.2 Start mysql in safe mode by skipping grant table

mysqld_safe --skip-grant-table
1.3 Enter as root user

mysql -u root
1.4 Change the root password

UPDATE mysql.user SET Password=PASSWORD('new_password') WHERE User='root';
1.5 Flush mysql privileges
flush privileges;
1.6 Kill mysqld_safe and mysqld

2. Add a database (Login to mysql as root for all the below operations)

create database ;
3. Add a new user

The command below will add a user. But there is a catch here. The 'password' should be the hash value of the password. To get the hash of a password, use

select PASSWORD('MyPlainTextPassword');
It will output a value like "1b25e4042f3f780d". Use this in the next command.
grant all privileges on db_name.* to 'user'@'localhost' identified by password '1b25e4042f3f780d';
4. Drop a user
use mysql;
drop user;

installing ikiwiki

Well, I have a machine running from a 2gb pen drive. When I wanted to install a wiki, all I saw was the size needed. (Ok, I was also interested in this when I saw it can use git -- one of my new fascination -- ). This one runs fedora 10. I followed the following steps to install it. Since it took me a while to get it working, I thought I will add it here

1. Install ikiwiki using yum (Don't remember which repo was used. I have fedora, updates and rpmfusion configured and enabled)
yum install ikiwiki

2. Add a user for this wiki
useradd wiki

3. Login as that user
su - wiki

4. Setup wiki (Catch: You need gcc for this. yum install gcc if you don't have one yet). This will ask you the folder to setup your wiki and also a user to edit wiki. Answer them with whatever folder name and username that you choose. (Rest of the article assumes that you installed it in "wiki" folder)
ikiwiki -setup /etc/ikiwiki/auto.setup
5. Configure your apache (Not needed if you have already allowed user directories and permitted executable scripts in them). This will have to be done as root

5.1 Allow user directories
Look for public_html in /etc/httpd/conf/httpd.conf. Comment "UserDir disabled" and uncomment "UserDir public_html"
5.2 Allow executable files in them

Add the following to your httpd.conf

Options ExecCGI
AddHandler cgi-script cgi pl

Do not use a SetHandler. It will result in errors from httpd (When you open the directory, it will try to execute the directory itself and fail)
5.3 Save your configuration and restart httpd

service httpd restart
6. Make changes to your wiki directories (Access control changes). This will have to be done as wiki user

6.1 Make your public_html accessible to other

chmod 711 ~
chmod 755 public_html

6.2 ikiwiki does not set certain permissions correctly and it leaves the cgi file suid. Take care of them

chmod g-w public_html/wiki
chmod a-s public_html/wiki/ikiwiki.cgi

6.3 You can also use some basic http authentication if you need.

Now your wiki should be ready to be used. Go to http://localhost/wiki/wiki to start using it

7. Last but not least, if you run into trouble, keep watching the httpd logs and then perform the action that caused the problem

tail -f /var/log/httpd/*

These logs are very useful and you can use them for debugging any issues regarding apache in general.

Sunday, March 1, 2009


I was using svn for version control. However, when you are travelling, svn is not the greatest VCS you can have. After having my share of server crashes, bad networks and places without networks, I decided to move to git, a distributed version control system.