Monday, February 28, 2011

Linux Usage: solution for installing debian deb in ubuntu

Sometimes, we will download debian deb and installed it under ubuntu. If you are lucky, this will be okay and the installation will go normally. However, it may report errors like:
The package XYZ needs to be reinstalled, but I can’t find an archive for it.

XYX is the name of your deb package.

At that time, you can remove the wrong package using the following command in terminal:
$ sudo dpkg –remove –force-remove-reinstreq XYZ

Sunday, February 27, 2011

Ruby on Rails: Missing generate script under script folder

I am learning Ruby on Rails as I need it to finish my project quickly. I just read some books and see how Rails can help me do things with shorter time. In a chapter, it is a practical and I try to follow also. I create a project with rake command and I can do that also. Good~~ Then, next step is to use generate script to generate model. The command is
$ ruby script/generate ...

I check that there is only one file under script folder which is rails. After I check from Google, I found that all scripts are removed in Rails 3. You should use
$ rails generate
or
$ rails g
instead of script/generate,
$ rails server
or
$ rails s
instead of script/server and so on.

Saturday, February 26, 2011

Android App: ECDroid 安卓英漢字典

係Android,大多字典都是需要利用online resource,所以手機必須有上網服務先可以使用,例如google translate..但對於一些沒有申請流動上網,只是有家中wifi,那就是很不方便!但是,其實Android上地有一些離線的字典軟件,例如colordict,它採用了stardict的字典檔,所以字庫龐大..但是它的缺點是格式不太整齊,這個原因是stardict本身的字典褲只是純文字,所以顯示出來也不太美觀,如果不理外觀,用來作字典是可以的

於是找找其他字典,發現有一個新出,由香港人開發的字典,但它的格式很整齊,也很美觀,速度也不錯,更適合離線使用,它就是ECDroid 安卓英漢字典。它的網址是http://ecdroid.no-ip.org 它的字庫高達 110,000 個,而且有離線發音功能,雖然是Android 的TTS,但也足夠有餘。作者還提供不同的安裝包,方便不同程度的使用者使用。唯一美中不足是不能在Market 下載。原因是作者想看看巿場環境,如果大家覺得好用滿意,請支持一下。但ECDroid 是我目前覺得最好用的一個字典軟件



 

Friday, February 25, 2011

Vim Usage: using clipboard

Vim is a very strong and powerful text processing software. People in Linux should hear this name although they may not know how to use it. However, when people is using vim, they may face a problem that is easy and common. But it is a strange question also, this is about clipboard of vim.

Let's do a simple experiment. Launch a browser and copy the text from a web page. Then, in vim, use "p" to paste the content as usual. Huh...you discover, there is nothing pasted here. Hoho...the reason is vim contains multiple clipboards and they are independent to system clipboard. Thus, when you copy the text from browser, it will save the content in the system clipboard. When you use "p" to paste the content in vim, vim is reading vim's clipboard.


Then, how to easy to copy and paste the content from system clipboard? Simple, you can use short-cut command "shift - insert" to achieve it although you need to move your hand far away. If you are using GVim, you can also use middle button. Okay, it is simple and now you learn the basic of vim clipboard.   

As you said before, vim contains multiple clipboards. The objective for this is for user to do some complicated text processing. Now, let's talk about ":reg". When you type this command in command mode, you can see a list of output which is familiar to you. Right, they are the content you copied. You can see that vim contains many clipboard and it is indexed by characters, numbers and symbols. All the clipboard's name starts with '"'. Wow~ can you see the content indexed by '"+'. This store the content that you have just copied from browser. You are right. '"+' is System clipboard.

At this time, you should be able to view content of all clipboards. Now, we are going to paste content from specific clipboard. We all know that "p" is the command for pasting. But if we need to paste from certain clipboard, "p" is not enough. To specify a clipboard, we need to tell vim explicitly using '"[clipboard index]'. For example, we want to paste the content from system clipboard, we can press '"+p' in command mode that means change to '"+' clipboard (system clipboard) and then paste. Now, you can see you pasted the content from the web page you copied.

