Friday, December 31, 2010

`multirow.sty' not found

When I use package multirow in Latex, error occurs when compiling the source file. The error is saying `multirow.sty’ not found.

We can fix under Ubuntu:
$ sudo apt-get install texlive-latex-extra

Monday, December 20, 2010

1 + 1 = ??

How do you answer that sum of one plus one?

Whatweb

What web is it?

When you visit a web, sometimes you just want to obtain information from the web. However, sometimes, you may want to know which server the web uses, which programming language the programmers use, which CMS they use. You may obtain this information from the server response. Here is a simple tool that helps you to find out the answer - Whaweb(http://www.morningstarsecurity.com/research/whatweb).

This is written with Ruby and simply type
$./whatweb url


It will show you the relevant information such as web server.

Tuesday, October 19, 2010

Check internet connection in Android

Sometimes, apps need internet access to get content from other remote resources. However, you also need to take care the case when there is no internet access. You can't assume users always has internet access. To check whether a mobile has internet or not, you can use the following code:

public boolean isOnline() {
ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
boolean connected = (conMgr.getActiveNetworkInfo() != null &&
conMgr.getActiveNetworkInfo().isAvailable() &&
conMgr.getActiveNetworkInfo().isConnected())
return connected;
}


Also, you need to add permission to the app so that it can access network status.



Note: In emulator, you can press F8 to toggle the internet access.

Remove extra space on the right in the WebView

WebView is a very important element in Android. In mobile, people like to scroll everything such as contact list, email, webpage. However, didn't you realize that the scrolling is only in the vertical direction? This makes the user interface more friendly.

In WebView, you can scroll a webpage horizontally and vertically, but it is better to fix the horizontal bar by adjust the size of the contents so that the contents don't expand the View. I did that but I found there is some extra spaces in the WebView to make view scrollable horizontally. First, I think it is related to CSS and margin, so I add

* {margin:0px; padding: 0px;}

But it doesn't work. Finally, I realize that is the problem of the vertical scroll that occupies some spaces. To solve this problem, you can set the scrollbar style to display the scrollbars inside the content area.
webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

Sunday, October 3, 2010

[HOWTO] Remove .svn folder under svn repository

When you svn checkout a project via SVN, it will create .svn folder to keep track the changing in this working folder also. However, when you need to give out the source code, this .svn folder may not be good to be distributed to other also. Instead of remove the folder one by one. You can use find command

find PATH -type d -name '.svn' -exec rm -rf {} \;

Friday, October 1, 2010

[HOWTO] Connect Creative Zen with Ubuntu

I have a Creative Zen, and if you need to transfer music to the device, you need another software to help you. In the past when I was using Fedora, there is a software named Gnomad2 http://gnomad2.sourceforge.net/. After compilation, you can use it can transfer your favorite songs.

However, it seems that Ubuntu 10.04 has some problem about this software. I use apt-get to install it first. Then, plugged in the zen, unmounted and started gnomad2. Gnomad2 crashed immediately. I tried "gnomad2" in terminal and received the following output:

Queried Creative ZEN
Segmentation fault

Then, I googled this situation and some tell me I should compile from the source. But it doesn't work for me, here is the guide and you can try

1. Uninstall gnomad2 from your system
$ sudo apt-get remove gnomad2


2. Clean out any left over dependencies
$ sudo apt-get autoremove


3. Download the source files for gnomad2
$ apt-get source gnomad2

Note:
a. You may get some error about dependency, you need to use apt-get to install the dependency if needed.
In my case, it told me I do not have "dpkg-source" then I
$ sudo apt-get install dpkg-dev

b. "apt-get" not "sudo apt-get", you don't need root permissions here as we're not installing anything. Using the sudo command will cause permissions problems later when trying to delete the source files.

4. Configure
$ ./configure

Note:
a. For the first time, it may get following errors
No package 'glib-2.0' found
No package 'gthread-2.0' found
No package 'libnjb' found
No package 'gtk+-2.0' found
Then to solve this problem,
sudo apt-get install libglib2.0-dev

sudo apt-get install libgtk2.0-dev

sudo apt-get install libnjb-dev

b. For the second time,
checking for id3tag.h... no
configure: error: *** id3tag.h C header is needed (missing -dev package?) ***\n*** You might have erroneously installed id3lib instead of libid3tag ****\nThis distinction is very delicate, so PLEASE pay attention! ***
To solve this problem,
$sudo apt-get install libid3tag0-dev


c.For the third time
configure: error: Your intltool is too old. You need intltool 0.35.0 or later.

$ sudo apt-get install intltool


5. compile
$ make


6. install
$ sudo make install


7. Gnomad2 installed successfully! Delete the files and directs apt-get downloaded.

Unfortunately, when I launch Gnomad2, it said it cannot find the device. Finally, I realized that Ubuntu can support my Zen using RhythmBox by default and I can use it to transfer music. Awesome!

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..

Sunday, January 10, 2010

[Game] SuperTux and Pingus

SuperTux and Pingus

If you are my friend, you should know that I seldom play computer games since I think it is quite meaningless and time-consuming. I, however, still play some mini computer games, such as Mine, Tetris, etc. In Linux, I found two games which are free and quite interesting to play. They don't waste you lots of time, I finish them within about two days. You need wisdom and skills to finish the games. Hope you enjoy them!

If you would get more details about them, please visit following links:



Screen shot:


SuperTux







Pingus







Saturday, January 9, 2010

[HOW TO] turn on NumLock when login Linux

Do you think it is convenient to turn on NumLock when you logon the system?

I used MS Windows for a long time and switched to Linux for about two years. In MS Windows, Numlock is already turned on when I logon. While in Linux, Numlock by default is off and I need to press numlock key before using key pad(but I always forget :-))

I searched this problem in Google and found a good program called NumLockX. You can install it through yum or apt-get

To install NumLockX using yum

yum install numlockx


To install NumLockX using apt-get

sudo apt-get install numlockx

Wednesday, January 6, 2010

[HOW TO] get MAC Address and IP in shell

Do you wanted to get the MAC or IP address of your computer in a Linux shell script?

Some people including me feel it is troublesome to get the real ip if using router.The following commands can help you to get them easily.

(These commands only get information from eth0 interface. If you have many network interfaces, you need to modify the command by changing "eth0" to your favour(e.g. lo))

To get internal IP address:

ifconfig eth0 | grep 'inet '  | sed -n '1p' | tr -s ' ' | cut -d ' ' -f3 | cut -d ':' -f2


To get MAC address

ifconfig | grep 'eth0' | tr -s ' ' | cut -d ' ' -f5 


To get external IP address:

wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1 | sed -e 's/^ *//' -e 's/ *$//'


If you think these commands are good and want to be your shell command, just copy following commands to "~/.bashrc" or "~/.bash_profile"

alias showip="ifconfig | grep 'inet ' | sed -n '1p' | tr -s ' ' | cut -d ' ' -f3 | cut -d ':' -f2"
alias showmac="ifconfig | grep 'eth0' | tr -s ' ' | cut -d ' ' -f5 "
alias showrealip="wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1 | sed -e 's/^ *//' -e 's/ *$//'"