Monday, November 28, 2011

Yet Another New Discuses

Last time I just bought two discuses from 北高雄, one red and one orange, so unfortunately both of them couldn't adapt to their new environment and a week later the red one was die due to diseases and the orange one was die due to starvation. 

Later on, I visited the aquarium store 魚世界水族 on 建工路 to look around their discuses. I just can't resist  not to buy their beautiful small discuses. Then I bought four discuses with special price ^^ (The boss just so nice to me!). Really recommend this store, if you want to buy some cheap and beautiful discuses. So, here are the pictures of my new discuses. 


They look a little bit darker, due to the shock during the way back home. 

The skin looks darker, but actually the real color is not like that







Those two blue discuses on the right side are the old fishes that have grown so big now





Wednesday, November 23, 2011

How to Convert MySQL Database Character Set from default latin1_swedish_ci to UTF8

Currently I am working with Joomla CMS (Content Management System) which is hosted in a foreign web host and its MySQL database is using latin1_swedish_ci character set. I need to convert it to UTF8 since the content of the website that I'm dealing with is in English, Chinese Traditional and Chinese Simplified.

After searching in the web, I found a php code that can do the thing I want. The solution is pretty easy (at least after I found this code), just copy and paste the code below in a php file, let's call it a converter.php file, and then on the second to fourth line of the codes below change the parameters so that it will fit to your database settings. Here's the code:

<?php
define('DB_NAME', 'putyourdbnamehere');    // Put your database name here
define('DB_USER', 'usernamehere');     // MySQL Username
define('DB_PASSWORD', 'yourpasswordhere'); // Password
define('DB_HOST', 'localhost');    // Mostly just use the localhost

function UTF8_DB_Converter_DoIt() {
 $tables = array();
 $tables_with_fields = array();

 // Since we cannot use the WordPress Database Abstraction Class (wp-db.php),
 // we have to make an a stand-alone/direct connection to the database.
 $link_id = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('Error establishing a database connection');
 mysql_select_db(DB_NAME, $link_id);

 // Gathering information about tables and all the text/string fields that can be affected
 // during the conversion to UTF-8.
 $resource = mysql_query("SHOW TABLES", $link_id);
 while ( $result = mysql_fetch_row($resource) )
  $tables[] = $result[0];

 if ( !empty($tables) ) {
  foreach ( (array) $tables as $table ) {
   $resource = mysql_query("EXPLAIN $table", $link_id);
   while ( $result = mysql_fetch_assoc($resource) ) {
    if ( preg_match('/(char)|(text)|(enum)|(set)/', $result['Type']) )
     $tables_with_fields[$table][$result['Field']] = $result['Type'] . " " . ( "YES" == $result['Null'] ? "" : "NOT " ) . "NULL " .  ( !is_null($result['Default']) ? "DEFAULT '". $result['Default'] ."'" : "" );
   }
  }

  // Change all text/string fields of the tables to their corresponding binary text/string representations.
  foreach ( (array) $tables as $table )
   mysql_query("ALTER TABLE $table CONVERT TO CHARACTER SET binary", $link_id);

  // Change database and tables to UTF-8 Character set.
  mysql_query("ALTER DATABASE " . DB_NAME . " CHARACTER SET utf8", $link_id);
  foreach ( (array) $tables as $table )
   mysql_query("ALTER TABLE $table CONVERT TO CHARACTER SET utf8", $link_id);

  // Return all binary text/string fields previously changed to their original representations.
  foreach ( (array) $tables_with_fields as $table => $fields ) {
   foreach ( (array) $fields as $field_type => $field_options ) {
    mysql_query("ALTER TABLE $table MODIFY $field_type $field_options", $link_id);
   }
  }

  // Optimize tables and finally close the mysql link.
  foreach ( (array) $tables as $table )
   mysql_query("OPTIMIZE TABLE $table", $link_id);
  mysql_close($link_id);
 } else {
  die('<strong>There are no tables?</strong>');
 }

 return true;
}
UTF8_DB_Converter_DoIt();
?>
Source: http://blog.mashida.info/?p=1353 and http://bingu.net/472/latin1_swedish_ci-to-utf8_general_ci/

Save the converter.php file and then upload to your webhost www folder and execute that php by requesting that file using your browser. E.g. If your webhost domain is www.mywebhost.com, then you can request the file with www.mywebhost.com/converter.php. And boom, everything is done, your database will be converted from latin1_swedish_ci character set to UTF8. And don't forget to delete your converter.php file on your webhost since it will not be used anymore.

Monday, November 14, 2011

