Thursday, July 31, 2008

Shell, recall last argument

This is also very good shell feature, but many times I failed to use. I will encourage myself by posting this. Here we go.

Suppose I created a temp dir, and move to it.

$ pushd .
$ mkdir /tmp/lalala
$ cd /tmp/lalala

The last command can be easily made by, recall by arrow-up, ctrl-A, remove 'mkdir', and type cd. Not bad, but bash has better option.

$ pushd .
$ mkdir /tmp/lalala
$ cd !$

Confused or frowned for another cryptic symbol memorization? That was my first impression. But, actually not. It is very elegant usage.

! is history recall. As we usually do "$ !510" - recall command number 510 in history.
$ is regex. End of line. Then, we can think usage of '!^'.

$ cat a b c d e
$ cat !^
cat a

So, each run will remember previous argv vector, and we can call by placer(^,$).
Another nice feature. I am interested in middle one, like c in previous example.

$ cat a b c d e
$ cat !:3
cat c

Not bad. Here is another interesting one.

$ cat a b c d e
$ cat !:1-
cat a b c d
$ cat !:1-
cat a b c

Popping every argument..
In my opinion, this is a gift from bash for who think before hand. Someone who lavishes meaningless 'ls', like me, wouldn't get benefit. :)

Tuesday, July 15, 2008

Transaction in MySQL

Personally, I use PostgreSQL. PostgreSQL is the most advanced open-source database. I am bravely saying that it is more advanced than MySQL is at the time of this writing. However, my department is running MySQL 5.0. I feel lucky that it is not MySQL 4.1. I have to migrate my current works stored in my desktop in postgresql to mysql. It is anticipated from the beginning, but I just didn't prepare.
The migration will not be hard, though. It is easy to convert postgres dump to mysql dump for import. I searched my favorite function, Transaction. To make transaction work, InnoDB must be used, which implies mysql should be compiled with support of InnoDB. Mostly it is true.
Here is one additional change to apply for postgres dump. Any create table statement should have something like this.

create table table_name ( ...description... ) TYPE=InnoDB;

Simple, but just wonder why InnoDB is not a default type, and who wants some table type without transaction support. Transaction on mysql is relatively new feature, on the other hand, PostgreSQL already supported long time ago. Oh well.. It is what it is. We use mysql, so be it.