Tuesday, January 30, 2007

My second child

His name is Lê Hoàng, he is now more than three year old and he loves car toy.

Do 'nt criticize the customer

Today I did very bad thing. I did criticize our customer for something, that I think they should not do. The tone I used may cause a problem in our working relationship. Rethinking about it, I recognized that there are many better options with the same effect than criticizing. People do care about tone and the way you express your message. With the customer, we should rather propose than criticize, use more informal and less formal way. With our staff, we should give more recommendation and less command.

My first job as programmer

When people are getting older, they tend to lost the past memory. I am not an exception. That is a reason (just to keep the memory) why I want write about my past professional experiences. My career has started quite early in 1991, when I was in the second year at Mathematic and Physic Faculty of Charles University in Prague. At that time a friend of my recommended me a part time work for Metasoft, a software company doing customized software for small enterprises. My task is to customize a application software that will support operation of an accommondation agency. The propgram is pretty simple, the agency has a list of apartments, house and vila for renting. The question, they are intereted is if some houses, apartments or vila of requested capacity are available for a particular period. The program has been writen in Clipper programing environment (simmilar foxpro) on MS DOS.

Sunday, January 28, 2007

Ruby plugin for IntellijIDEA

My favorite IDE, IntellijIDEA has finally released workable ruby plugin. I hope that missing features as code completion and refactoring will be added. This is first post, I has uploaded a picture. After playing with the ruby plugin, I have discovered that code certain completion works when using key combination ctl+alt+shift+space.

Saturday, January 27, 2007

Variable-length argument list

Ruby allows us to define a method with variable-length argument list by placing asterisk before array argument. When we call this method, arguments are placed as normal separated by colon but inside the method we got an array of arguments.
def varargs(*args)
  args.each {|arg| puts arg}
end

varargs()                # 
varargs('arg1')          # arg1
varargs('arg1', 'arg2')  # arg1 \n arg2

We can also do reversely, which mean to pass an array as parameter when calling a method and expand array inside the method.

def one(arg)
  puts "one argument: #{arg}"
end

def two(arg1, arg2)
  puts "two arguments: #{arg1}, #{arg2}"
end

def three(arg1, arg2, arg3)
  puts "three arguments: #{arg1}, #{arg2}, #{arg3}"
end

def call(method,*args)
  send(method,*args)  
end

call(:one,'1')                  # one argument: 1
call(:two,'1', '2')             # two arguments: 1,2
call(:three,'1', '2', '3')        # three arguments: 1,2,3

Sunday, January 21, 2007

Câu lạc bộ những người bạn của CSE

Trong một cuộc nói chuyện của Tôi với Anh Nguyễn Việt Bắc, anh Bắc bảo Tôi đại loại như thế này "đi đâu cũng gặp người trước từng làm CSE, mấy hôm trước gặp mấy cậu làm FPT, hỏi câu trước, câu sau hóa ra trước làm CSE". Tôi nảy ra ý định tạo 1 trang web liệt kê danh sách các nhân viên/cộng tác viên từng hoặc đang làm việc, thực tập tại CSE, với mục đích ghi nhận sự phát triển và thành đạt của họ trong xã hội, chia sẻ kinh nghiệm trong công việc, cuộc sống cũng như các cơ hội hợp tác. Hy vọng ý tưởng này sẽ được hưởng ứng, nếu không thì ai đó cũng nên tạo 1 trang web về những người ghét của CSE chăng ? Đây là blog đầu tiên tôi thử viết bằng tiếng Việt. Nó cũng không khó như Tôi tưởng, chỉ cần Windows OS, Unikey và Firefox. Khi không có điều kiện kết nối Windows trực tiếp vào Internet, bạn Tôi Anh Khôi, nghĩ ra cách, trước tiên viết tiếng việt trên Windows bằng UltraEdit, lưu dưới dạng UTF8, upload file vừa viết lên Unix, trên Unix mở file nói trên bằng firefox, copy nội dung, paste vào blog window khi post. Mới nhìn có vẻ rối rắm nhưng khi làm cũng khá đơn giản.

Saturday, January 20, 2007

Kick off your software project as soon as possible

Frederick Brooks in The Mythical Man-Month said that "The bearing of a child takes nine months, no matter how many women are assigned. Many software tasks have this characteristic because of the sequential nature of debugging". The implication is in order to meet schedule, we should kick off a software project as soon as possible (perhap before a contract is signed) and within the project we should start as many tasks as possible and at earliest possible time.

Sunday, January 7, 2007

Ruby singleton class