New Members of My Discus Family

New members of my discus family
Feed the fishes in aquarium before releasing the new comer with hope that they will not bully them
Feed them with Artemia (Brine Shrimps) put in floating feeding net

Another angle of my new discuses in plastic
皇冠七彩

Red Pigeon Discus
New fish 1

New fish 2


New fish 2

"Sucking" fish
Quarantine the old fishes with separation net box, since they are bullying the new comer
Five discuses in my aquarium

Friday, November 11, 2011

Java Programming Thread

什麼是 Thread?
Thread 翻成中文叫做執行緒。一個程式一般來說就是一個 Process, 會執行一個工作就是從 main( ) 或主程式(事實上是一個主執行緒)從第一行到最後一行,而執行緒可以讓程式可以同時執行好幾個工作。更清楚的解釋: http://en.wikipedia.org/wiki/Thread_(computer_science)

A multithreaded process with two threads executing in time clearly showing that the threads execute separately and execute mutually exclusively in time. [Source: http://en.wikipedia.org/wiki/File:Multithreaded_process.svg]


什麼時候要用到Thread?
當我們有很多動西要同時一起跑的時候就要用到Thread, 比如說你的程式要刷新畫面,同時也要下載東西,播放音樂,監聽事件(Event Listener 同時要有好幾個 while loop 在等待).

到底要 extends Thread 還是 implements Runnable (extends Thread VS implements Runnable)? 
The difference:

1)If you want to extend the Thread class then it will make your class unable to extend other classes as java is having single inheritance feature whereas If you implement runnable interface, you can gain better object-oriented design and consistency and also avoid the single inheritance problems.
2)Extending the thread will give you simple code structure in comparison to Runnable Interface.
3)Using Runnable Interface, you can run the class several times whereas Thread have the start() method that can be called only once.


Thread .setDaemon(true) 的方法(method)
如果設成Daemon則代表這個thread在背後執行

從Main函式開始的是一個非Daemon執行緒,如果您希望某個執行緒在非Daemon執行緒都結束後也跟著終止,那麼您要將它設定為Daemon執行 緒,下面這個程式是個簡單的示範: 
  • DaemonTest.java
package onlyfun.caterpillar;
 
public class DaemonTest { 
    public static void main(String[] args) { 
        Thread thread = new Thread(new Runnable() {
            public void run() { 
                while(true) { 
                    System.out.print("T"); 
                } 
            }        
        }); 
        thread.setDaemon(true); 
        thread.start(); 
    }
} 

Wednesday, November 9, 2011

Useful Linux Terminal Commands

lsb-release (Linux Standard Base - Release)
- Print your linux distribution-specific information
for example:
# lsb-release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 11.10
Release:        11.10
Codename:       oneiric


iwlist (Wireless Interface list)
- Get more detailed wireless information from a wireless interface

This is useful when you use Ubuntu on your laptop and you want to connect to the wireless network but you don't know the SSID of the available APs (Access Points) around you.

Example:
# sudo iwlist wlan0 scan

wlan0     Scan completed :
          Cell 01 - Address: 54:E6:FC:E6:62:B8
                    Channel:3
                    Frequency:2.422 GHz (Channel 3)
                    Quality=42/70  Signal level=-68 dBm
                    Encryption key:off
                    ESSID:"cse_f5011"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
                              9 Mb/s; 12 Mb/s; 18 Mb/s
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
                    Mode:Master
                    Extra:tsf=000000bb0a5b09de
                    Extra: Last beacon: 48ms ago
                    IE: Unknown: 00096373655F6635303131
                    IE: Unknown: 010882848B960C121824
                    IE: Unknown: 030103
                    IE: Unknown: 2A0102
                    IE: Unknown: 32043048606C
                    IE: Unknown: DD180050F2020101860003A4000027A4000042435E0062322F00
                    IE: Unknown: DD1E00904C334E101BFFFF000000000000000000000000000000000000000000
                    IE: Unknown: 2D1A4E101BFFFF000000000000000000000000000000000000000000
                    IE: Unknown: DD1A00904C3403051B00000000000000000000000000000000000000
                    IE: Unknown: 3D1603051B00000000000000000000000000000000000000
                    IE: Unknown: DD0900037F01010000FF7F
                    IE: Unknown: DD0A00037F04010000004000
          Cell 02 - Address: 00:02:2D:2A:3E:DF
                    Channel:8
                    Frequency:2.447 GHz (Channel 8)
                    Quality=58/70  Signal level=-52 dBm
                    Encryption key:off
                    ESSID:"WaveLAN Network"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s
                    Mode:Master
                    Extra:tsf=0000000001dd3a38
                    Extra: Last beacon: 6380ms ago
                    IE: Unknown: 000F576176654C414E204E6574776F726B
                    IE: Unknown: 010482848B96
                    IE: Unknown: 030108
                    IE: Unknown: 800600601D003600



