Monday, December 11, 2006

My Experiments with Mandriva (Not with Truth :) )

Lately (2 days back) I got the Mandriva DVD from one of my friend. I was fascinated with the 3D effects it provides and installed in my machine. I faced a lot of issues.



1) Gaim - I was chatting with my friend. In the middle, i opened another window and started reading something. After a couple of minutes, when i saw the chat window a whole bunch of messages were waiting for me. He was about to scold me. I was NOT NOTIFIED about any new messages. Felt really bad :(



2) The X server crashes when i try to login for the second time. Seems like X server is not yet stable... im not sure. When I switch between the virtual consoles also, sometimes it crashes.



3) I installed netbeans. After installation when i attempted to start it, i could see only the netbeans window without any contents inside it. No menus, nothing. The reason being, AIGLX conflicts with netbeans. When I disabled the 3D effects, it launched fine.



4) I dont think Mandriva has to advertise that their linux is Free throughout from the booting screen to login screen, KDE start menu. It is really annoying...

Thursday, November 09, 2006

Firefox trusts Google in Linux a lot?????

Most of you might have known the feature provided by Google. Using your id you can save your search and use other services offered by Google. I'll do it regularly. I am using a dual boot (FC5, XP) machine. I was logged into my Google account using Firefox on my linux. Without signing out, I closed my browser and rebooted to Windows. When I logged in to linux again and opened Firefox, I saw that im logged in to my Google account. I could not believe it. I tried it multiple times. It was happening repeatedly. But this does not happen in Windows.

Seems like the session information is serialized by firefox in linux and it is used subsequently. This happens only with Google and not with any other sites like Yahoo, Hotmail....

Can anybody explain why??

Wednesday, November 08, 2006

Export Variables from Shell scripts

This time, I got a script that sets some environment variables. They had suggested to run as . script . I noticed it, but I didn't cared about that and ran it in the traditional way as ./script . When I echoed the variable, it was not displayed. Then I tried as they have mentioned (Obviously after meddling with the scripts :)). Wow, I got the values. But how????? I googled and then found out that

"When we run a script using ./script it creates a separate shell and then run it. So, since the variable is exported in that shell, it is not available to the parent shell after completion.

When we run a script using . script it runs the script in the same shell which makes the variables available even after the completion of the script."


In Tamil, we have a saying "Katradhu kai mann alavu. Kallaadhadhu ulahalavu". Meaning, Whatever you know is the amount of sand you can have in your hand. Whatever you dont know is as huge as the world. :)

Saturday, October 14, 2006

More on VIM

I was bored and just browsing through del.icio.us. And got a link saying that VIM is easy than you think. Got interested and Wanted to know what they are telling about vim. They said that VIM 7.0 supports tabs. Here is the link

Browsers, editors in linux and now???? vim.
Everybody is after tabs... :) For people like me, who don't like to see the desktop cluttered with windows, like in some operating systems, it will be gud to use.

And will those OS introduce tab based explorers for browsing the local file systems in future????

Wednesday, October 11, 2006

Power/Weakness (???) of Reflection in Java

Blogging after a loooooooooooooooooong time. :)

I got this question and answer from somebody else and thought of sharing:

public class test{
  private String id;
    public String getId() {
      return id;
    }
}


In this class, how to set value to id?

The answer is "Reflection"

Use the following code:

test obj = new test();
Field myfields[] = test.class.getDeclaredFields();
for (int i = 0; i < myfields.length; ++i) {
  if ("id".equals(myfields[i].getName())) {
    Field f = myfields[i];
    //This is important , otherwise u get a access denied exception
    f.setAccessible(true);
    f.set(obj,"I modified it");
  }
}


Seems like this is a security issue in Java. I read that if we used SecurityManager, this can be avoided. ( Have to learn about SecurityManager :) )

Thursday, July 13, 2006

Finding Symbolic Links in Java

This time, I had to list all the files in my PC using Java. I wrote a java program and while running it, I got a error saying, "too many levels of symbolic links". I searched in Google, and found that, I can eliminate the symbolic links using the following code.

File system listing shows (b.txt -> a.txt).

File f = new File("b.txt");
System.out.println("Canonical : "+f.getCanonicalPath());
System.out.println("Absolute : "+f.getAbsolutePath());

Output :
Canonical : a.txt
Absolute : b.txt

Here, if both the path are not same, then the file pointed by Absolute path is a link or may be present inside a folder which is a link to another.

This didn't told me whether a file is sym link or not. coz, if the file is present inside a directory which is a link to another, then I this code will say that the file is a sym link.
ie. if dirB is a link to dirA and the file is present in dirA, then this code will tell me that the file is a sym link, which is not true.

