Wednesday, April 29, 2009

Pride Vs Shame

Hi,

Today there are few moments where i felt proud about my country at the same time felt ashamed.

Pride: I was working out in gym as usual. In the change room, i heard a background music compsed by our ARR in his slumdog millionaire. It was quite unusual for me to hear a song which is so familiar to me in the gym amidst the normal akon, justin timberlake, beyonce songs. This just gave me a feel good feeling but what made me to feel proud was one foreigner humming that background music on his way for shower. 

ARR - you made me (or rather us) feel proud. Miles to go!!

PRIDE



The other incident - Once i had my shower i was leisurely reading daily mail paper kept in leisure area of gym. There, i saw a photo of autorickshaw carrying loads of coconut fibres in a way that it entirely hides the autorickshaw itself. The comment on the photo was mockery. The below is the photo taken in our own mysore. 

SHAME



All the pride i had about my country few days before just vanished like passing clouds.

Thursday, April 16, 2009

One line find and replace string command in Linux/Unix.

Hi,

One of my friend was in urgent need for a find and replace command in set of files of some specific extension and asked me if i have one.

I gave him the following: Hope this is useful for you.

find . -name "*.extension" -exec sed -i s/strtofind/strtoreplace/g '{}' \;

where,
extension- extension of the file names where you want to find and replace.
strtofind- string to be found in those files.
strtoreplace- string to be replaced in those files.

Note: Please take caution when you want to find and replace strings having "/". You may need to use \\/ to make sure that "/" is treated as string by the sed command.

Thursday, April 09, 2009

Cleared SCJP 1.5 - 09/March/2009

Hi All,

Forgot to update you guys. I cleared SCJP1.5 exam on March 9,2009 with 87%. So here are few tips that i would like to suggest for future test takers.
  • Planning - minimum 2 hours per day for 3 weeks needs to be spent (42 person hours). 2 Weeks (28 person hours) for reading book and 1 week (14 person hours) for giving practise exams.
  • Book - Kathy Sierra.
  • Forums - www.javaranch.com
  • Mock Test - All mock exams listed in http://faq.javaranch.com/java/ScjpMockTests
  • Special mock test - Devaka Cooray (Exam Lab) mock test - listed as 46 in the above said mock test link.
  • Extra materials - To have a good understanding about Auto-boxing concepts and the generics concept along with examples, i purchased the materials from www.javabeat.com. The concepts explained in their material are very simple and intutive.
  • Scoring pattern - I was able to clear all the mock exams in the link mentioned above with score around 85%. Devaka Cooray is exception where i got only 51%,55%,57% and 60% in the assessment, first mock, second mock and final mock respectively. So dont get scared if you get low scores in Devaka's Exam Lab. Infact, the questions in the real exam were much more simpler than Devaka's Exam Lab.
If you need any further information, please mail me at thoppae.saravanan@gmail.com

Thursday, March 26, 2009

Recursive Listing of Files - Java code.

Hi,

Here is a small program that i have written to list directories recursively and also the count of files in each directory and output the same to console or to a file as per user preferences.

Usage: java ListFiles directory_to_scan [outputfile]

You can use this code if you really like and i dont impose any license restriction or something :)

