Monday, June 27, 2011

Love

What is really Love? Parents to kids, or to your brother/sister, Love at first sight, to your husband/wife and the cycle goes on. What is really mean by Love? It’s a feeling or responsibility or both. Where it is this resides? Is it real need of your life? Can you live without Love?

It’s a very famous topic specially when you’re a teenager. But do we really understand it at that age? Or do we understand at it all?

For a civilized person living without love is almost impossible. We cannot define the Love by few sentences, but you can feel it when you’re in Love.

But Love is general form that used to describe a close connection with another party. When your kid or wife is around it’s your total responsibility and care that you provided for them. But when your brother is around it’s more like friendship. Your mother cares you more than you care for her.

Love at first sight, hmmm….. Is means physical attraction? So far you’re not in touch with her. So how come you Love a stranger. You don’t know her feelings. Any species has one goal when you see the world for the first time. It’s your duty to make sure the existence of your species. That’s why when you’re mature enough you will have your family. Whatever ceremonies, rituals you follow the prime idea behind getting married is having kids. Someone can argue that “I don’t want to have kids, but I will get married one day”. The point is as species you are a failure. It’s in our genes. No requirement or guidelines it is built in to the system.

Think how you cross your dog. Dog doesn’t need guidelines, isn’t it?

So what is homo-sexuality? Definitely you can’t have offspring. So why doesn’t it vanished during evolution.

Certain animals team up to protect them self from intruders, specially their offspring. So bond between team members need to be very high. Mutual understanding needs to be very high. This may be a reason.

And any bullet proof system has its own holes. ;)

May be its another way how it control the population.

Back to the topic- So these ceremonies, rituals, and modern life style is also a part of the biological human evolution. No right!!! But when you think what the real outcome of these is? Then you realize you’re still a player of the entire game. We think we created these, but rather those came to us. By doing that we pass our genes to next generation. So the Love also has its own variations. And is Love a part of the evolution?
Once you have kids then your parents love your kid more than you. They are much happier when your kid is around more than anything. Legally you cannot leave your kid whenever you want, but you can leave out your parents at any time. Why is that? Kid is your responsibility but still you “Love” him/her. So still we are playing the game of nature which make sure your kid grown up and have their own kids’ one day.
Do you know any animal that protect their parents? But mum protects her kid all the time. But humans care about their parents. We took a different path for our survival which any other species wasn’t able to do it so far. So we can accept the different. But for some reason we didn’t built that as a policy. Its heavily push up by religions.
Still we care more than anything when it’s come to our son/daughter. Simple reason may be whatever you are; biologically still specie that has top priority on survival.
So next question why you Love other animals? Cause they compete with each us. Remember you evolve in a way that no animal will able to challenge you anymore. So you’re superior. So nature tricks you to love other species so they survive.

So is the Love between different parties still part of the human evolution? Or it just happened to be? Are we super heroes of this movie?
Or is that nature tricks you. So you think you are superman, Thats ok. But remember you still playing their game.

Friday, June 17, 2011

Folder share with Virtual Box

My requirement is share my Windows7 folder with Fedora-13 on virtual Box. Steps were quite straightforward except wasn’t able to find details in document. Steps were followed after went through few searches.

Initially I shared one folder from virtual Box main view. But wasn’t able to mount using file system vboxsf/vboxfs.

sudo mount -t vboxsf share-vm /home/kasun/window-share/
mount:unknown filesystem type ‘vboxsf’

Open a console window. Just a terminal
sudo yum install system-config-display

sudo system-config-display
sudo yum install gcc kernel kernel-devel kernel-headers

Restart the VM to boot with the newest kernel. Go to the Devices menu and select install Guest additions

Tick the CD/DVD DevicesVBoxguestAdditions.iso. Now you will see the ISO in your home folder.

cd /media/VBOXADDITIONS_3.2.6_63112

VBoxLinuxAdditions-x86.run
sudo mount -t vboxsf share-vm /home/kasun/window-share/

Copy some files to your share-vm folder and check from your VB. So you are installed guest addition to VB. This will also enable you to use “Seamless Mode”, “Full screen” with my Windows7.


Fedora-14

yum -y update kernel
yum -y install kernel-devel kernel-headers dkms gcc gcc-c++

Restart the virtual machine after the updates.
Now, go to Devices and select Install Guest Additions from menu as shown below.

Once ISO file mounted, open the terminal and go inside CD ROM (Under /media)

Run following command as root.

sh VBoxLinuxAdditions-x86.run

Successful installation will return following OK results.
Restart again.