Now, you know how to paste content from certain clipboard. Then how to copy content to certain clipboard, for smart user, I think you know the answer now. The step is "1) specify a clipboard" and then "2) copy the content". You know how to specify the clipboard. To copy content in vim, use "y". For example, you want to copy the content to system clipboard so that you can paste the content to other application. First, use '"+yy' to change the clipboard to system clipboard and then copy the line (for more usage of yank[y], please read in the help ":help y"). Then you can paste the content in other application or you can check if it is success by ":reg" command.

Remarks: Some people tell me that it cannot be used. You need to check whether your vim compiled with clipboard support. To check it, use command in terminal
$ vim --version
If you can find +clipboard or +xterm_clipboard, you can use it properly. Otherwise, you need to compile it again with clipboard support. In ubuntu, you can use
$ sudo apt-get install vim-gnome
to obtain a vim that support these two functions

Thursday, February 24, 2011

Linux Usage: batch unzip all rar files

If you have a bunch of rar files under Linux and you need unrar all of them. This is quite a trouble. First of all, in the past Linux doesn't have rar tools. Fortunately, this is available right now so that we can process rar under Linux.

Now, the problem is how to handle lots of rar files. One way is to using Xwindows environment. You may use your mouse to select all files and right click uncompress. The other way is to use command:
$ for f in `ls --color=none`; do rar x $f; done

It loops through all files under current directory and pass it to rar program to extract the rar file. rar is the program name, x is the parameter meaning that this is a extraction and $f is the file name

Wednesday, February 23, 2011

Vim Usage: viminfo

Yesterday, I talked about the session in vim which is used to store the layout, tabs, files opened records. How about mapping, abbreviate, mark and options, history, register, recent search records?

All of these values are stored in viminfo. To create a viminfo file manually, use ":wviminfo [filename]". In fact, before exiting vim, vim will automatically create a .viminfo file under home directory. To use ":wviminfo" is to create a viminfo explicitly. It is because .viminfo will be updated every vim exits. Who know what you do after using vim. Thus, it is better to create a viminfo by yourself such that the viminfo file you created will not be changed no matter how you use vim later (unless you save the viminfo file with same file name). Which ":wviminfo" will save what values and numbers of records depends on "viminfo" option setting. You can check it by ":set viminfo". If you want to edit it, you can read the manual by using ":help viminfo".

Now, to restore viminfo, just use ":rviminfo [filename]" command. Then, you can restore all values and registers. Thus, you may need to use following command if you need to work on a project to restore the environment with viminfo.

:wviminfo project1.viminfo       " create a viminfo file
:qa                                        " quit vim

Enter vim again, you will see a blank windows. Then, restore the environment from viminfo

:rviminfo project1.viminfo        " read viminfo file

