Thursday, September 30, 2010

[HOWTO] Change order of buttons on the menu bar

In Ubuntu 10.04, the default theme style looks like MacOS. Thus, the button on the menu bar follows the order of MacOS also which is "close", "minimize" and then "maximize" placed on the top right corner.


Some people might not like this arrangement and want to change back to traditional one.

To do so, open a terminal
$ gconftool-2 --set "/apps/metacity/general/button_layout" --type string "menu:minimize,maximize,close"


If you want to switch them back to the left corner
$ gconftool-2 --set "/apps/metacity/general/button_layout" --type string "close,minimize,maximize:"


In fact, you can play around with the order to suit your need. Have Fun!!

Wednesday, September 29, 2010

JS1k

I just know that there is a competition about javascript called JS1k. As the name self-explained, this is about to write a javascript program with 1k only. Unfortunately, when I know this event, the deadline passed. The rules are
  1. Create a fancy pancy Javascript demo
  2. Submissions may be up to 1k. (And not crash)
  3. Externals are strictly forbidden, unlike "some" contests. (Good luck minifying jQuery though!)
  4. Must work on current fx, sa, ch and o. (Let's level the playing field)
  5. Minification and hacks allowed. (Go nuts)
  6. Bonus points if your submission fits in one tweet ;)
  7. Last day to submit is 10 September 2010
If you are interested, you can visit JS1K home page. Here is the top one and the author shows his source code with comment in his website, http://marijn.haverbeke.nl/js1k.html

Tuesday, September 28, 2010

[HOWTO] Use IBus in Ubuntu

Since I don't know why I can't install fedora 13 in my computer, I installed Ubuntu 10.04 instead. The first thing I need to do after installation is to type Chinese. When I used Fedora 12, I used to use gcin as my favorite input method. So, now I have a chance to switch to IBus as the default input method in Ubuntu is IBus.

To start IBus
Click System >> Preferences >> IBus Preferences

You will see a message which reads:
IBus daemon is not started. Do you want to start it now?
Then simply click, "Yes"

After clicking yes, the following message shows:
IBus has been started! If you can not use IBus, please add below lines in $HOME/.bashrc, and relogin your desktop.
export GTK_IM_MODULE=ibus
export XMODIFIERS=@im=ibus
export QT_IM_MODULE=ibus
You can try to follow the message if you have any problem, but I skip it since I didn't have any.

IBus Preferences
In the general tab , you can check "Show input method name on language bar" (I suggest to do so).
In the input method tab, you can add any input method you want.
I use Cangjie(倉頡) as my main input method, and by default, there is a input method named cangjie(m17n) in the list. However, I don't like this one since it insert a space after every character.
I prefer to use cangjie3(倉三). The way to install it is to use apt-get
open a terminal and run
$ sudo apt-get install ibus-table-cangjie

After installation
you can find cangie3 under Chinese menu. Then click add.

Let IBus start automatically when restarting my computer
Go to System >> Preferences >> Startup Applications
Click "add" button and input following details
Name: IBus daemon
Command: /usr/bin/ibus-daemon -d
Comment: start IBus daemon when Gnome starts

To use IBus
press control + space to enable or disable the IBus

Friday, September 24, 2010

[HOWTO] Convert Simplified Chinese to Traditional Chinese and vice-versa (繁轉簡)

Now, I am implementing a program that need to have a database pre-stored some data. I grep the data from internet but those are simplified Chinese. I need to convert them into traditional Chinese. This can be done using one command

$ iconv simplified_chinese_input.txt -f utf8 -t gb2312 | iconv -f gb2312  -t big5 | iconv -f big5  -t utf8 -o traditional_chinese_output.txt


This involves three steps actually,
1. This first convert the text file from UTF8 to GB2312 (Simplied Chinese) 2. Then, convert the GB2312(Simplied Chinese) to Big5 Encoding (Traditional Chinese) 3. Finally, convert the Big5 to UTF8 text file

In fact, you can change the order so that it can convert traditional Chinese to simplified Chinese
$ iconv traditional_chinese_input.txt -f utf8 -t big5 | iconv -f big5 -t gb2312 | iconv -f gb2312 -t utf8 -o simplified_chinese_output.txt