But i will appreciate if you just send me a mail that you are benefitted by this simple piece of code.

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ListFiles {
private static List filesList = new ArrayList();
public static void main(String args[]) {
if(args.length ==0) {
System.out.println("Usage: ListFiles directory [outputfile]");
System.exit(-1);
}
String directoryName = args[0];
String outputFile = null;
if(args.length == 2) {
outputFile = args[1];
}
if(directoryName != null && !directoryName.isEmpty()) {
File directory = new File(directoryName);
if(directory.isDirectory()) {
File[] files = directory.listFiles();
int fileCount = directory.listFiles(new DirectoryNameFilter()).length;
filesList.add(directory.getAbsolutePath() + " = " + fileCount);
getFilesCount(directory);
}
if(outputFile != null) {
File output = new File(outputFile);
BufferedWriter bufWriter = null;
try {
bufWriter = new BufferedWriter(new FileWriter(output));
for(String fileName: filesList) {
bufWriter.write(fileName + "\n");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if(bufWriter != null) {
try {
bufWriter.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
} else {
for(String fileName: filesList) {
System.out.println(fileName);
}
}
}
}
private static List getFiles(File directory) {
List fileList = new ArrayList();
File files[] = null;
if(directory.isDirectory()) {
files = directory.listFiles();
for(File file:files) {
if(file.isDirectory()) {
fileList=getFiles(file);
} else {
filesList.add(file.getAbsolutePath());
}
}
}
return fileList;
}
private static void getFilesCount(File directory) {
File files[] = null;
int fileCount = 0;
if(directory.isDirectory()) {
files = directory.listFiles();
for(File file:files) {
if(file.isDirectory()) {
fileCount = file.listFiles(new DirectoryNameFilter()).length;
filesList.add(file.getAbsolutePath() + " = " + fileCount);
getFilesCount(file);
}
}
}

}

class DirectoryNameFilter implements FilenameFilter {

@Override
public boolean accept(File dir, String name) {
if(!new File(dir,name).isDirectory()) {
return true;
} else {
return false;
}
}
}

Tuesday, January 06, 2009

Leeds Castle - 03/Jan/2009















It has been a long time i visited some place outside london. Also since dostana1 (if you dont know who is dostana1 please read Mahindra City Memories - Part I) was here during the new year holidays, i thought it will be mutually beneficial if i go along with him to some place outside london. I then decided to go (rather take him) to Leeds Castle. Along with us, my roomie - Sri joined.

This leeds castle is in Kent county - south east part of England. To reach leeds we took a train to Bearsted station (which costs just 10.55 pounds - return ticket inclusive) from London victoria. There are two stations we can consider to reach this place. One is this bearsted station and the other one is maidstone station. But since bearsted station is closer to leeds castle and as it is the station that was mentioned in the leeds-castle.com site we took train going via this station.

Planning went for toss as usual. We planned to start by 10 AM atleast, but then by the time we boarded the train from east croydon it was almost 11.20 AM. Our journey plan was something like this.

East croydon - London Victoria - Bearsted station - Leeds Castle.

Breakfast?? - my money saving mind worked again. If we buy a croissant in some of the shops like upper crest, Delice de france, caffe nero it will cost around 1.5 pounds per croissant. But if the same purchased in some super market stores like somerfield, tesco or sainsbury it will cost only 40 pence. So I purchased a pack (which contains 4 croissant) of croissant from somerfield super market near east croydon and also got chai latte from caffe nero. We finished our breakfast during our travel from East croydon to london victoria.


We had a train from London Victoria to Bearsted station around 12.15pm and we reached Bearsted station around 1.15 pm. Once we reached the station we asked station keeper how to go to leeds castle from there. He informed us that there will be a bus in another 5 minutes, so we rushed to the bus stop which was just outside the station. To our dismay we did not find any buses going that way. A cab driver came to rescue us (some other indian friends were also waiting for the bus) offering drive till leeds castle. Dostana1 said that it should be free of cost but i know for sure that he was trying to indulge himself in joking mood which he can never ever do that. To prove my point the cab driver collected 10 pounds for the whole drive (We are totally 8 so it just costs 3 pound for 3 for us).

Once we got down i took out my samsung omnia phone (as we did not carry any other good cameras ;)) and starting shooting our Dostana1 and Sri.


The landscape around the castle was too good and we got to see goose, peacock and black swan (believe me it is really black swan !!!) roaming freely.
Also we saw that air balloons carrying people to have a panaromic view of leeds castle (costs 15 pounds per head :) - so obviously he he he)

After giving poses in various scenic areas, we got into the castle and awestruck the way it was built. I got to know little bit history of this castle. To get a good idea about the history of the castle please read it from wikipedia - http://en.wikipedia.org/wiki/Leeds_Castle

Oh yeah, you need to purchase entrance ticket to get in leeds castle but yet there is a way to enter for free!!!! I let you to find out how to do that.



Once our visit of castle is over, we again started taking snaps. But at this moment the temperature was getting down drastically that we are not able to stand without shivering. To add to this shiver, we found that no cab was available from the leeds castle towards bearsted station and also came to know that the public service bus is available only once in a hour. To make sure that the train availability/frequency is good, i used my samsung omnia to connect to internet (i really got to know the power of my mobile at these crucial times :)) and found that there is a train in another 30 minutes. So i asked Sri/Dostana1 to inquire about the cabs in the nearby souveneir shops. They did inquire about this and a lady helped us by calling a local cab driver. Cab driver arrived on time (Thanks to Sri who found out that the cab driver was waiting for us without even giving us a hint that he is a cab driver :)) and helped us to reach the bearsted station just 2 minutes before the train arrival. We had to shell extra of 4 pounds for this than we had spent for the cab earlier.



Once we got into the train we found out that we are in a compartment where there was no heater. You could imagine what was the state of Dostana1 and Sri in this case.

To summarize and to give some useful information from the above trip:
1) Take train to bearsted and from there take cab to leeds castle. Cab will be standing in the bearsted station itself.
2) Check if you can visit the castle for free of cost.
3) Go for air balloon ride (I will go once i become rich ;))
4) If you dont get cab to return to bearsted station - dont look any where else, just go to souveneir shop and ask for help.