Thursday, July 31, 2008

Notes from

From the book <Elements of Java Style>

62. Describe why the code is doing what it does, not what the code is doing.

70. Define subclasses so they may be used anywhere their superclasses may be used.
The Liskov Substitution Principle
The Open-Closed Principle

100. Use lazy initialization
class PersonalFinance {
private LoanRateCalculator loan = null;
public LoanRateCalculator getLoan(){
if (this.loan == null) {
this.loan = new LoanRateCalculator();
}
return this.loan;
}
}

Packaging Conventions
104.Place types that are commonly used, changed, and released together, or
mutually dependent on each other, into the same package.
- The Common Reuse Principle
- The Common Closure Principle
- The Resue/Release Equivalence Principle
- The Acyclic Dependencies Principle

105. Isolate volatile classes and interfaces in separate packages.
volatile := something likely to change

Monday, July 28, 2008

Switching Control and Caps Lock on Windows(For Emacs)

I didn't know I can do this till my colleague told me when he saw I'm playing Emacs. "Your small figure will probably feel bad after you doing too much in Emacs", he said, "Try to switch the Control and Caps Lock." Sounds interesting! I google the solution and it makes life easier in Emacs. But not very convenient out of Emacs.

key points: add a new field to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout with name : Scancode Map
and type : Binary Value and value : 00000000 00000000 03000000 3A001D00 1D003A00 00000000

details

;;; Updated
use autohotkey turns out to be more convenient. (swap control with Win key)
LWin::Control
LControl::LWin

Saturday, July 26, 2008

Olympics 2008, Welcome to Beijing




北京欢迎你
词:林夕   曲:小柯

迎接另一个晨曦,带来全新空气
气息改变情味不变,茶香飘满情谊
我家大门常打开,开放怀抱等你
拥抱过就有了默契,你会爱上这里
不管远近都是客人请不用客气
相约好了在一起,我们欢迎你
我家种着万年青,开放每段传奇
为传统的土壤播种,为你留下回忆
陌生熟悉都是客人请不用拘礼
第几次来没关系,有太多话题
北京欢迎你,为你开天辟地
流动中的魅力充满着朝气
北京欢迎你,在太阳下分享呼吸
在黄土地刷新成绩
我家大门常打开,开怀容纳天地
岁月绽放青春笑容,迎接这个日期
天大地大都是朋友请不用客气
画意诗情带笑意,只为等待你
北京欢迎你 像音乐感动你
让我们都加油去超越自己
北京欢迎你,有梦想谁都了不起
有勇气就会有奇迹
北京欢迎你,为你开天辟地
流动中的魅力充满着朝气
北京欢迎你,在太阳下分享呼吸
在黄土地刷新成绩
北京欢迎你,像音乐感动你
让我们都加油去超越自己
北京欢迎你,有梦想谁都了不起
有勇气就会有奇迹
我家大门常打开 开放怀抱等你
拥抱过就有了默契,你会爱上这里
不管远近都是客人请不用客气
相约好了在一起,我们欢迎你
北京欢迎你 为你开天辟地
流动中的魅力充满着朝气
北京欢迎你,在太阳下分享呼吸
在黄土地刷新成绩
我家大门常打开 开怀容纳天地
岁月绽放青春笑容 迎接这个日期
天大地大都是朋友请不用客气
画意诗情带笑意,只为等待你许茹芸
北京欢迎你,像音乐感动你
让我们都加油去超越自己游鸿明
北京欢迎你,有梦想谁都了不起
有勇气就会有奇迹金海心
北京欢迎你,为你开天辟地
流动中的魅力充满着朝气
北京欢迎你,在太阳下分享呼吸
在黄土地刷新成绩
北京欢迎你,像音乐感动你
让我们都加油去超越自己
北京欢迎你,有梦想谁都了不起
有勇气就会有奇迹付丽珊
北京欢迎你,有梦想谁都了不起
有勇气就会有奇迹
北京欢迎你 有梦想谁都了不起
有勇气就会有奇迹