Now, you can get back the vim environment you exit before. If you want to restore the layout and tabs, please read my previous post about using session.

    Tuesday, February 22, 2011

    Vim Usage: use session

    Many software has a function that it will restart the last status when you launch the program again. For example, eclipse will restore the layout, perspective, files opened when you launch it again.

    Question: Does vim contain this function?
    Answer: Yes for sure, otherwise, there are lots of people complaining it. To archive this function, we need to use session to store the status before you exit and restore it when launching.

    When we are developing a project, this is not a short-period job. If you exit vim and launch it again from scratch, I think you will pull your hair out and want to kill vim immediately as this is a troublesome work!

    Session is a good tool that store windows layout. For example, you may have many tabs and splitting windows. You can store them into session so that when you launch it, you can have such layout again.

    To create a session, you can use ":mksession [filename]".  If filename is omitted, vim will create a file named session.vim. In fact, session is a vim script and you can edit it if you like. You also can view the session file so that you can have better understanding how session works.

    Which value is stored depends on 'sessionoptions'. By default, 'sessionoptions' is set to be "blank,buffers,curdir,folds,help,options,tabpages,winsize". You can check this with ":set sessionoptions" command in vim. That means vim will store current blank windows, buffers, current directory, folding, help windows, current options, tabs and windows size when you make a session file.

    Remark: if you are using windows version vim and you want this session file can be execute under windows and vim, you need to add two more 'sessionoptions'. They are "slash" and "unix". "slash" is to replace back slash with slash and "unix" is to store the line break in unix format (There is some different between dos format and unix format, if you want to know more, you can read my previous post).

    If you don't want to store current directory path, you want to set the current directory is same as location of session file. To do that, you need to modify 'sessionoptions' that to remove "curdir" and add "sesdir". After that, when you load the session file, the location of session will be set to be current working directory. Also, after this setting, all path in the session file will become relative path instead of absolute path.

    Ok, we talked a lot of advantage of using session and how to create a session. How can we use it? The answer is that it is easy, you can use ":source [sessionfile]" to load the session, or you can use in this command in terminal
    $ vim -S [session file]

    Monday, February 21, 2011

    Vim Usage: how to press your ``Esc''

    In vim, how would you press the Esc key to switch from insert mode to command mode? For sure, it is a key that you need to move your hand out of alphabet keys. Some people would slap the key..haha..it sounds a little bit violence. For me, I use my little finger, huh, some people think I have a very big hand or a very long little finger.

    If you have read Vim Tips, you probably know what's going on. In fact, I am pressing cap lock instead of Esc. In Linux, it is convenient to set your key. You can use xmodmap to modify X windows layout. Since I seldom to use Cap lock, and in order to speed up using vim, I swap Esc and Cap lock. To do that, you can create a .Xmodmap with following content under your home directory
    remove Lock = Caps_Lock
    keysym Escape = Caps_Lock
    keysym Caps_Lock = Escape
    add Lock = Caps_Lock

    Then execute
    $ xmodmap ~/.Xmodmap

    Then you will realise that your caps lock become Esc key already. For sure, if you like this mapping, you need to start the script on Gnome start up to take the effect.

    Sunday, February 20, 2011

    Vim Usage: encrypt your text file

    Computer security is a very important issue when the computer is public. File in computer can be easy accessed by other people if you don't protect your file in a serious manner. Vim provides a security function that you can set a password to your file.

    To encrypt a file, you need to start vim with -x parameter. e.g.
    $ vim -x password.txt"

    Vim then will ask you to enter a password for this file. The password will be hidden with stars to prevent from other people seeing your password. Thus, you need to enter the same password again to avoid typo mistakes.

    Now you can edit your file normally as usual. When you save the file, the file will automatically be encrypted.

    When you use vim to open this file, vim will ask you to input the password in order to authentic the editor (you won't need to put -x in the command). You also can use ":edit" command to edit encrypted file.

    If you use other editors such as notepad to view the encrypted file, you should see messy symbols. If you input a wrong password, you also will get error. Vim doesn't provide password verification, every key can open the file, but only correct one will decrypt the file and the decrypted content is meaningful. This method makes it more hard to crack.

    If you want to clear the password, you can use ":set key=" to set the key to be null. Then you save the file, this file will not be encrypted any more. In fact, you can use ":set key=[your password]" to set your key. However, it is bad since every body can see what you typed on the screen. To avoid this problem, you can use ":X" command which is same as -x parameter in vim to ask you input password.

    There is other issue about the security of vim. The encryption of vim is enough to prevent the people want to view your file, but if people was a professional hacker, he can crack your file with using many time. Also, vim will create a swap file when you edit it. This swap file can be viewed by the super user. Thus, we can avoid this by using "-n" to not create swap file for vim. You can use the command to launch vim:

    $ vim -x -n filename.txt

    If you are editing the file, you can use ":setlocal noswapfile" to stop create swap file. However, since there is no swap file, file recovery is difficult to achieve. One way to solve it is to save your file in shorter time. :-)

    Saturday, February 19, 2011

    Vim Usage: generate HTML format source code with syntax hightlight

    In vim, this supports to have syntax highlight which makes the program attractive, at least it is not dull and easy to debug. Sometimes, you may want to publish your code online so people can view your program. One way is to put the source code to web host directly, so people can download your source code and view it in their own favourite editor. The other way is to publish your code in HTML format, thus people can view it anywhere once there is a web browser.

    Vim provides more function on that, it can generate a HTML from your program with syntax highlight. You just need to type the following in command mode:
     ":TOhtml"
    Then, you may need to wait a little bit time which depends on your size of the program. Once it is done, it will generate a html named program_name.html and you can save it by ":w" and publish it if you want. Cool~

    But, if you want to modify the style, you will think it is a trouble. Vim by default won't output using CSS, for example, it uses font tags instead of using style. For formatting, it use pre tags instead of replacing space with   and newline with
    tag. To force vim output using css and not pre, you can set it by ":let html_use_css=1" and ":let html_no_pre=1". If you want to output standard xhtml also, add ":let use_xhtml=1".

    Friday, February 18, 2011

    A quick way to identity which system you are using. 32bits? 64bits?

    To check if your computer is using 32bits or 64bits, it is easy job once you use the following commands. There are many ways to check under Linux, I list some which is easy to remember.

    Method 1:
    $ uname -m 

    Output:
    • i386/i686 = 32bits
    • x86_64 = 64bits
    Method 2:
    $ file /bin/bash

    Output:
    • ELF 32-bit LSB executable, Intel 80386 = 32bits
    • ELF 64-bit LSB executable, x86-64 = 64bits

    Method 3:
    $ getconf LONG_BIT

    Output:
    • 32 = 32bits
    • 64 = 64bits

    Choose your own command which you are easy to remember! Enjoy!

    Vim Usage: add more syntax to support special extension

    Vim is able to detect your programming language in the file you open. The mechanism for vim to do that is to check extension of the file. However, some files are not included by default in vim like .inc. To make vim can correctly detect the syntax with your file extension. You need to set file type explicitly. In command mode, input ":set filetype=php" to tell vim that the current opened file is using php syntax.

    However, it is annoying that you need to type this command whenever you open .inc file. To do that permanently, modify filetype.vim under ~/.vim folder which store all vim settings and plugin for current session user. Then, find "au BufNewFile,BufRead *.php,*.php\d,*.phtml,*.ctp    setf php" which mean for the file with extension *.php, *.phtml and *.ctp, vim will treat them as php syntax. Thus, you just need to add *.inc to this line, that becomes "au BufNewFile,BufRead *.php,*.php\d,*.phtml,*.ctp,*.inc    setf php", save and then reopen .inc file. You can see it is using php syntax now.

    If you have some syntax you want to diy, you can create a syntax file under ~/.vim/syntax folder. Then in filetype.vim add "au BufNewFile,BufRead *.inc    setf inc". Save it and you will use your own inc syntax format for inc extension files. Nice!

    Thursday, February 17, 2011

    Vim Usage: batch comment out in program code

    When doing programming, commenting out some code for debugging is needed in many cases. In fact, most IDE like my favourite java IDE, Eclipse, they include this function already. You can select the lines you need to comment out/undo comment by using their fancy edit tab. In vim, how can you do that?

    There are so many solutions in vim.

    Method 1: 
    If you are using your own vim and you need to do commenting out code very often, I suggest you to use vim plugin - comments. The web site includes the installation guide and how to use it. You can check it.

    Method 2:
    You can use block selection mode in vim. To enter block selection mode, press "Ctrl - v". Then, use arrow keys or "h j k l" to move the cursor and select the lines you need to comment out. Then, press "I" which mean insertion at the beginning of line. Depending on your programming language, you can input "//" for C, C++ or java, etc, or "#" for shell script, python, etc. Finally, press "Esc" to escape the insert mode. See...Vim will automatically insert the comment symbol for the lines you selected.

    To uncomment out the lines, use "Ctrl - v" again to enter block selection mode. Highlight all comment symbol, then press "d". All the characters you selected will be deleted. Cool!

    Method 3: 
    Last time you talked about mastering replacing function in Vim. You can use this to comment lines also. (Want to have more detail, please refer to my post)
    To comment lines, ":[startline], [endline]s/^/[comment symbols]/g"
    This means replace "^" with comment symbols from startline to endline globally. What "^" means is the beginning of line. This is the same meaning in Regex (Regex is very useful in vim, and in *nix system).
    To uncomment lines,  ":[startline], [endline]s/^[comment symbols]//g"
    This means replace comment symbols which are located at the beginning of line to empty. In order words, to delete all comment symbols which are located at the beginning of line.
    Example (remember to use appropriate seperator):
    • add // within line 10 and line 20: ":10,20s#^#//#g"
    • uncomment within line 10 and line 20: ":10,20s#^//##g"
    • add # within line 10 and line 20: ":10,20s/^/#/g"
    • uncomment within line 10 and line 20: ":10,20s/^#//g"
    In fact, the best way is to use "+" as separator as there is no programming language use "+" as separator in my knowledge.
    • add // within line 10 and line 20: ":10,20s+^+//+g"
    • uncomment within line 10 and line 20: ":10,20s+^//++g"
    • add # within line 10 and line 20: ":10,20s+^+#+g"
    • uncomment within line 10 and line 20: ":10,20s+^#++g"

    Wednesday, February 16, 2011

    Vim Usage: mastering the replace function

    Replacing text is a daily using for text editing. For most visual editor, you probably can click edit->replace to achieve the goal. Right now, it maybe a hard time that you have to do it in vim. What you need to remember is ":s" which stands for substitution. To use it, you need to provide the search text and replace text like ":s/abc/123". When you press enter, you may not be satisfied. This command means to substitute first occurred "abc" with "123" in current line. If you want to do it in whole line, you need to put one more parameter (/g). Thus the command is ":s/abc/123/g" which is substituting "abc" with "123" globally within the line.

    In fact, vim provides lots of flexibility for users. You can combine this with range. That means you can replace text within a range of lines. You can type ":n, $s/abc/123" which replace the first occurrence of "abc" to "123" for each line in the range. If you need to replace all occurrence between line n and the end of file, you should use ":n,$s/abc/123/g" to replace them globally from line n to the end. Remember, "n" is line no, if you want to set the range from current line to the end of file, you can use ".". "." is a very useful key in vim.

    Now, you may want to replace within whole file. You may think you can use ":1,$s/abc/123" to specify replace from line 1 to end line. However, you can use other one if you like to save some key strokes. ":%s/abc/123" is to replace first occurred "abc" with "123" in every line. ":%s/abc/123/g" is to replace all "abc" with "123" in every line. (Actually, if you want, you may want to remember two more which do the same action: ":g/abc/s//123" and ":g/abc/s//123/g")

    Last problem, what if I want to replace the text with "/"? Should I use ":s/abc//123//" to replace "abc/" with "123/"? However, "/" in this command is used for separator and vim can't interpret this command definitely. Luckily, vim doesn't force you to use "/" with separator. You can use "#" or "+".  For example, to replace "/home/user1" with "/home/user2", you can use ":s#/home/user1#/home/user2#g" or ":s+/home/user1+/home/user2+g".

    Conclusion:
    If you just need to find a function which is same as replace function in usual editors, ":%s/target/replace/g" is enough for you.

    Summary:
    • ":s/abc/123" - replace first occurred "abc" with "123" in current line
    • ":s/abc/123/g" - replace all "abc" with "123" in current line
    • ":n, $s/abc/123" - replace first occurred "abc" with "123" from line n to end of file
    • ":n, $s/abc/123/g" - replace all "abc" with "123" from line n to end of file
    • ":., $s/abc/123/g" - replace all "abc" with "123" from current line to end of file
    • ":%s/abc/123" - replace first occurred "abc" with "123" in every line
    • ":%s/abc/123/g" - replace all "abc" with "123" in every line

    Remark:
    Do you remember that you have introduced two commands to convert dos format file to *nix format? One is using vim to set the encoding and the other one is using dos2unix command. Huh........you actually can do that using replace function in vim. First, what is the different between dos format and *nix format file? The answer is that the new line characters are different in the system. DOS uses (0A0D) to represent the end of line while *nix uses (0A) to represent a new line. Thus, if you are viewing a dos file in, you will see many "^M" in the end of each line which is a extra character for windows to know that which is a new line. [Vice versa, if you are viewing *nix file under windows, you may see whole file concatenated in one line if you are using notepad. The reason is that windows doesn't know it is a time to change to new line without (0D)]

    Now, you know what the problem is and for sure, what you need to do is to delete all "^M" in the document. Thus, please use ":%s/^M//g" in command mode. Be careful, here "^" is not same as shift 6. You need to type: ":%s/[ctrl-v][ctrl-M]//g".

    Tuesday, February 15, 2011

    Vim Usage: Copy and paste multiple lines across different files

    If you use vim, it is better to avoid using mouse. (I think that's good and convenience if you can control your vim without leaving your hand out of keyboard. In fact, I think it is the most important reason to use vim.) However, you may need to copy multiple lines in one document and paste them into same document or other files. Probably, you can use mouse and highlight multiple lines,  then edit->copy. I think this is ok for vim newbie and definitely this will take some times for hand switching from keyboard and mouse. Here is a better way, at least I use this one. (If you have better command, please feel free to give a comment :-) )


    I will use "m" to help me. "m" is used for making a marker. You can use it in your text file. Then, you can jump to any line. In command mode, you press "m + [any letter (a-z)]". It will make a marker with the letter you choose. For example, you can move to line 10 and type "ma" (I usually use a as my marker). Then you make a marker on line 10. Once, you move to other place within the file. You can type "'a" to go back your marker a (line 10 in our example). Thus, it helps you to have better navigation experience in vim.


    But, how can I make use of marker to copy and paste multiple lines? Remember, when you need to copy something in vim, you have to use yank "y". You can go to any lines other than line 10, then press "y'a", which means you copy from current location to marker a (line 10). You then can you paste command "p" to paste the thing you just copied.


    Then, our next step is to pasting the copied content to other files rather than current file. To edit other file, you can use ":ex [filename]". Then you should be editing other file right now, you can press "p" to paste. Nice!


    Summary:
    • "m + [a - z]" - create a marker with the letter [a - z]
    • "'m +[a - z]" - go to marker [a - z]
    • "y'[a - z]" - yank from current line to marker [a - z]
    • ":ex [filename]" - edit other file

    Monday, February 14, 2011

    Vim Usage: Convert to Unix format from dos format

    When a dos format text file is edited by *nix system, a "^M" character will be added at the end of each line. This is because there is a difference between line break of dos system and that of *nix system.

    If you are vim user, you certainly will open the file with vim. You probably will see some information that ""dos.txt" [dos] 55L, 33C". [dos] means you are editing a dos format file. If you see [mac] instead of [dos], it means it is created under mac environment.

    Some time, you will get an error about wrong interpreter if you wrote a shell under windows and then execute under *nix system. One possible reason is due to "^M" character, thus you need to delete all this character. There are many methods to do so. Previously, I introduced a unix tool to convert dos file to unix file using dos2unix (read this post). This time, I use vim since it is built-in *nix already.


    In command mode
     : set ff
    [this will file format of current file]
     : set fileformat=unix

    Sunday, February 13, 2011

    Vim Usage: remove all empty lines

    In text editing, especially when you copied the content from some website, you might want to delete all empty lines in your text. In the past, I will do something stupid which is to delete the empty line one by one. It takes time and I use this command to achieve my goal
    dd, (go to next empty line), then "." ,until you delete all the empty line.

    Explanation:
    • dd - delete whole line
    • . - repeat the last command (I like this one, very useful)
    However, I realized there is a command which is much more useful and handy:

    :g/^$/d
    Feel free to use it if you need to delete all empty lines :-) 

    Friday, February 11, 2011

    Vim Usage: Change upper case/lower case

    I am addicted to use vim all the time, in programming (except eclipse), in text editing. I like to use it since it increase my working progress and the command helps me a lot.

    I am going to post some notes when I learn some new useful command/macro.
    One useful function is to change letter case. For one character, you can simply use "~" to change to case from upper to lower or vice versa.

    However, what if I want to change whole passage to UPPERCASE or lowercase. We can use gU / gu command.

    1. Change whole passage to lower case
    you can use "ggguG" in command mode.

    Explain:
    • gg - go to the first line and first character
    • gu - change letter to lower case
    • G - go to the last character of last line
    Thus, it goes to the first character, change to lower case until the last character.

    2. You can use motion command to change case

    guw、gue、gUw、gUe

    3. some special combinations

    • gUU - change current line to uppercase
    • 10gUU - change 10 lines including current line to uppercase
    • gU0 - change first character of current line to uppercase
    • gU$ - change last character of current line to uppercase
    • gUG - change character from current position to last charactor of last line

    Tuesday, February 8, 2011

    Install Longman Dictionary under 64-bit Ubuntu

    Since I need to reinstall my computer as the previous post said, I install Longman Dictionary again, but I got the following error:

    The setup program seems to have failed on amd64/glibc-2.1
    Fatal error, no tech support email configured in this setup

    I remember I faced this error before but I have forgotten the reason and how I solve it. After googling, it seems to be that the software doesn't support 64-bit system. To solve it, we need to sacrifice a bit and use 32-bit.
    $ linux32 ./setup.sh
    Then you should install it without problem.

    Ubuntu 10.10 is not stable for ATI display

    I upgrade my computer to Ubuntu 10.10 from 10.04 LTS without any problem. However, when I use it, it hangs randomly. The whole screen freezes and the only thing I can do is to hard reboot. I think it is related to my display card driver (I use ATI HD 4300 series). Thus, I deleted it and the problem is that the session will automatically logoff randomly. It seems that it is better than freezing the screen, huh..at least I can login again.... Then, I download the driver from ATI ...after installation, freezing screen problem occurred again.....Then I have no choice and I am setting up Uunutu 10.04 LTS again right now........

    This experience tells me that it is better to use LTS version.... and it seems that Ubuntu 10.10 doesn't support the display well for ATI. However, for my netbook, this is ok..

    Monday, February 7, 2011

    Set default half punctuation in IBUS

    I usually use half punctuation even when I am typing Chinese character. I should use full punctuations unless I need to type some formal and official documents. Every time, I launch IBUS which these two action "Ctrl+space" to turn on IBUS and then "Ctrl+." to switch to half punctuation mode.

    Recently, I take a look of IBUS source code and I found how IBUS determine which mode is turned on by default. It look at the table database file. For me, I use cangjie3. Thus I edit the database with sqlite3 (you can use apt-get to install it)
    $ sqlite3 /usr/share/ibus-table/tables/cangjie3.db

    Then, you can view your current setting by:
    select * from ime;

    You can see that by default,def_full_width_punct is set to be TRUE. Thus, I simply set it to be FALSE using sql:
    update ime set val='FALSE' where attr='def_half_width_punct';

    Finally, you just need to restart IBUS and you will find the default punctuation mode is half.

    Sunday, February 6, 2011

    Set Default Traditional Chinese in IBUS under English Ubuntu 10.10

    I am using Ubuntu 10.10 in my netbook. Basically, this is good and I used it for a long time. However, I hate the Ibus default setting for my usual chinese input method (cangjie) as the default chinese mode is simplied chinese if I use English Ubuntu (locale: LANG: en_HK). Thus, I found a way to solve my problem and set the default chinese mode to be traditional. I modified the ibus problem.

    1. Edit /usr/share/ibus-table/engine/table.py
    2. Find the following code (at about line 116)
    if __lc.find('zh_') == 0:
                    # this is a zh_XX
                    __place =__lc.split('_')[1]
                    if __place == 'cn':
                        return 0
                    else:
                        return 1
                else:
                    if self.db._is_chinese:                                                                               
                        # if IME declare as Chinese IME
                        return 0
                    else:
                        return -1
    3. Edit as following
    if __lc.find('zh_') == 0:
                    # this is a zh_XX
                    __place =__lc.split('_')[1]
                    if __place == 'cn':
                        return 0
                    else:
                        return 1
                else:
                    if self.db._is_chinese:                                                                               
                        # if IME declare as Chinese IME
                        # return 0
                        return 1  #Edit this line to return 1 instead of 0
                    else:
                        return -1
    4. Restart IBUS and DONE