If you need to do this many times, you can store it as a Shell Script named S2T.sh with following content.
#!/usr/bin/sh
iconv $1 -f utf8 -t gb2312 | iconv -f gb2312 -t big5 | iconv -f big5 -t utf8 -o $2


Then, set it to be executable
$ chmod u+x S2T.sh


Finally, use it with
$ ./S2T.sh input.txt output.txt


Hope it helps.

Communicate Google with Command

On Linux, we offer need to type command and I think using command is better than by clicking most time. This is because I need to control the mouse precisely to certain location. This is not convenient for me at all. In addition, I don't want to leave my hand out of the keyboard, so I remember some useful command such as using Ctrl+L in Firefox to type URL instead of using the mouse to click on the url field. I can navigate different web without leaving keyboard. If you are vim experienced user, I think you should like this firefox plugin - Vimperator which you can navigate webpage with your keyboard only.

Now, Google provides many web applications such as Gmail, Contact, Google Docs and this blog Blooger, etc. Fortunately, Google provides a command line tool for them also named GoogleCL http://code.google.com/p/googlecl/. This is a command line tools for the Google Data APIs.

You can do many things using this command tools just like

1. Blogger - create a new post
$ google blogger post --title "create post using GoogleCL" "I can create a new post in command line"


2. Picasa - upload new image to Picasa
$ google picasa create --title "GoogleCL Photos" *.jpg


3. YouTube - upload new video to YouTube
$ google youtube post --category Education linux_command.mpg


For more usage, you can visit the GoogleCL official website. You will find it is extremely useful and you can cooperate with Crontab with GoogleCL, you can do more such as creating a Calendar everyday.

Do Programming Quickly??

I think I am still young in programming area. I learnt Pascal in High School and learn C++ and Java in University. Most of the time, implementing a program takes lots of time especially designing Graphic User Interface (GUI).

Ubuntu now provides a solution "Quickly" that helps people to write program QUICKLY.
https://wiki.ubuntu.com/Quickly

Quickly uses Python as programming language, GTK as the GUI. It provides lots of handy commands help you to program. Basically, what you need first is to install Quickly, but it only has Ubuntu version only. I hope it can support more distribution later.

1. To install
$ sudo apt-get install quickly


2. Build a project
$ quickly create ubuntu-application myapps
$ cd !$

(refer to my previous post to know what !$ means if you don't know)

3. Edit the project
$ quickly edit


4. Design the GUI
$ quickly design


5. Run the program
$ quickly run


Which Quickly, it is really easy to build your own application with small amount of time.

Thursday, September 23, 2010

Linux is awesome if you remember the commands??

Recently, my friend had to use Linux to do something. After one day working, he told me a statement and I think it is funny: "Linux is awesome if you can remember all the commands, otherwise, Linux sucks."

Then, I think a little bit. That's may not be true since Linux has many choices of Windows Environments like Gnome, KDE, etc. They are easy to use and very handy. Most daily works, you can do them by a few click just likes M$ Windows.

However, I do agree that the commands in Linux is awesome if you know them. Sometimes, I use "wget" to download files instead of browser. I use vi(vim) as my major text editor. Writing a bash script can do more such as starting some services/programs when the Linux starts.

Here are some commands I think they are useful:

1. Ctrl + E and Ctrl + A
Sometimes, you find that you need to modify the command at the beginning or at the end. You can simply press "Home" or "End" to go the first position or last position. However, it doesn't work such as using SSH. If you really want to go to beginning, the stupid way is to press left arrow. In fact, you can use Ctrl+E to move the end and Ctrl+A to move to the beginning.

2. !$ - A useful variable.
This stores the last argument in the previous command. Here is an example to this variable.
$ mkdir folder
$ cd folder


In fact, you can you use the following commands:
$ mkdir folder
$ cd !$


3. A crazy command, I like this command very much!
$ :(){:|:&};:

It seems that it is an invalid command. In fact, this does work!!
First of all, :(){ ... } defines a function called ":" with no arguments. In side this function, is call ":" again and "|"=pipe the output to itself. The semi-colon end the function definition and the last colon call the function.
To be concluded, this command call a function that recursively creates a process. Then, your system will hang..