ldconfig (Load Configuration)
- Configure dynamic linker run-time bindings

ldconfig  creates,  updates, and removes the necessary links and cache (for use by the run-time linker, ld.so) to the most recent shared librariesfound in the directories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories (/usr/lib and /lib).  ldconfig checks the header and file names of the libraries it encounters when determining which versions should have their links updated.  ldconfig ignores symbolic links when scanning for libraries.


">" (greater sign)
-Redirecting Output

Redirection of output causes the file whose name results from the expansion of word to be opened for writing on file descriptor n, or the standard output (file descriptor 1) if n is not specified. If the file does not exist it is created; if it does exist it is truncated to zero size.

The general format for redirecting output is:
[n]>word

If the redirection operator is >, and the noclobber option to the set builtin has been enabled, the redirection will fail if the file whose name results from the expansion of word exists and is a regular file. If the redirection operator is >|, or the redirection operator is > and the noclobber option to the set builtin command is not enabled, the redirection is attempted even if the file named by word exists.  


">>" Appending Redirected Output

- Use to append the redirected output to the designated file
for example:
# echo "test" >> testFile.txt
if the original testFile.txt has content:
abc
then the result will be:
abc
test

Redirection of output in this fashion causes the file whose name results from the expansion of word to be opened for appending on file descriptor n, or the standard output (file descriptor 1) if n is not specified. If the file does not exist it is created.

The general format for appending output is:
[n]>>word


mkdir -p (Make multiple sub directories with parent directories)
-Make directory with also sub directory and no error if sub directory is existing and make parent directories as needed
E.g.:
# mkdir -p /home/test/dir1/{public,private,log,backup}



zip -r (Compress File(s))
-Compress a directory to a zip file
E.g.: 
To zip directory called images in your home directory (/home/username/images), type the following command:
# zip -r myimages.zip /home/you/images/


It recurses into directories (all files and directories inside pics) to produced zip file called myimages.zip


unzip
-Unzip or extract your .zip file

Sunday, November 6, 2011

高雄水族館評語


上個禮拜為了要買七彩神仙魚特地去了高雄市好多好多的水族館,想說寫下來讓自己有個紀錄而且也讓大家可以參考一下,說不定大家跟我一樣想要試養七彩神仙看看。以下我用黃色標起來的水族館是我覺得不錯的而且推薦大家去看看:



* 新樂街的 公園水族:
沒有七彩,而且店面很小!


* 鼓山區華安街的 萬龍七彩水族:
七彩專賣店,有些還蠻漂亮的但是價錢偏高,其餘的魚看起來都普普,是老闆自己繁殖的。另外,這邊的豐年蝦好大一片只要120元而已(其他地方賣150元老闆說的)。



* 博愛路的 地中海: 
有七彩神仙,但是都是大的而且沒有很多,店面感覺破破爛爛的東西也有些灰塵了。


* 大昌二路的 彩洋水族館
專賣七彩神仙魚/Discus,漂亮的七彩很多但是都很貴! 最便宜150元的那種都很爛,不是身體有缺陷就是顏色不好看(比如很多黑點)。

* 明誠路的 北高雄
有便宜的七彩一隻180元, 三隻450元,但是看起來不是很健康而且七彩不多,這家店是我最常去的水族館,環境很好,魚種很多,東西常常有優惠價(Tropical的魚飼料當時打7.5折,沒有其他更便宜的了),推薦!

* 大樂 (Dollar) 後面的 北高雄
跟明誠路的北高雄差不多,只是這裡多了貓狗的Salon。


* 九如一路的 永豐魚寵物水族生活館
有七彩神仙,東西很多,賣場很大,魚種類很多而且大部分看起來都很健康養到胖胖的,可惜這邊的魚價錢有點偏高。


* 華夏路的 永信水族量販:
有蠻多七彩神仙,也有便宜150元的(皇冠和電籃),然後有個店員叫Vincent感覺還蠻親切的而且Offer special price 原本500元變400元的紅色七彩神仙給我,但後來我都沒有跟他買。另外,這家店的其他魚種也很多,魚缸都很乾淨,有些魚算蠻便宜的,但是這邊的魚看起來都瘦瘦的,但是整體來說這家水族館不錯!