In ruby world singleton class is term used frequently to describe something that is in java world called anonymous class. The term is sometime very confusing. I have seen this technique being used to extend class's behavior (as instance of Class). Suppose that we need to define a class instance variable the variable associated with the class (different from class variable, which is global variable)
class Foo
end
class Foo
  class << self
    attr_accessor :instances
  end
end
the equivalent variant of above code is
class Foo
end
class_foo = Foo
class << class_foo
    attr_accessor :instances
end
now do some test
Foo.instances =[] #=>[]
Foo.instance_variables #=>[@instances]
Foo.class_variables #=>[]
Foo.instances << Foo.new #=> [#<Foo:0x8241cbc>]
class Foo
  @@total = 0
end
Foo.class_variables #=>["@@total"]
The great tutorial about ruby singleton class can be found here

JRuby Going Camping Tutorial

Blog application does not work as per instructions described in JRuby Going Camping Tutorial. There are two reasons 1)latest JRuby version 0.9.2 probaly has bugs and 2)latest vesrion Camping 1.5 use un-usual ruby feature that is un-supported in JRuby. To make it work we should use JRuby version 0.9.1 and Camping version 1.4.2. The installation process for MS Windows is below 1. download,install JRuby version 0.9.1 and set JRUBY_HOME to installed directory e.g.
set JRUBY_HOME=d:\jruby-0.9.1
2. download and install MySQL into e.g.
c:\Program Files\MySQL\
3. download install MySQL JDBC and set CLASSPATH to MySQL JDBC driver e.g.
set CLASSPATH=c:\Program Files\MySQL\MySQL Server 
5.0\jdbc\mysql-connector-java-5.0.4-bin.jar
3. install camping version 1.4.2
%JRUBY_HOME%\bin\gem.bat install camping --version="1.4.2" 
--no-ri --no-rdoc --include-dependencies
4. install ActiveRecord-JDBC
%JRUBY_HOME%\bin\gem.bat install ActiveRecord-JDBC 
--no-ri --no-rdoc --include-dependencies
5. download file blog.rb from here into e.g.
d:\rubyapp\blog\
6. start mysql database manager
cd C:\Program Files\MySQL\MySQL Server 5.0\bin
mysqld.exe --console 
7. create blog database and blog user in mysql database
cd c:\Program Files\MySQL\MySQL Server 5.0\bin
mysqladmin.exe -u root create blog
mysql -u root
mysql>create user blog identified by 'blog';
mysql>grant all on blog.* to blog;
mysql>exit
mysql.exe --user=blog --password=blog -D blog
mysql>show tables
mysql>exit
8. run the blog application
d:\rubyapp\blog>%JRUBY_HOME%\bin\jruby 
%JRUBY_HOME%\bin\camping blog.rb

Saturday, January 6, 2007

Enterprise Rails

I have found two interesting documents that describe some experiences of using ruby on rails in a real enterprise project Rails Enterprise Ready from Jay Fields Rails for Enterprise from Rick Bradley and Charles Johnson

Managers vs. Leaders

John Kotter in "What Leaders Really Do." draws a sharp distinction between managers and leaders as follow Managers - Cope with Complexity: Plan and Budget, Organize and Staff, Track and Control Leaders - Cope with Change:Set Direction, Align People, Enable Motivation

Friday, January 5, 2007

Ruby's RI documentation

Ruby's RI program recognize '::' as class method and '#' or '.' as instance method File::dirname means dirname is class method of class File File#stat means stat is instance method of class File. So to get document of class method dirname of the class File, we type
huy@huy-desktop:~/support$ri File::dirname
we will get something like that
---------------------------------------------------------- File::dirname
     File.dirname(file_name ) -> dir_name
------------------------------------------------------------------------
     Returns all components of the filename given in _file_name_ except
     the last one. The filename must be formed using forward slashes
     (``+/+'') regardless of the separator used on the local file
     system.

        File.dirname("/home/gumby/work/ruby.rb")   #=> "/home/gumby/work"
To to get document of instance method stat of the class File, we type
huy@huy-desktop:~/support$ri File#stat
or other way is
huy@huy-desktop:~/support$ri File.stat
the result then is
------------------------------------------------------------- File#lstat
     file.lstat   =>  stat
------------------------------------------------------------------------
     Same as +IO#stat+, but does not follow the last symbolic link.
     Instead, reports on the link itself.

        File.symlink("testfile", "link2test")   #=> 0
        File.stat("testfile").size              #=> 66
        f = File.new("link2test")
        f.lstat.size                            #=> 8
        f.stat.size                             #=> 66

Wednesday, January 3, 2007

dos2unix

If your shell script looks well but does not work on linux machine, it probaly contains ^M at the end of each line because it may be created or modified using a dos/windows editor. To fix this problem run
dos2unix
command, which is OS/MAC to UNIX text file format converter available on linux.