Saturday, April 16, 2011

Display UUID of disks in Debian

Jaya Srila Prabhupada.

The command is: blkid

Jaya Sri Sathguru Bhagawan Sridhara Swamy Maharaja

Wednesday, April 13, 2011

What I learned the last week

Jaya Srila Prabhupada (most merciful savior)

TCP/IP programming in Windows.

Started with my own classes ServerSocketFactory and ClientSocketFactory which encapsulated the TCP/IP api of .NET. One more class NetworkSocket encapsulated the Socket api of .NET

Learned by mistakes.

First mistake was that I bound the listening socket to the localhost (SockAddress.Local) instead of binding to SocketAddress.Any

I learnt that one can chain readers like this:
new StreamReader(new NetworkStream(new Socket(adr_family, sock_type, proto_type)));

Now writing or reading from a reader object writes to the underlying stream!

The client used to ask for something by sending a string of characters with a newline trailing and I was trying to receive it without expecting a newline. Sometimes it was the other way round. Both should settle on one scheme. When we call the 'ReadLine' method on a StreamReader, it doesn't return until it sees a newline. The ReadLine method always returns a string that was read from the stream (here socket).

What happens when you are trying to read from a connected socket but the remote socket is closed, the Receive method (analogous to 'recv' in unix socket programming) returns immediately with zero bytes. Analogously if we are using the 'ReadLine' method on a StreamReader of a socket, the ReadLine method returns immediately with a null value (and NOT a null string).

Jaya Sathguru Bhagawan Sri Sridhara Swamy maharaja.

Monday, March 28, 2011

Using 'du' command to leave out other filesystems

Jaya Srila Prabhupada.

du -hsx /home

this command leaves out other filesystems that may have been mounted in the filesystem heirarchy starting at /home.

Jaya Sathguru Bhagwan Sridhara Swamy Maharaja.

Backing up home folder

Jaya Srila Prabhupada

cp -vrx /home /home/ghd/mnt-backup

Because we use the -x option, this command doesn't copy contents from other filesystems that may have been mounted in the filesystem heirarchy starting from /home.

Jaya Sathguru Bhagwan Sridhara Swamy Maharaja.

Thursday, March 17, 2011

Conditional Expression in C

Jaya Srila Prabhupada



A conditional expression is of the form:
expression ? expression_true : expression_false

Yes, the conditional expression involves the ternary operator!

Jaya Sri Sathguru Sridhara Swamy Maharaj.

Wednesday, March 16, 2011

Sorting the output from 'ls' command when filenames have numbers

Jai Srila Prabhupada.

Many times filenames contain numbers of arbitrary length - file1, file2, ..., file9, file10, file11, ..., file19, file20, file21, ... so on. When we run the 'ls' command, the output is sorted based on dictionary order and not in the way shown above.

Use the following command:
ls | sort -V

Note that we are calling 'ls' without any arguments, otherwise it won't work.

Jaya Sathguru Bhagawan Sri Sridhara Swamy Maharaja.

Friday, March 4, 2011

Why some Linux distros install to extended partitions



Jaya Srila Prabhupada

Some Linux distros including openSUSE create an extended partition on the hard disk before installing the OS on to it. Also the partition numbering starts from 5 and not from the next available number. For example, if I have one partition on the hard disk namely sda1 and I am installing openSUSE on it, the latter creates an extended partition sda2 and logical partitions starting from sda5 (sda5, sda6, and so on). One may wonder why the logical partitions didn't start from sda3.

The reason is extra convenience that one gets when one needs to add a partition. For example, if another (primary) partition is added to the disk described above, the new partition will be numbered as sda2 and the extended partition that was previously numbered as sda2 becomes sda3. However, and this is the important point, none of the logical partitions need to be renumbered; they still start from sda5. Thus no changes need to be made to the boot loader (e.g. GRUB) and fstab entries in the installation.

Jaya Sathguru Bhagawan Sridhara swami maharaj.