But I will know that, there is a path without any sym links to access this file.

Sunday, July 02, 2006

Devices can generate smells

I was going through Slashdot and I found that devices can be used to generate smells. I got interested and went to the following link. It explained me more. Some time back, My friend has asked me for some object. I just jokingly told him that I'll send him thru attachment of an e-mail. He said that, there are things which are tangible and untangible. But after seeing this, I feel that that the day by which we can send objects through emails is not tooooooooooooo far... :) :)

Tuesday, June 27, 2006

Adobe Reader can READ

This time I got a mail saying the above subject. I can't believe it. I tried and it worked...
But it is only for windows. :(

Short cut keys for making Adobe to Read a pdf file for you:

Ctrl+shift+b - to hear the entire Document
Ctrl+shift+v - to hear the page
Ctrl+shift+c - to resume
Ctrl+shift+e - to stop

There are lot of ways to make people lazy... This is one among them...
Just kidding. :) :)

Joining lines in sed

I copied some text from a web page. I wanted to print the doc. It was pre aligned. When I copied it to my word processor, it was not aligned properly and it ate up lot of space. I wanted to combine the lines to a single paragraph. Since Im not much familier with the word processor, I decided to use sed. After googling, I found

sed -e :a -e '$!N;s/\n\([a-zA-Z]\)/\1/;ta' -e 'P;D'

Done...

Friday, May 05, 2006

CAT or REDIRECT

Today I had a strange problem. Let me explain...

I want to read a property file and assign values to variables.
My code was like cat prop_file | while read line ; do value=$line; done
print $value


Guess the output I got !!!!
Output: (Nothing) :(

I and my collegue fought for a looooooooooooooooooooooooong time. Then he asked me to use as follows. Modify the code as:
while read line ; do value=$line; done
print $value


and asked it to run as ./myfile.sh prop_file
Hurraaaaaaaaaaaaaaaaaaaaayyyyyyyyyyy!!!!!!!!!!!!!!
I got the output.

Reason: After some trials he told me that the reason might be: The cat might spawn a new shell and execute the entire while loop inside the shell. So the value might not persist after the end of while.

And this entry is dedicated to Vaidhy (my collegue) ... :) Thanks Vaidhy...

Thursday, March 23, 2006

Recording in VIM

Today I had to do something like moving a text following a pattern to a next line.

Eg: sometext; othertext

I didn't wanted to go through all the lines individually and move it
to next line. At that time, I heard something called as "recording"
from one of my friends. As per that I did the following and I felt in
very deeeeeeeeeeeeeeeeeep love with VIM.

  • Entered recording mode by pressing "q" followed by a letter say "a"
  • Then searched for ";" using "/" and then went to insert mode
  • Inserted a new line and then moved down to next line.
  • Pressed "q" again to quit recording mode.
  • Then pressed "@a" and it replaced the first occurance of the pattern to next line.
  • To repeat 10 times, I used "10@a"
Once we are in recording mode, vim stores all the key strokes with the name we give. Then replays all the actions when we use "@". Similar to "play" in a tape recorder.
The number (10) indicates the number of times to replay.

Really a nice feature of VIM...

Thursday, February 23, 2006

Tips

From today, I like to add new some useful tips that I came across in "Tips" title.

  • Check Folder size in Unix thru console : du -h
  • Check disk free space in Unix thru console : df -h
  • List all open ports : nmap -sT < host name >
  • Read file contents through bash : cat file.lst |while read line; do echo "${line}"; done
  • We know that top gives the information about the CPU, MEMORY usage of a process in a Linux Box. For Solaris, we have prstat command. This gives the similar information.
  • Setting priority for a process in Linux : nice -n -20 <command>. Starts the "command" with highest priority. 19 is the lowest priority.
  • Setting priority for a running process : renice <priority> -p <pid>
  • Listing directory structure in tree format (I stole it from a website ;) ) : ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'

List will grow as and when I learn new things... :)


Monday, January 02, 2006

Creating Shared Libraries using GCC

I have used a lot of shared libraries. Then thought of building one with gcc. Before building, I thought that it will be difficult thing to do. After creating one, I felt like "Is that all we have to do ?????". I followed the steps:
  • Created a function in a file (myshared.c) without a main() function.

  • Compiled it with -enable-shared option and renamed to libmyshared.so. Thatz all. I have created a shared library.

  • For using it, I updated the LD_LIBRARY_PATH to the location where the .so is present. The other option is to run ldconfig.

  • To use it, I used gcc -lmyshared myfile.c.
    • -l option searches for libmyshared.so in the library path.
    • myfile.c is the one that uses the function that I have created in the myshared.c
  • Done.....