Tuesday, July 22, 2008

Vim Commands

Select the match in the complete list
CTRL-N / CTRL-P

Differs from 'j'/'k' when lines wrap
map gk
map gj

Option for 'smart search'
set ignorecase smartcase

\C := case sensitive
\c := case insensitive

Offsets (when searching)
/default/2
/const/b+2
/const/e+1

Sunday, July 20, 2008

Install Subversion in Ubuntu Server

https://help.ubuntu.com/8.04/serverguide/C/subversion.html

Enable/Disable Apache Mod:
  a2enmod/a2dismod


"Instance" an Interface (Java)

It looks like "instance" an Interface...

import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class InterestingTests {

    @Test
    public void TestConstructInterface() {
        TurnstileController controller = new TurnstileController() {
            private boolean lockState = false;
            private boolean unlockState = false;

            public void lock() {
                lockState = true;
            }

            public void unlock() {
                unlockState = true;
            }

            public boolean isLockState() {
                return lockState;
            }

            public boolean isUnlockState() {
                return unlockState;
            }
        };
        controller.lock();
        assertTrue(controller.isLockState());
        controller.unlock();
        assertTrue(controller.isUnlockState());
    }

    private interface TurnstileController {
        public void lock();
        public void unlock();
        public boolean isLockState();
        public boolean isUnlockState();
    };

}

Thursday, July 17, 2008

My Network Config of (Sun)VirtualBox

Host: Windows XP
Guest: ubuntu 8.04 Server

VirtualBox Network Config:



ubuntu network config:

Why eth1 has address 169.254.4.130 ?
Actually it depends.
Start the VirtualBox with two network adapters and check all IP address in your host.
You'll see the IP address of the adapter for VirtualBox, then set the eth1 IP address accordingly.

Wednesday, July 16, 2008

Install SVN as Windows Service

sc create svn binpath= "\"C:\svn-win32-1.4.4\bin\svnserve.exe\" --service -r C:\Workspace\SVN\repos" displayname= "Subversion Server" depend= Tcpip start= auto

net start svn

Something in Generic Programming

-- difference between raw type list and wildcard type list
You can put any element into a collection with a raw type, easily corrupting the collections type invariant. you cant put any element(other than null) into a Collection<?>. Attempting to do so will generate a compile-time error message.

-- parametrized types are invariant.
In other words, for any two distinct types Type1 and Type2, List<Type1> is either a subtype nor a supertype of List<Type2>.

test class in java

Friday, July 11, 2008

Simple Sample of Regular Expression in Python

import re

def read_file():
file_name = 'merge.log'
file = open(file_name, 'r')
file_content = file.read()
patterns = re.compile(r'(r\d{5}\s\|\scn-cma)(.*(?!cn-cma).*)(r\d{5}\s\|\s(?!cn-cma))', re.DOTALL)
results = patterns.search(file_content)
#results = patterns.match(file_content)
print dir(results)
if results :
results = results.groups()
print results[0]
def display(x):
print '$' * 50, '\n', x
#[ display(x) for x in results ]
file.close()

merge.log

Monday, July 07, 2008

JSE5, New Language Features Introduce by Joshua Bloch

(For me), it's a good overview introduce of JSE5 new feature.
http://java.sun.com/features/2003/05/bloch_qa.html
Any other advance articles?

Saturday, July 05, 2008

Clean Up Ubuntu Grub Menu after Updates

change the file: /boot/grub/menu.lst

details here

Wednesday, July 02, 2008

Links for Blackberry

gmail : http://gmail.com/app
miniopera : http://mini.opera.com

Update System
0. prerequisites
1. rename/rm Vendor.xml in "program files"/"Common Files"/"Research In Motion"/AppLoader
2. loader.exe /nojvm will start the application installation.

Tuesday, July 01, 2008

Lexically Function Scrop

The following definition help to understand why need closure implement in JavaScript.

Functions in JavaScript are lexically rather than dynamically scoped. This means that they run in the scope in which they are defined, not the scope from which they are executed.