* 鼎山街的 永信水族量販:
有七彩神仙,也有便宜150元的那一種(皇冠和電籃七彩)還有打八折喔! 但是150元的那一種看起來都健康(快要掛掉的那一種,可能是因為他們剛買進來,魚還沒適應),其他的七彩都還不錯看,只是有點貴!這家的魚飼料尤其是Tropical牌的蠻便宜,打八折。

* 鼎山街永信水族量販對面的水族館
沒有七彩神仙而且魚很少!

* 後昌路的 龍鳳水族:
沒有七彩神仙,很多大型而且奇奇怪怪的魚。


* 藍昌路的 地中海:
七彩只有 4隻,漂亮但是應該很貴。


* 大順三路的水族館忘了什麼名子:
很爛的水族館,東西都是灰塵而且是很厚很厚的灰塵喔! 魚也不多,去那邊浪費時間而已!

* 應昇路的 山水水族量販:
沒有七彩神仙,這邊的魚和烏龜飼料算蠻便宜的。

* 建工路的 魚世界水族賣場:
便宜的七彩很多 150元的(皇冠和電籃),而且大部分看起來都還蠻漂亮的。我最後就是在這一家買,買4隻跟老闆出價500元,但是老闆不給,最後老闆以 550元的價錢賣給我,哈哈 好像賺到了!^^



以下是我在網路上找到的高雄市水族館優質商家的列表讓提供給大家參考參考
高雄市水族館優質商家介紹
高雄市水族館
http://www.petgd.com.tw/

高雄市水族館-永豐魚寵物水族生活館 07-3875986 高雄市三民區九如一路278號
高雄市水族館-彩洋水族中心 07-3803426 高雄市三民區大昌二路473號
高雄市水族館-畢格拜爾國際股份有限公司 07-3115688 高雄市三民區中華二路367號
高雄市水族館-雅格水族館 07-3964708 高雄市三民區民豐路41號
高雄市水族館-山水水族量販 07-3877990 高雄市三民區延吉街50號
高雄市水族館-優樾實業有限公司 07-2364135 高雄市三民區建國二路34號8樓
高雄市水族館-洪星七彩站 0800-331313 高雄市三民區鼎力路136號
高雄市水族館-永信水族連鎖-鼎山店 07-3978995 高雄市三民區鼎山街293號
高雄市水族館-地中海-鼎山店 07-398-3097 高雄市三民區鼎山街362號
高雄市水族館-萬隆水族量販廣場 07-342-4598 高雄市三民區鼎中路427號(文藻學院旁)
高雄市水族館-北高雄水族大賣場 07-3872033 高雄市三民區聯興路58號
高雄市水族館-萬魚龍水族廣場﹝高雄店﹞ 07-7232369 高雄市中正一路262號
高雄市水族館-徐文豐七彩神仙中心 07-3651635 高雄市左營區後昌路625巷72號
高雄市水族館-地中海-華夏店 07-349-8422 高雄市左營區華夏路971號
高雄市水族館-魚坊七彩工作室 07-2875683/0917539232 高雄市前金區自立二路73巷28號
高雄市水族館-地中海-獅甲店 07-334-9839 高雄市前鎮區中東五路1366號
高雄市水族館-豐源淡水魚批發 07-8128481 高雄市前鎮區衙忠路55號
高雄市水族館-海源七彩專賣 07-8222783 高雄市前鎮區漁港路145號
高雄市水族館-彩廬七彩 - 苓雅門市 07-3341234 高雄市苓雅區四維三路128號
高雄市水族館-綠色工坊 07-7151126 高雄市苓雅區宜昌街14號
高雄市水族館-尖端專業海水.水草水族工藝 07-3314623 高雄市苓雅區林森二路98號
高雄市水族館-地中海-鳥松店 07-733-1627 高雄市鳥松鄉中正路355-2號
高雄市水族館-地中海-博愛店 07-557-5546 高雄市博愛2路272號
高雄市水族館-地中海-民族店 07-223-3450 高雄市新興區民族2路136號
高雄市水族館-地中海-右昌店 07-368-0722 高雄市楠梓區右昌街715號
高雄市水族館-伊甸園七彩水族 07-6105543 高雄市楠梓區右昌街753號
高雄市水族館-混水摸魚水族館 0935-942912 高雄市楠梓區旗楠路26號
高雄市水族館-萬龍七彩水族 07-5213707 高雄市鼓山區華安街131號
高雄市水族館-海鯨水族大賣場 07-5350813 高雄市興中一路275號
高雄市水族館-尚美水族館 07-8156657 高雄市鎮國路40號