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.

Tuesday, June 24, 2008

Going back to Fedora Core

My recent Fedora Core 9 can be said successful. I still like Gentoo so much. But, in the work place, running gentoo may risk me to stay longer in the office. My choice of alternative is "Fedora Core 9".
I began this with Ubuntu 7.04 which was the left over from the previous. And switched to Kubuntu 8.04 with KDE4 three or four months later. Disappointed so much and tried Fedora Core 9. Thought about Open Suse, but FC was the next.

I tried Fedora Core just once about two years ago for a couple months. I guess it was FC6 or FC7. I switched to Gentoo when RedHat 9 became Fedora Core. So basically, I left RedHat world long time. I don't even remember how it was.

In short, Fedora Core changed a lot from where I stopped using. The biggest advantage of FC9 is very considerate default. Different from Ubuntu policy (literally enabling everything regardless of system resource for ease of use), FC focused more on lower level stability such as kernel API compatibility across the versions. Hibernate works very nice. Good for laptop. So, in kernel level, Fedora Core opens flexibility more, and it is stable more.
But don't get wrong with X11 crashes. That's not due to unstable kernel. That's because the gap between distro's open end and user failure to provide suitable driver. I believe this has been and will be the endless fight for Linux kernel and X11 driver.

Friday, June 13, 2008

KDE4: Gentoo, Kubuntu, and Fedora Core 9

I am okay with KDE4. There are still some quarks in KDE4, but generally I like how it is now. I can't explain detail of KDE4 in each distribution. In short, I dropped Kubuntu for KDE4. I agree that Ubuntu linux is doing a great work, but with KDE4, they need to catch up.

With Gentoo, things are smooth. Sure!! I pay huge compile time for this. In my work place, things are moving in fast phase. So, having gentoo isn't quite suitable. I chose Kubuntu when I had a chance to refresh my work desktop. Kubuntu KDE4 was pretty disappointing. One of most annoying example is that I couldn't move widgets in panel. Right click did not even offer "Move" option which I remembered it was there on Gentoo. So, I had to find another time to refresh my desktop. My desktop didn't find time to kick out Kubuntu, yet. I could flush and rebuild my laptop during the last weekend with Fedora Core 9. Still some issues, but much better than Kubuntu.

When I get a chance, I will compare rpm vs. deb. In short, deb is more convinent, but rpm is more flexible. dpkg(deb package) mainly uses package based dependancy and extends out to file based integrity check if it needs to. RPM, on the other hand, takes file based, but yum wraps these into package level and group level ( collection of packages ).