Friday, November 04, 2011

解決 DejaVu Sans Mono 字型在 NetBeans 下中文顯示成方塊的問題

  1. 找到 NetBeans 安裝路徑, ex: C:\Program Files\NetBeans 7.0.1
    進入 etc 資料夾 ex: C:\Program Files\NetBeans 7.0.1\etc
    打開 netbeans.conf 並搜尋 netbeans_jdkhome 參數
    該參數存放的是 JRE 的路徑 ex:"C:\Program Files\Java\jre6"
  2. 進入 JER 的路徑, 並進到 lib 資料夾 ex: C:\Program Files\Java\jre6\lib
  3. 複製一份 fontconfig.properties.src 並更改檔名成 fontconfig.properties
  4. 編輯 fontconfig.properties 檔
    新增下列的內容
    filename.DejaVu_Sans_Mono=DejaVuSansMono.ttf
    filename.DejaVu_Sans_Mono_Bold=DejaVuSansMono-Bold.ttf
    filename.DejaVu_Sans_Mono_Bold_Oblique=DejaVuSansMono-BoldOblique.ttf
    filename.DejaVu_Sans_Mono_Oblique=DejaVuSansMono-Oblique.ttf
    
    修改下列的內容
    sansserif.plain.alphabetic=DejaVu Sans
    sansserif.bold.alphabetic=DejaVu Sans Bold
    sansserif.italic.alphabetic=DejaVu Sans Oblique
    sansserif.bolditalic.alphabetic=DejaVu Sans Bold Oblique
    monospaced.plain.alphabetic=DejaVu Sans Mono
    monospaced.bold.alphabetic=DejaVu Sans Mono Bold
    monospaced.italic.alphabetic=DejaVu Sans Mono Oblique
    monospaced.bolditalic.alphabetic=DejaVu Sans Mono Bold Oblique
    sequence.sansserif.x-windows-950=
      alphabetic,chinese-ms950,dingbats,symbol,chinese-ms950-extb
    sequence.monospaced.x-windows-950=
      alphabetic,chinese-ms950,dingbats,symbol,chinese-ms950-extb
        
  5. 做完上述的修改後, 再進入 NetBeans -> Tools -> Options -> Fonts & Colors -> Syntax -> Default -> Font, 選擇 Monospaced 字型, 這樣就可以正確地顯示 DejaVu Mono 的字型了, 收工!

Wednesday, September 28, 2011

Sage - Online Mathematical Software

Sage is an mathematical software, the coolest point is it can run with any web browser.

I tried a sample plot function below, the usability is awesome too!

x=var('x')
plot(-0.3+(x+0.6)^0.5, (0,100))

Monday, September 19, 2011

Benchmarks for mt_rand() and rand()

Benchmarks results as below:

mt_rand() 10000000 times for 4.7026278972626 seconds
each one average is 0.00000047 seconds
rand() 10000000 times for 4.7438910007477 seconds
each one average is 0.00000047 seconds

The test machine is Amazon EC2 High-CPU Instances (20 ECU)

Another test as below:

mt_rand() 10000000 times for 2.4974269866943 seconds
each one average is 0.00000025 seconds
rand() 10000000 times for 2.4646849632263 seconds
each one average is 0.00000025 seconds

The test machine is Amazon EC2 Micro Instances (1 ECU)

Tuesday, September 06, 2011

CentOS install node.js

Basically, follow the installation guide in the node.js GitHub wiki page. I use the "Building from source" guide. Then install npm, follow the guide too, just easy type with "curl http://npmjs.org/install.sh | sh"

When I test nmp installation (install express), I found that I should type 'npm install -g express', and the express will be installed in the directory which I want. Otherwise, nmp will install locally (such as: ./node_modules/).

Wednesday, August 31, 2011

Install PHPUnit on Windows 7

First you need install a Zend Server in C:\Zend folder

Install Pear

Run commands below

# pear channel-update pear.php.net
# pear upgrade pear
# pear channel-discover pear.phpunit.de
# pear channel-discover pear.symfony-project.com
# pear channel-discover components.ez.no
# pear clear-cache
# pear update-channels
# pear install --alldeps phpunit/PHPUnit

DONE!

Friday, August 26, 2011

32bit 系統下 json_decode 遇到 BIGINT 的問題

在 32bit 系統下處理 Facebook 的 uid 時, 一定會遇到 json_decode 時, php 把 uid 轉成 float 的情形, 大部分的情形只要把 uid 轉成 string 就能做其他的事了, 以下是正確的轉型技巧

$json = '{"uid":100000123456789}';
$arr = json_decode($json, true);
// $arr = array(1) {
//   ["uid"]=>
//   float(1.0000012345678E+14)
// }
$s2 = sprintf ( "%.0f", $arr['uid'] );
// $s2 = string(15) "100000123456789"