Here we go- It is done. Now it’s enabling with seamless mode, increasing screen and folder sharing.
Installing in Ubuntu 11.4 and virtual-box 4.0.8
Well, this is the easiest.
Go to Devices Installs Guest Additions


Then run the VBoxLinuxAdditions.run inside mounted ISO
./VBoxLinuxAdditions.run

Then restart. You are done. Share you folders now.
sudo mount -t vboxsf share-xp share-ubuntu

Tuesday, June 14, 2011

MySQL special data types – BLOB

BLOB is data type which hold large binary object. MySQL has TINYBLOB, BLOB, MEDIUM BLOB, and LARGEBLOB. These were based on the size of the data that it can hold.
And BLOB is referring to as binary strings or byte strings. On the other hand TEXT treated as character strings. BLOB doesn’t have a character set. Comparisons, Sorting will do on the numeric values of the bytes in the column. Using SQL strict mode value will be truncated to match with maximum column length.
Except few things you can treat BLOB as VARBINARY. For indexes you need to specify prefix length and there is no DEFAULT value for BLOB.

-----------------------------------------------------------------------
mysql> CREATE TABLE test (blob_col BLOB, INDEX(blob_col(10)));
Query OK, 0 rows affected (0.19 sec)
mysql> desc test;
+----------+------+------+-----+---------+-------+
| Field    | Type | Null | Key | Default | Extra |
+----------+------+------+-----+---------+-------+
| blob_col | blob | YES  | MUL | NULL    |       |
+----------+------+------+-----+---------+-------+
1 row in set (0.05 sec)

mysql> CREATE TABLE test2 (blob_col BLOB, INDEX(blob_col));
ERROR 1170 (42000): BLOB/TEXT column 'blob_col' used in key specification without a key length
-----------------------------------------------------------------------
Note – prefix can be up to 1000 bytes long. On innodb it is 767 bytes. Importantly prefix length were calculated in bytes but in CREATE TABLE statements it is use no of characters.
-----------------------------------------------------------------------
mysql> CREATE TABLE test2 (blob_col BLOB, INDEX(blob_col(10000)));
Query OK, 0 rows affected, 1 warning (0.08 sec)

mysql> desc test2;
+----------+------+------+-----+---------+-------+
| Field    | Type | Null | Key | Default | Extra |
+----------+------+------+-----+---------+-------+
| blob_col | blob | YES  | MUL | NULL    |       |
+----------+------+------+-----+---------+-------+
1 row in set (0.00 sec)
-----------------------------------------------------------------------
Below is example of BLOB field usagein java.
Write to Database – insert “fileName” to the MySQL database.
            connection.setAutoCommit(false);
            //I have disable the auto commit
            File file = new File(fileName);
            fis = new FileInputStream(file);
            preparedStatement = connection.prepareStatement(INSERT_PICTURE);
            preparedStatement.setBinaryStream(1, fis, (int) file.length());
            preparedStatement.executeUpdate();
            System.out.println("INSERT Query executed");
            connection.commit();
-----------------------------------------------------------------------
Read from the Database
            Statement stmt = connection.createStatement();
            ResultSet rs = stmt.executeQuery(selectQuery);
            System.out.println("SELET Query executed");
            System.out.println("Going to write the files to the disk");
            System.out.println("---------------------------------");
            while (rs.next()) {
                String fileName = "fileNameOut.jpg";
                File image = new File(fileName);
                fos = new FileOutputStream(image);

                byte[] buffer = new byte[1];
                is = rs.getBinaryStream(1);
                while (is.read(buffer) > 0) {
                    fos.write(buffer);
                }
                System.out.println("File " + fileName + " written to the disk");
-----------------------------------------------------------------------
Table definition is,
CREATE TABLE `picture` (
                  `picture_blob` longblob,
                  `id` int(11) NOT NULL auto_increment,
                  PRIMARY KEY  (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1
-----------------------------------------------------------------------
It’s better to have good understand about max_allowed_packet parameter when working with BLOB columns. If the client program encounter “Packet too large” or “Lost connection to MySQL server during query” better check this property. And may result in strange response specially when deal with bigger BLOB columns. Keep in mind that BLOB was larger than 100MB, and then MySQL need 3 times the size of memory allocated for BLOB processing.
mysql> show variables like "max_allowed_packet";
+--------------------+---------+
| Variable_name      | Value   |
+--------------------+---------+
| max_allowed_packet | 1048576 |
+--------------------+---------+
TINYBLOB – 255bytes
BLOB – 65535bytes
MEDIUMBLOB – 16777215bytes
LONGBLOB – 4GB