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.
Thursday, September 25, 2008
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.
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)".
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 :)
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. :)
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.
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.
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.
Subscribe to:
Posts (Atom)
