Thursday, August 11, 2011

How to login with Administrator account in Thinkpad

単純にadminでログインしたいだけであれば以下の手順でできます。

  1. 「ユーザーアカウント制御設定の変更」からUACを無効化
  2. OS再起動
  3. コマンドプロンプトを起動し以下を入力
    net user administrator /active:yes
  4. 「ユーザーアカウント」にadminが出ることを確認

resource: http://bbs.kakaku.com/bbs/K0000092865/SortID=11470155/

Monday, August 08, 2011

jQuery file upload plugin: AjaxFileUpload

We can use AjaxFileUpload make a file upload process.

Basic usage:
function ajaxFileUpload()
{
  $.ajaxFileUpload({
    url:'upload.php',
    secureuri:false,
    fileElementId:'fileToUpload',
    data:{name:'logan', id:'id'},
    success: function (data, status) {
      alert($(data).text());
    }
  });
  return false;
}

Official Guide have more detail usage.

Wednesday, July 20, 2011

CentOS install Zend Server CE

Follow the official guide "RPM Installation (RHEL, CentOS, Fedora and OEL)" first.

I install Zend Server CE with "Manually Installing Zend Server" guide. But my Zend Server repository is downloaded from here, enter the Linux tab, download the "Zend Server (DEB/RPM Installer Script)" package. Use the "zend.rpm.repo" repository file.

Then, you can finish the installation with "yum install zend-server-ce-php-5.3"

Link the /usr/bin/php to /usr/local/zend/bin/php
ln -s /usr/local/zend/bin/php /usr/bin/php
Or use "ln -f -s /usr/local/zend/bin/php /usr/bin/php"

Troubleshooting:
1. "Cannot load /usr/local/zend/lib/apache2/libphp5.so into server"
    solution: close SELINUX, /etc/selinux/config >> SELINUX="disabled"

Sunday, June 26, 2011

在 Windows 版的 Zend Server CE 安裝 PEAR

在使用 ZendServer\bin\go-pear.bat 的時候, 會出現 phar...does not have a signature 的錯誤, 這時候只需要修改 go-pear.bat 的內容

original: %PHP_BIN% -d output_buffering=0 -d PEAR\go-pear.phar
change to: %PHP_BIN% -d output_buffering=0 -d phar.require_hash=0 PEAR\go-pear.phar

這樣就可以解決無法安裝 PEAR 的問題

PEAR 安裝完後, 如果有發生 Structures_Graph 的 library 找不到, 去 Pear 下載 Structures_Graph 的 package 回來放到 PEAR 的資料夾, 再執行下面幾個指令:

pear channel-update pear.php.net
pear upgrade pear

最後再 Zend Server CE 內設定 include_path 加入 pear 套件的路徑
如果 go-pear.bat 已經加好了, 就重新啟動 Zend Server 即可使用 pear 套件了

資料來源: http://katsande.com/installing-phpunit-for-php-5-3-on-zendserver

Friday, June 24, 2011

PHP DEBUG 工具 debug_print_backtrace

發現到兩個有用的 debug function
debug_print_backtrace 和 debug_backtrace

debug_print_backtrace() 的功用是將目前程式區塊呼叫的位置開始, 一層一層往上找呼叫的位置, 可以將程式 trace 到最一開始的進入點, 這樣的方式可以有效的找到整個程式是從那一段開始出錯的, Zend_Db 也有實作這樣的功能, 沒想到原來 PHP 裡就已經內建了

debug_print_backtrace() 和 debug_backtrace() 不同的地方在於, debug_backtrace() 是未被格式化的資料, debug_backtrace() 回傳的是一份矩陣的 trace 資料, 而 debug_print_backtrace() 回傳的是已經備格式化過的文字, debug_print_backtrace() 比較方便用來快速檢視, 但若是要寫 LOG 或其他用途, debug_backtrace() 是比較好的選擇

Tuesday, June 07, 2011

camelize and underscore

從 CakePHP 的 Inflector Class 裡頭找到這段的程式碼, 非常精簡地寫法!
/**
 * Returns given $lower_case_and_underscored_word as a camelCased word.
 *
 * @param string $lower_case_and_underscored_word Word to camelize
 * @return string Camelized word. likeThis.
 * @access public
 * @static
 */
function camelize($lowerCaseAndUnderscoredWord) {
  $replace = str_replace(" ", "", ucwords(str_replace("_", " ", $lowerCaseAndUnderscoredWord)));
  return $replace;
}
/**
 * Returns an underscore-syntaxed ($like_this_dear_reader) version of the $camel_cased_word.
 *
 * @param string $camel_cased_word Camel-cased word to be "underscorized"
 * @return string Underscore-syntaxed version of the $camel_cased_word
 * @access public
 * @static
 */
function underscore($camelCasedWord) {
  $replace = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $camelCasedWord));
  return $replace;
}