Thursday, October 2, 2008

KDE4.1 on Fedora Core 9

It is pretty busy days. I can't find time for a technical post. But, I want to mention that I am happy with new KDE 4.1 update with FC9.
I generally don't follow updating my work desktop. Recently, I did it and required rebooting for kernel 2.6.23 update. After logging in, I found KDE is updated to 4.1. It had enhanced look, and I updated my nvidia card from livna, and OpenGL based theme worked. It looks much cooler.

Thursday, September 25, 2008

Good excuses NOT to use version control

Recent post from stackoverflow.com made me laugh. 'No version control' execuse. I have to reveal my stupid experience for this. It was my first year in career. I developed a replacement of production data feeder. It had a significant improvement, and I was sure it will make other people's life easier. But, suddenly, an accident happened. At that time, neither did I version control, nor backed up a source. The fact that first year professional doesn't know version control system should not be a good execuse, but I didn't know that.

My intention was to clean up test data like this:

$ rm -fr $PRJ_HOME/data

But, actual command was issued like this:

$ rm -fr $PRJ_HOME/ data

With just an extra space, I screw up the $PRJ_HOME. Fortunately, I had spare partition with enough disk space. I dumped /dev/sdaN to a single file. It was too big to open in vim, so chopped in pieces, and went through ugly binary format searching for my piece of code. After recovering all of my sources, I learned CVS and spent a week to learn to setup and manage CVS. Now it became Subversion.

There is no execuse, no good reason not to use VCS(Version Control System).
I can think of one. Temporary project only, which will create noisy commits on main VCS. However, even though the project is temporary, building on my own subversion tree locally and stuff into it before going to main VCS is not a bad idea.

Tuesday, September 23, 2008

Emacs, company-mode

I ran into a company-mode. This is a new completion style, and I like it. I recommend to watch its demo screencast.

company-expand-common function will take your TAB key away. I rebound it to [C-tab].
Very useful and good looking.

Monday, September 22, 2008

Chaining condition

I was reading a python code and discovered this useful feature.

if LOWER < x < UPPER

do_something


I have expressed this "if LOWER < x and x < UPPER" until I discovered chaining expression like this.
Perl and Ruby didn't accept chaining expression. C and C++ will not work because, (let's see the parsing)

1. C replaces expression with result of evaluation. Therefore, '1 < x < 10' expression will be '( (1 < x) < 10 )' and it will be evaluated to non-zero for any x.

2. C++ also replaces expression, but it knows boolean (true/false). Therefore, '1 < x < 10' expression will be either 'true < 10' or 'false < 10'. Since C++ is strong-typed language, this expression requires support of additional function like "boolean operator<(bool&, int&)". If it is supported, it should also support "boolean operator<(int&, bool&)". Now, int is not the only comparable. Beginning with float and double, signed/unsigned char, etc. It gets ugly very easily. Another approach will be replace true to (int)1 and false to (int)0 so that it can leverage existing framework. Anyway, end result is not related to the result of '1 < x < 10'

3. Due to this nature, supporting this expression in dynamic language isn't simple problem. For example of '( (1 < x) < 10)' case, inner expr can be any type based on 'what x is', the interpreter should be able to handle this fine.

Anyway, "1 < x < 10" is more elegant than " (1 < x) and (x < 10)".

Sunday, August 10, 2008

Howto install Emacs snapshot (v23.x)

It's another 3:00am.
I am an emacs advocate. I used vim enough, and still use vim for certain circumstances. However, I use emacs mainly for development.
Stable version of Emacs is v22. v23 is development tree. There is one big advantage compiling emacs v23. "xft" support. So, if you want to use 'Consolas' font in emacs, using v23 will simplify a lot. Configure switch is:

# ./configure --with-x-toolkit=gtk --enable-font-backend --with-xft \
--prefix=/usr/local/emacs-snapshot --with-tiff=no

It requires gtk.h. So, you need gtk2-devel package for Fedora Core. (Other distro like Ubuntu should not be a problem to find equivalent package. ) Then,

# make bootstrap
# make install

Then, add following line to use Consolas font.
(set-default-font "Consolas-11")

Simple enough. :)

Now, for people who didn't read README, like me, here is some quarks.
If you happened to execute 'make' before 'make bootstrap', you may run into a problem. (might be different problems, depending on revision). In my case, I cvs up and just issued "make" assuming that previous config information would be transparent. Not really. The top most error was:

"faces.el:29:13:Error: Symbol's function definition is void: cl-compile-time-init"

That line is (require 'cl). If you open Makefile, you will see that "make" and "make bootstrap" targets are different. In this case, somehow cl(common lisp) package was not ready when faces.el was compiling. According to Makefile, make bootstrap will 'force clean and bootstrap from a clean state' My assumption was partially right, but Makefile case did not cover my case, yet. Went through several seg-fault and compiled on my own and made it to work.

I believe that the easiest way was to "make clean" and start from scratch :)

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.