2010年6月30日 星期三

Apple Downloads

http://www.apple.com/downloads/macosx/

RHEL java 1.6安裝

#安裝JDK,目前最新版本是JDK 6 Update 17,請到此下載
http://java.sun.com/javase/downloads/index.jsp

#安裝JDK,回答完Yes的版權問題後, 開始自動解壓縮並安裝RPM

$ sh jdk-6u17-linux-i586-rpm.bin

#新增path在/etc/profile
$ vi /etc/profile

##JAVA Environment
export JAVA_HOME=/usr/java/jdk1.6.0_17
export JAVA_BIN=/usr/java/jdk1.6.0_17/bin
export JAVA_OPTS="$JAVA_OPTS -Xmx512M -Dcom.sun.management.jmxremote"
export PATH=$JAVA_HOME/bin:$PATH
#export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
export CLASSPATH=./:${JAVA_HOME}/lib:${JAVA_HOME}/jre/lib/ext

$ source /etc/profile
$ java -version

.htaccess / httpd.conf deny access to .svn directories



Order allow,deny
Deny from all

寄送 subversion repository 的更新通知

subversion 提供了一個很方便的 hook 功能,可以為對 repository 進行的動作設定相關的動作。詳細的作法請見 svnbook 第 5 章的 Hook Scripts 一節。這裡簡單筆記一下如何用 svn hook 作 repository 的 email 更新通知。



在 subversion repository 目錄裡面有 conf, dav, db, hooks, locks 等目錄。其中 hooks 目錄就是用來存放 hooks 的地方。總共有 5 種 hook:

start-commit: 在 commit 開始之前執行,常用來檢查使用者是否有權執行動作。
pre-commit: 在 transaction 完成而未真正 commit 之前執行,常用來檢查 commit 動作的有效性。可以在這個地方對 commit 時的 log 訊息進行要求。
post-commit: 在 transaction 完成而 commit 結束,建立了新的 revision 之後執行,常用來寄送 e-mail 通知訊息。
pre-revprop-change: subversion 的 revision property 並不會存入 repository,這個 hook 可以在 revision property 變更之前作一些處理,譬如把更新的資訊存到外部的紀錄檔裡面。
post-revprop-change: 用途與 pre-revprop-change 類似,但會在 revision property 變更之後執行。
看起來 hook 在 post-commit 上面最為合適。subversion 提供了 Perl 與 Python 的 email 寄送程式 commit-email.pl 與 mailer.py 。經我測試, commit-email.pl 在寄 email 的時候沒辦法正確處理 non-ascii log message,但 mailer.py 可以寄送 utf8 log message。此外, commit-email.pl 只接受命令列參數,但 mailer.py 則可以用設定檔進行比較多的組態。

Debian 把 subversion 提供的一些補充工具 (像 commit-email.pl 和 mailer.py) 包在 subversion-tools 裡面,請記得安裝。

首先要把 post-commit 打開,假設 $repo 是 repository 所在的目錄,那麼要先建立 $repo/hooks/post-commit 。該目錄下預設就有一個模板檔:

$ cd $repo/hooks
$ cp post-commit.tmpl post-commit
$ chmod a+x post-commit
這是一個 shell script。它不必然要是 shell script,只要是可執行檔即可 (可以用 Perl, Python 或 C 來寫)。原本它使用 commit-email.pl ,我們來把它改成 mailer.py :

#!/bin/sh
REPOS="$1"
REV="$2"
/usr/lib/subversion/hook-scripts/mailer/mailer.py commit $REPOS $REV
mailer.py 要有三個參數,第一個參數是 commit 與 propchange 兩者之一,指定用於 *-commit 或 *prop-change 時的 email 寄送。不過僅是這樣還不能運作,我們得在 $repo/conf 裡放好組態檔 mailer.conf 才行:

cp /usr/lib/subversion/hook-scripts/mailer/mailer.conf.example $repo/conf/mailer.conf
Note

直接執行 /usr/lib/subversion/hook-scripts/mailer/mailer.py 不給參數,就會秀出參數的說明。
我們必須設定組態檔裡 [general] 區塊裡的 mail_command 及 smtp_hostname (一般使用預設值即可),以及 [defaults] 區塊裡的 to_addr 。 to_addr 就是 email 要通知的地址,可以設很多個,其間用空白分隔。

[defaults] 區塊裡還有

commit_subject_prefix 可以用來設定 commit 時 email Subject: 的前飾詞
propchange_subject_prefix 設定 revision property 改變時的 email Subject: 前飾詞
範例:

[general]
diff = /usr/bin/diff -u -L %(label_from)s -L %(label_to)s %(from)s %(to)s
mail_command = /usr/sbin/sendmail
smtp_hostname = localhost
[defaults]
commit_subject_prefix = [repocommit]
propchange_subject_prefix = [repopropchange]
from_addr =
to_addr = my@email.address
reply_to =
generate_diffs = add copy modify
suppress_deletes = yes
如果不指定 from_addr 的話,From: 就會填入 committer 的使用者名稱。

摘自:http://blog.seety.org/everydaywork/2005/7/13/378/

2010年6月29日 星期二

CSS 去除list最上面的線 / 去除最右邊多餘的margin空間

去除list最上面的線


HTML


  • リストメニュー 1

  • リストメニュー 2

  • リストメニュー 3

  • リストメニュー 4

  • リストメニュー 5


CSS
ul {
_zoom: 1;
overflow: hidden;
}

ul li {
margin-top: -1px;
padding: 5px;
border-top: 1px dotted #999;
}

2010年6月28日 星期一

Mac OSX Leopard 快捷鍵

有人可以告訴我Leopard 好用嗎!~好用嗎!~~~好用嗎!~~~~~~~~
之前聽說有很多問題,(蘋果都還沒熟,愛吃呴!)
現在不知道情形如何!?
有衝動給他敗下去!

想不到我無聊到貼快速鍵了

ALL
Cmd-C 複製
Cmd-V 貼上
Option-移動 複製文件到新地址
Cmd-移動 移動並自動對齊
Cmd-Delete 刪除
Cmd-Option-移動 做替身(快捷方式)
Cmd-Shift-Delete 清空垃圾桶
Cmd-Shift-Option-Delete 強制清空垃圾桶
Tab 選定下一個項目
Shift-Tab 選定上一個項目
Return 執行預設動作
Escape 關閉對話框
Page Up 向上翻頁
↑ 選取上一個文件
Page Down 向下翻頁
↓ 選取下一個文件
Cmd-Shift-G 打開』前往文件夾』對話框
Cmd-. 關閉對話框


Exposé 和系統的快捷
F8 切換Space
Shift-F8 慢速切換Space
F9(預設設置) 使用 Exposé 顯示所有打開的視窗
F10(預設設置) 使用 Exposé 在某個應用程式中顯示所有打開的視窗
F11(預設設置) 使用 Exposé 隱藏所有打開的視窗並顯示桌面
Cmd-H 隱藏程式
Cmd-Option-H 隱藏其他程式
Cmd-Q 退出程式
Cmd-Shift-Q 退出所有程式並且登出用戶
Cmd-Option-Shift-Q 強制登出用戶
Cmd-Tab 切換到下一個應用程式
Cmd-Shift-Tab 切換到上一個應用程式
Cmd-移動 整理選單欄
按下 Option 鍵並點按一個視窗 切換視窗並隱藏當前視窗
按住 Option 並點按 Dock 圖示 切換到另一個應用程式並隱藏當前應用程式
按下 Control 鍵並點按該項 查看某個項的快捷(上下文)選單
將鼠標移到該詞上面,然後按 Cmd-Control-D 使用 Dictionary 查看對字詞在應用程式中的定義

沒有回應
Cmd-句號 [.] 停止程序
Cmd-Option-Escape 打開』強制退出』
電源鍵 關機
Cmd-Option-Shift-電源鍵 強制關機或重新啟動(在某些電腦上)
Cmd-Control-電源鍵 強制重新啟動


Finder
Cmd-點擊 標題 查看當前視窗的路徑
Cmd-雙擊 (文件夾上) 新視窗中打開文件夾
Option-雙擊 (文件夾上) 新視窗中打開文件夾並關閉當前視窗
Cmd-1 用圖示瀏覽
Cmd-2 用列表瀏覽
Cmd-Option-向右 箭頭 列表模式下顯示包含的目錄
向左 箭頭 列表模式下關閉選定目錄
Cmd-向下 箭頭 在圖示或列表模式下打開選定目錄
Cmd-Option-向下 箭頭 在圖示或列表模式下在新視窗打開選定目錄並關閉當前視窗
Cmd-Shift-Option-向下 箭頭 (慢速)在圖示或列表模式下在新視窗打開選定目錄並關閉當前視窗
Cmd-向上 箭頭 打開上一級目錄
Cmd-Option-向上 箭頭 打開上一級目錄並關閉當前目錄
Cmd-3 用分欄瀏覽
Cmd-4 用cover flow瀏覽
Cmd-Y 打開快速查看
Cmd-Option-Y 用幻燈片顯示
Cmd-Shift-H 打開用戶文件夾
Cmd-Option-Shift-向上 箭頭 聚焦桌面
Cmd-Shift-I 打開iDisk
Cmd-Shift-D 打開桌面
Cmd-Shift-C 打開』電腦』
Cmd-Shift-K 打開網絡
Cmd-Shift-A 打開應用程式
雙擊 標題 最小化視窗
Cmd-M 最小化視窗
Option-點擊 按鈕 應用到所有激活的視窗
按下並按住滾動條 快速瀏覽長文稿
按住 Option 鍵並點按滾動條 迅速在「滾動到當前位置」和「滾動到頁面」之間切換
Cmd-波浪符號 (~) 激活當前應用程式中的上一個或下一個視窗

Dock
移動 分割線 自定義Dock大小
Option-移動 分割線 調整Dock到合適大小
Control-點擊 顯示Dock快捷選單
Control-點擊圖示 顯示項目的快捷選單
Cmd-點擊 打開圖示所在文件夾
Option-點擊 切換並隱藏當前程式
Cmd-Option-點擊 切換並隱藏所有程式
Cmd-Option-移動 強製程式打開文件
Cmd-Option-D 顯示/隱藏Dock

啟動
*快捷鍵只能在啟動時使用
當您看到程序指示器(看起來像旋轉的齒輪)時,請按住左邊的 Shift 鍵。 防止自動登錄
聽到啟動音之後立即按住 Shift 鍵,然後當您看到程序指示器(看起來像旋轉的齒輪)時釋放該鍵。 以安全模式啟動(只
有必要的 Mac OS X 項被啟動, 一些功能和應用程式可能無法正常工作。)
在登錄屏幕上點按「登錄」按鈕之後,請按住 Shift 鍵。 防止登錄時打開「登錄項」和 Finder 視窗
C 從光盤啟動
N 從預設的 NetBoot 磁盤映像啟動
T 以目標磁盤模式啟動
Option 選擇啟動磁盤(在某些電腦上)
Cmd-X 使用 Mac OS X 而不是 Mac OS 9 來進行啟動(如果兩者均位於同一宗捲上)
按住鼠標鍵 推出可去掉的光盤
Cmd-Option-P-R 還原參數 RAM
Cmd-V 顯示詳細的狀態信息(詳細模式)
Cmd-S 以單一用戶模式啟動



Safari
Cmd-Option-F google搜索欄
Option-向上 箭頭 向上翻頁
Option-向下 箭頭 向下翻頁
Cmd-點擊 鏈接 在後台用新標籤打開
Cmd-Shift-點擊 鏈接 打開並激活新標籤
Cmd-Option-點擊 鏈接 打開新視窗
Option-點擊 Close 按鈕 關閉其他標籤
Cmd-Shift-] 選取下一個標籤
Cmd-Shift-[ 選取上一個標籤
Cmd-Shift-H 打開主頁
Cmd-Shift-K 切換』禁止彈出視窗'
Cmd-Option-E 清空緩存
Cmd-Option-R 不用緩存並刷新頁面
Cmd-F 查找
Cmd-M 最小化視窗
Shift-點擊 按鈕 慢動作動畫效果
Cmd-加號[+] 增大字體
Cmd-減號[-] 減小字體
Cmd-0 預設字體

Dashboard
使用這些快捷來處理 Dashboard 和 Dashboard widget。
F12(預設設置) 顯示或隱藏 Dashboard
Cmd-R 重新載入當前 widget
Cmd-等號 (=) 顯示或隱藏 widget 欄
Cmd-向左箭頭鍵,Cmd-向右箭頭鍵 滾動 widget 欄
注:要更改 Dashboard 的快捷,請選取「文件」>「系統偏好設置」,點按「Exposé & Spaces」,然後點按「Exposé」。


Front Row
您可以使用鍵盤來控制 Front Row 而無需使用 Apple Remote 遙控器。
Cmd-Esc (Escape) 打開 Front Row
Cmd-Esc 或 Esc 從打開的選單中關閉 Front Row
向上箭頭鍵,向下箭頭鍵 瀏覽選單和列表
Cmd-Esc 或 Esc 返回上一級選單
空格鍵或 Return 選擇選單或列表中的項
空格鍵或 Return 播放和暫停音頻或視頻
向上箭頭鍵,向下箭頭鍵 更改音量
向右箭頭鍵,向左箭頭鍵 前往下一個或上一個歌曲或照片
向右箭頭鍵,向左箭頭鍵 前往所播放 DVD 的下一章或上一章
右箭頭鍵,左箭頭鍵(按住按鈕) 快進或倒回歌曲、視頻或 DVD
在某些 Apple 鍵盤和便攜式電腦上,您或許也可以使用特定按鍵來更改音量和控制回放。


鍵盤導航
Control-F1 打開/關閉全鍵盤控制
Control-F2 聚焦選單欄
Control-F3 聚焦Dock
Control-F4 聚焦活躍視窗或下一個視窗
Control-F5 聚焦視窗工具欄
Control-F6 聚焦浮動視窗
Control-F7 在控制或文本框與列表之間移動
Control-F8 聚焦選單欄中的狀態選單
Cmd-Accent [`] 聚焦活躍應用程式的下一個視窗
Cmd-Shift-Accent [`] 聚焦活躍應用程式的上一個視窗
Cmd-Option-Accent [`] 聚焦視窗抽屜
Cmd-Option-T 顯示或隱藏字符調板

摘自:http://blog.roodo.com/woodwork/archives/5141295.html

2010年6月25日 星期五

Doctrine yaml table charset

MyCustomOptionRecord:
columns:
name: string
options:
collate: utf8_unicode_ci
charset: utf8

2010年6月23日 星期三

MacBook比較,那一款MacBook最適合你!

MacBook
我們最實惠的筆記型電腦
NT$34,900 起
進一步了解
立即購買
13 吋 MacBook Pro
適用於每個人的高效能筆記型電腦
NT$40,900 起
進一步了解
立即購買
15 吋 MacBook Pro
頂級行動運算高手
NT$61,900 起
進一步了解
立即購買
17 吋 MacBook Pro
終極行動工作室
NT$79,900 起
進一步了解
立即購買
MacBook Air
最輕最薄的 Mac 筆記型電腦
NT$53,900 起
進一步了解
立即購買

摘自:http://www.apple.com/tw/mac/whichmacbook/compare.html

2010年6月22日 星期二

Aptana安裝 & Checkout SOP

1.下載Aptana Studio3 Beta & Install
2.安裝PDT
「Help」->「Install New Software...」->「Work with --All Available Sites--」->「Programming Language」->安裝PDT
3.安裝Subclipse
「Help」->「Install New Software...」->「Add Site」* http://subclipse.tigris.org/update_1.6.x/->安裝所有subclipse套件
3-1.設定SVN
「Preferences」->「Team」->「SVN」->「SVN介面」->「SNVKit」
4.設定Workspace
「File」->「Switch Workspace」->「other」->「C:\Appserv\www」
5.右鍵->「New」->「PHP Project」->「UR資料夾」
6.在「UR資料夾」點右鍵->「New」->「Other」->「SVN」->「自SVN取回專案」->建立新的檔案位置->「UC SVN URL/urstyle/crontab」->「以工作區專案的方式取出」->專案名稱「urstyle_crontab」->「C:/AppServ/www/urstyle」->OK
7.在專案資料夾點右鍵->「Configure」->「Add PHP Support..」

封鎖Baidu Robot / Baidu Spider

在 .htaccess加上:
SetEnvIf User-Agent ^Baidu baidu
Deny from env=baidu

2010年6月21日 星期一

Smarty的使用的memcached做緩存處理

最新公司平台部门提出说smarty文件读取过于频繁,磁盘IO太大了。

查看了一些smarty的手册,支持 $cache handler func 可以自定义缓存处理函数
参见:http://www.itdoc.cn/manual/smarty/section.template.cache.handler.func.html
实例中给出了一个数据库封装了,read,write,clear三个动作。
这样使用memcache封装一下也很好实现的。
看了国外人写了一个先附上,他这边没有考虑分布式(如果需要自己完善一下)

function memcache_cache_handler($action, &$smarty_obj, &$cache_content, $tpl_file=null, $cache_id=null, $compile_id=null, $exp_time=null) {
// ref to the memcache object
$m = $GLOBALS['memcached_res'];

// the key to store cache_ids under, used for clearing
$key = 'smarty_caches';

// check memcache object
if (get_class($m) != 'memcached') {
$smarty_obj->trigger_error('cache_handler: $GLOBALS[\'memcached_res\'] is not a memcached object');
return false;
}

// unique cache id
$cache_id = md5($tpl_file.$cache_id.$compile_id);

switch ($action) {
case 'read':
// grab the key from memcached
$contents = $m->get($cache_id);

// use compression
if($smarty_obj->use_gzip && function_exists("gzuncompress")) {
$cache_content = gzuncompress($contents);
} else {
$cache_content = $contents;
}

$return = true;
break;

case 'write':
// use compression
if($smarty_obj->use_gzip && function_exists("gzcompress")) {
$contents = gzcompress($cache_content);
} else {
$contents = $cache_content;
}

// add the cache_id to the $key string
$caches = $m->get($key);
if (!is_array($caches)) {
$caches = array($cache_id);
$m->set($key, $caches);
} else if (!in_array($cache_id, $caches)) {
array_push($caches, $cache_id);
$m->set($key, $caches);
}

// store the value in memcached
$stored = $m->set($cache_id, $contents);

if(!$stored) {
$smarty_obj->trigger_error("cache_handler: set failed.");
}

$return = true;
break;

case 'clear':
if(empty($cache_id) && empty($compile_id) && empty($tpl_file)) {
// get all cache ids
$caches = $m->get($key);

if (is_array($caches)) {
$len = count($caches);
for ($i=0; $i<$len; $i++) {
// assume no errors
$m->delete($caches[$i]);
}

// delete the cache ids
$m->delete($key);

$result = true;
}
} else {
$result = $m->delete($cache_id);
}
if(!$result) {
$smarty_obj->trigger_error("cache_handler: query failed.");
}
$return = true;
break;

default:
// error, unknown action
$smarty_obj->trigger_error("cache_handler: unknown action \"$action\"");
$return = false;
break;
}

return $return;
}

这些还没有真正上线运行,不知道他更新是否及时,年后会考虑部署。

参考资料:
http://www.itdoc.cn/manual/smarty/section.template.cache.handler.func.html
http://swag.dk/swag/kode/
http://lists.danga.com/pipermail/memcached/2007-September/005218.html
http://www.smarty.net/forums/viewtopic.php?t=10115

摘自:http://hi.baidu.com/lnnujxxy/blog/item/f7f610039d757e83d43f7c23.html

2010年6月20日 星期日

[Debug]Joomla_1.5.18-Stable-Full_Package + VirtueMart_1.1.4-COMPLETE_PACKAGE.j15無法進入到Product Detail頁

解法:
修改/joomla/components/com_virtuemart/themes/default/templates/common/featuredProducts.tpl.php

href="purl(URL."index.php?option=com_virtuemart&page=shop.product_details&flypage=".$featured["flypage"]."&product_id=".$featured["product_id"]) ?>"
改成
href='purl(URL."index.php?option=com_virtuemart&page=shop.product_details&flypage=".$featured["flypage"]."&product_id=".$featured["product_id"]) ?>'

PHP MVC Framework Performance – Part 1

As part of my assessment of PHP MVC Frameworks which I blogged about in Choosing the best PHP MVC Framework I decided to do a compare performance of the various PHP MVC Frameworks I was considering. I did this using Apache Bench with ab -t 30 -c 10 http://testserver/framework/index.php as this is common and did the basic Hello World test where each framework just put out Hello World in an empty HTML document. Here are the results…

The test server was a Windows XP machine with T7200 2.00GHz CPU and 2GB RAM running WAMP with PHP 5.2.6, Apache 2.2.8. No opcache was used in this test altough that’s something I will probably use for another test.

The latest version of every framework was used and all features like DB access were disabled for the test to give a true comparison.

All tests were run 5 times and any results there weren’t around the average of other results were removed and the test run was repeated, to avoid skewing results.

It’s pretty pointless to provide figures in requests per second as every machine is different and everyone will hence get different results, but it makes a lot of sense to compare all frameworks against a common base. For that base I chose to use performance of raw PHP, which on my test machine did an average of 740 req/s. A test with a HTML test on the same machine did 850 req/s (so not a huge difference). I should also note that the exact file being requested was always used (e.g. index.php or index.html), as just referencing the directory further decreased performance because Apache had to work out which file to show for the directory index.

Here are the results:

Raw PHP - 740 req/sec – 100%
PHP Pro MVC 0.0.4 - 200 req/sec – 27%
DooPHP 1.2 – 170 req/sec – 23%
Yii Framework 1.1.1 – 130 req/sec – 18%
Kohana PHP 2.3.4 – 55 req/sec – 7.5%
CodeIgniter 1.7.2 – 38 req/sec – 5%
Zend Framework 1.10 – 24 req/sec – 3%
So what does this all mean, let’s analyse the results…

Firstly PHP Pro MVC is a minimalistic MVC framwork written as an example of how to write an MVC framework and is used by OpenCart (with some modifications). I used it in the comparison to get an understanding how how any sort of even a basic PHP framework would impact performance.

As claimed on their website DooPHP is indeed the fastest of the frameworks, but it’s nowhere near as fast as they claim to be as compared to other frameworks. I also wouldn’t recommend using it because it’s not very logically structured compared to some others. Speed isn’t everything.

Yii is also indeed quite fast and to my surprise was significantly faster than Kohana or Code Igniter! However I tested v1.1.1 and Yii Framework Performance Bencharks were done on version 1.0.2. As I’ve said before I quite like Yii Framework because it just feels natural and logical.

Kohana was a bit faster than Code Igniter but in the same ballpark. As I’ve also pointed out I think that Yii is better than Kohana because code completion in PHP IDEs doesn’t work with Kohana and that’s a major issue.

Code Igniter was a bit slower than I would have hoped it would be, but that’s understandable because of all the interoperability code that doesn’t really need to be there if you’re using PHP5 only. This is consistent with Kohana vs Code Igniter Perofmance results obtained by other people.

Zend Framework is the slowest of the lot, which is understandable given how heavy the framework is and how many files get loaded just to render a template from a controller. This is also something that’s been pointed out in tests by other people.

I didn’t bother testing Cake PHP or Symfony as it’s well know that they are even slower than Zend Framework.

Now, here’s something VERY IMPORTANT!

You can compare performance of frameworks on Hello World tests all you want, but in a real life situation the performance of your framework will be dwarfed into insignificance by the following 2 factors:

Database Access
File System Access
Database Access and File System Access are the two slowest operations there are so how quick the actual code runs matters very little. In fact, the reason why Zend is so much slower than others is because it splits the code between so many files and it’s not even the parsing that’s the biggest problem, but file access, as I was running without opcode caching. With opcode caching you can expect the performance to improve to a point where the performance difference between frameworks will be insignificant in comparison to database access operations.

So, based on all of this my recommendation are as follows:

Choose the framework that best suits your needs and don’t worry so much about raw performance (unless the framework is split between many many files and you’re not using opcode caching, in which case file system access becomes a limiting factor). You should consider other factors when about the PHP Framework as I’ve outlined in Choosing the best PHP MVC Framework.
Try to use opcode caching wherever possible to avoid file system access becoming a limiting factor.
Make sure you optimise your database performance (read queries and indexes) and try to minimise the number of database accesses (especially in loops) by using joins and retrieving multiple rows with a single query. This one thing will dwarf any difference you may see in PHP MVC Framework performance!

摘自:http://www.sheldmandu.com/php/php-mvc-frameworks/php-mvc-framework-performance-part-1

Bootstrapping modules in ZF 1.8 and up

Firstly we have to add a line to application.ini enable modules at the end of the [production] section:

File: myproject/application/configs/application.ini

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] = ""

摘自:http://akrabat.com/zend-framework/bootstrapping-modules-in-zf-1-8/

doctrine 中文亂碼

默認在數據庫插入數據庫的時候,如果是中文會產生亂碼.其實解決方法也很簡單,在正常的連接後設置一下Charset就行了.
$manager = Doctrine_Manager::getInstance();
$conn = $manager->connection(DSN, 'doctrine');
//加上下面的,並設置為utf8
$conn->setCharset("utf8");
$manager->setAttribute('model_loading', 'conservative');

摘自:http://www.liifei.com/?p=370

2010年6月16日 星期三

How to use VirtueMart fronpage as Joomla! frontpage

Sign into the admin area, go to Menu>mainmenu, unpublish the original "Home" menu item, click "New" at the top right, select "Component" and from the Component List on the left, select "VirtueMart". Be sure to name the new menu item "Home", or it will not work properly as Joomla considers the menu item "Home" to be the primary page no matter what it is actually linked to.

2010年6月8日 星期二

Choosing a PHP Framework Round 2: Yii vs Kohana vs CodeIgniter

It was over a year ago that I wrote the article that compares CodeIgniter and Kohana. Since then both CodeIgniter and Kohana have seen major progress with the release of CodeIgniter 1.7.0 and Kohana 2.3.

In December 2008, a new PHP framework called Yii has been released to the public with a stable 1.0. There were a lot of new PHP framework released in 2008, but Yii was one of the more recognised ones because:

The author, Qiang Xue, is the author of the well established PRADO framework.
It is a simple to use, well organised, PHP 5 only MVC framework.
It claims to have astonishing performance.
Before I start this round of comparison, let me briefly list my experience with these frameworks, so you may interpret this article with your own judgement.

CodeIgniter: I started using CodeIgniter since its version 1.2.x from a few years ago. During the past few years I have worked on projects mainly using version 1.5.x and 1.6.x. I have now stopped using CodeIgniter in favour of using other PHP 5 only frameworks.

Kohana: I first started using Kohana when it was called BlueFlame back when it was first forked out of CodeIgniter. Since then I have lurked and participated in the Kohana community. All of my recent projects are done in Kohana.

Yii: The 1.0 release of Yii had my attention, but I didn’t really dive into it until about now. However, most of my impressions on Yii are based on its documentation and this article by Daniel.

Let’s see how they compare with each other.

Same notes as before: Grading scale: Limited < Fair < Good < Excellent. If a feature is not available in the distributed package, but is available via 3rd party libraries, I will state that in the comparison. If a feature is available both in the distributed package and via 3rd party libraries, only the official one will get assessed.


Software releases used for this comparison are:

CodeIgniter 1.7.1
Kohana 2.3.1
Yii 1.0.3

Licensing

CodeIgniter Good

CI uses a modified, generally regarded as more restrict, BSD/Apache-style license.

Kohana Excellent

Kohana uses a new BSD license.

Yii Excellent

Yii uses a new BSD license.

PHP Compatibility

CodeIgniter

PHP >= 4.3.2 (including all versions of PHP 5)

At first glance, it seems that CI has the edge because it supports both PHP 4 and PHP 5. However, if you are familiar with OOP then you would know that a lot of compromises had to be made in order to offer PHP 4 support. This is one of the primary reasons some developers including myself avoid to use CodeIgniter.

Even if you decided to use CodeIgniter, I still strongly recommend you build your application using PHP 5 and proper OOP techniques.

Kohana

PHP >= 5.2.3

Yii

PHP >= 5.1.0

Supported Databases

CodeIgniter Excellent

MySQL
MySQLi
PostgreSQL
MSSQL
Oracle
SQLite
ODBC
Kohana Good

MySQL
MySQLi
PostgreSQL
MSSQL
PDOSqlite
*Note: Kohana devs have decided long ago NOT to use PDO. Kohana 3.0 is planned to offer support for PDO.

Yii Excellent

All the DBMS supported by PDO (PHP Data Object).

* Note: Support for Active Record is limited by DBMS. Currently, only the following DBMS are supported:

MySQL 4.1 or later
PostgreSQL 7.3 or later
SQLite 2 and 3
Community

CodeIgniter Excellent

CodeIgniter is blessed with a strong, active community that is friendly and helpful. CodeIgniter offers a forum, a bug tracker and a wiki.

Kohana Good

Kohana has a small but elite community. It offers a forum, Trac and IRC.

Yii Good

Yii is the youngest of the three, therefore has the smallest community, it is however growing rapidly as the framework itself gains more attention. Yii offers a forum, a project hosted at Google Code and a documentation section that supports user comments.

Documentation / User Guide

CodeIgniter Excellent

CodeIgniter is known for its excellent documentation. Its user guide is comprehensive, easy to follow and up-to-date. Every release of the framework contains a copy of the user guide too, in case you are maintaining more than one version of CodeIgniter applications.

Kohana Good

Kohana’s documentation has been improved since my last article. It now has coverage for most aspect of the framework. However, some parts of the documentation are out of date and sometimes incorrect.

I’ve been using Kohana for a long time now and I found the documentation sufficient and very helpful. It may not have the fine layout found in CodeIgniter’s user guide, but it certainly helps me track down features and usages.

Yii Fair

The documentation of Yii seems to be fairly well constructed even though I haven’t started using Yii. All new features or changed features are carefully documented so you know what is going on with the specific version of Yii you use. The API documentation is also very useful thanks to the fully documented code base. However, many features at this stage are not documented in the guide, you need to go through the API or the code base itself.

Tutorial / Sample Availability

CodeIgniter Good

CodeIgniter has a dedicated wiki page for all the tutorials, and you can dig around their forums to find more.

Kohana Good

Kohana has a dedicated page for tutorials, but is out-of-date. It also hosts a learning centre which unfortunately has not been updated since September 2008. You can still head over to their forums to find useful tutorials though.

Yii Good

Yii has a cookbook section that contains a selection of tutorials. As always, check their forums to find more.

MVC

All three frameworks use the MVC (Model-View-Controller) architecture.

CodeIgniter Yes

Apart from the standard MVC architecture, CodeIgniter also offers libraries, plugins, helpers and hooks.

Kohana Yes

Apart from the standard MVC architecture, Kohana also offers modules, events, libraries, helpers and hooks.

Yii Yes

Apart from the standard MVC architecture, Yii also offers components, modules, extensions, view widgets and helpers *.

* Helpers are undocumented but are referenced in the guide and in the API. All of the helpers can be found in the utils folder under the main framework directory.

Modularity

CodeIgniter via 3rd party libraries

CodeIgniter does not support modules out-of-box, but you may use 3rd party libraries such as HMVC or Matchbox to achieve similar effect.

Kohana Excellent

Kohana not only offers modules, but also has cascading file system which takes modularity to a higher level.

Yii Good

Yii 1.0.3 has added support for modules.

Conventions

Unlike CakePHP, all three frameworks offer flexible conventions. There are some defaults but most of them can be overwritten or configured.

Configuration

CodeIgniter Good

CodeIgniter has a fairly good configuration system.

Kohana Excellent

Kohana has an exceptionally well configuration system.

Quoted from the guide: The file structure of config files follows Kohana’s file structure. Meaning that configuration files in the application directory take precedence over those in modules which take precedence over those in the system directory. The one exception is config.php which is hardcoded into the application/config directory and cannot be moved elsewhere.

Yii Good

Yii has a fairly good configuration system.

Database Abstraction and ORM

Definitions: Database Abstraction, ORM

CodeIgniter Good

CodeIgniter has a very powerful database class. It offers query builders as well as database manipulation classes, however it has no built-in ORM support.

One important thing that needs clarification is that even though CodeIgniter has Active Record, it is NOT the same Active Record pattern people commonly refer to. CodeIgniter’s Active Record is merely a collection of query builders.

For ORM, please check out IgnitedRecord and DataMapper. Interestingly enough, despite their naming, IgnitedRecord uses the Data Mapper pattern and DataMapper uses the Active Record pattern.

Kohana Good

The most notable time saver during my project development has to be the ORM. Kohana offers a lightweight but useful ORM implementation. It’s not as sophisticated as the Rails Active Record module, but it does the job quite well. I especially love the ease of updating many-to-many records.

Yii Good

Yii has a more complex syntax for declaring model relationships than Kohana. However, it also offers more powerful features such as named scope, albeit the syntax is nowhere near as clean as Ruby on Rails’.

Auth and ACL

CodeIgniter via 3rd party libraries

CodeIgniter has a couple of 3rd party Auth and ACL libraries, please head over to their forums to find more.

Kohana Good

Kohana has a built-in Auth module and a number of 3rd party Auth and ACL libraries including my Authlite.

* A more complete Auth + ACL solution is being cooked for the 2.4 release. Check out Samsoir’s replies in this thread.

Yii Excellent

Yii has built-in support for both authentication and authorisation. As I have no first hand experience with Yii yet, I can only judge this feature from the documentation, by the look of it it’s fairly easy to use and flexible enough for most systems.

Validation

CodeIgniter Excellent

CodeIgniter’s form validation library.

Kohana Excellent

Kohana’s validation library.

Yii Excellent

Yii’s validation usage. All of the system validators can be found in the validators directory under the main framework directory.

Caching

CodeIgniter Limited

CodeIgniter only supports basic file system based page caching.

Kohana Good

Kohana offers a slightly more useful cache library that supports file, SQLite, APC, eAccelerator, memcache, and XCache based caching, with tag support.

Yii Good

Similar to Kohana’s implementation, Yii supports memcache, APC, XCache and DB based (default to SQLite) page and segment caching.

Session

CodeIgniter Good

CodeIgniter’s session class is fairly good, it supports database storing as well as handling flash data.

Kohana Good

Similarly to CodeIgniter, Kohana also offers a very good session library.

Yii Excellent

Yii provides a much more powerful and flexible session class. Unfortunately session at this stage is undocumented in the guide. Flash data is not part of the session classes but part of the Auth package.

Logging / Debugging

CodeIgniter Good

CodeIgniter has a basic error handling class and a profiler class.

Kohana Excellent

Kohana has a good logging class as well as a more flexible profiler.

Yii Excellent

Yii has a logging/profiling class that is just as powerful and flexible as Kohana’s.

Templating

All three frameworks encourage the use of native PHP for templating.

CodeIgniter alternative syntax available

CodeIgniter also provides an alternative template parser class.

Kohana alternative syntax available via 3rd party libraries

Kohana has no built-in alternative template syntax support. However, you can find some 3rd party ones such as Temper.

Yii alternative syntax available

Yii also provides an alternative template syntax borrowed from Prado.

Helpers

Helpers are usually libraries that used for simple, repetitive tasks.

CodeIgniter Excellent

CodeIgniter offers 21 built-in helpers.

Kohana Excellent

Kohana offers 19 built-in helpers.

Yii Limited

Yii offers 6 built-in helpers.

Bundled JavaScript Library

Bundling JavaScript does NOT mean you have to use the bundled JavaScript. In fact, I encourage the use of unobtrusive JavaScript than using the bundled classes.

CodeIgniter None

CodeIgniter has no bundled JavaScript library.

Kohana None

Kohana has no bundled JavaScript library.

Yii jQuery

Yii has jQuery bundled, and it provides a number of useful classes such as auto-complete.

Web Services

I recommend integrating Zend Framework for web service uses.

CodeIgniter Limited

CodeIgniter has an XML-RPC class.

Kohana None

Kohana has no built-in support for any web services.

Yii Limited

Yii has SOAP support.

Internationalisation

CodeIgniter Limited

CodeIgniter provides a basic language class.

Kohana Fair

Kohana provides basic locale and language support.

Yii Good

Yii provides a more complete i18n class.

Unit Testing

I recommend using SimpleTest or PHPUnit for your unit test needs.

CodeIgniter Limited

CodeIgniter has a very basic unit testing class.

Kohana None

Kohana has no built-in unit testing support in the distributed release version (v2.3.1). However, a unit test module can be found in SVN trunk.

Yii None

Yii has no built-in unit testing support.

The Verdict

Verdict from round 1: There is no right or wrong in which framework you use, everyone has his own taste. For me, CodeIgniter’s excellent documentation and Kohana’s strict PHP5 + easy to use are the primary reasons to choose them over say, CakePHP and Symfony. That said, CakePHP, Symfony and other frameworks are all excellent choices depending on your taste and experience. On one hand I envy the Ruby community because they obviously have the de facto framework to work with, on another hand, we have more options hey? :)

At this stage I can’t comment on Yii, but I am very tempted to developing at least one project using it. So far I am reasonably impressed by the features it offers. :)

Do you have anything to say about the frameworks? Found mistakes in the article? Start the discussion in the comments! :)

摘自:http://www.beyondcoding.com/2009/03/02/choosing-a-php-framework-round-2-yii-vs-kohana-vs-codeigniter/

ICONV強制轉碼

前一陣子在幫別人寫UTF8轉BIG5的時候,遇到衝碼轉不回BIG5的情形= =
以前遇到這種情形的時候,我記得會自動將無法轉碼的字元轉為??
而現在怎麼會全部不見,後來才發現要加一個參數,以前不會發生現在會,真怪,那就先記錄下來以後備查!

iconv("utf-8", "big5//IGNORE", $string);
//就是那個//IGNORE

摘自:http://phpwrite.blogspot.com/

2010年6月4日 星期五

Linux更新Server時間

echo "#Update Server Time
10 5 * * * root /usr/sbin/ntpdate tock.stdtime.gov.tw && /sbin/hwclock -w" >> /etc/crontab

2010年6月3日 星期四

透過 shell script 發送 email

如果想用 shell script 發送郵件,可以用 mail 實現:

# echo "email content" | mail -s "email subject" you@emaildomain
以上語句會發送一封標題為 "email subject" 的電郵到 you@emaildomain,其中 "email content" 為電郵內容。

以下簡單的兩行 shell script 便會將檔案系統使用量,透過電郵發送給指定的電郵信箱:

#!/bin/sh
/bin/df -h | /usr/bin/mail -s "server capacity" you@emaildomain

摘自:http://www.hkcode.com/linux-bsd-notes/444

Replacing Sendmail with Postfix on FreeBSD

The following steps can be used to replace sendmail with postfix on FreeBSD.

Notes:
These steps seem to work on FreeBSD 5.2.1. They should work on other versions as well.
The ports collection needs to be installed.
Steps:
Install postfix from /usr/ports/mail/postfix-current:

# cd /usr/ports/mail/postfix-current
# make install
The install will ask to create the postfix group and to enable postfix in /etc/mail/mailer.conf.

The updated mailer.conf(5) should look like the following:

#
# Execute the Postfix sendmail program, named /usr/local/sbin/sendmail
#
sendmail /usr/local/sbin/sendmail
send-mail /usr/local/sbin/sendmail
mailq /usr/local/sbin/sendmail
newaliases /usr/local/sbin/sendmail
Stop sendmail:

# /etc/rc.d/sendmail stop
Disable sendmail:

Disable starting sendmail on boot:

# echo 'sendmail_enable="NONE"' >> /etc/rc.conf
Disable building sendmail during buildworld:

# echo "NO_SENDMAIL=true" >> /etc/make.conf
Disable sendmail's daily cron jobs by putting the following /etc/periodic.conf:

daily_clean_hoststat_enable="NO"
daily_status_mail_rejects_enable="NO"
daily_status_include_submit_mailq="NO"
daily_submit_queuerun="NO"
Enable postfix:

# cd /usr/local/etc/rc.d
# ln -s /usr/local/sbin/postfix postfix.sh
Configure postfix. The following entries in the Postfix FAQ are useful:

Running Postfix inside an intranet
Delivering some users locally while sending mail as user@domain
Using Procmail for system-wide local delivery
Root's mail is delivered to nobody
Update the aliases db:

# /usr/local/bin/newaliases
Start postfix:

/usr/local/etc/rc.d/postfix.sh start

摘自:http://www.csua.berkeley.edu/~ranga/notes/freebsd_postfix.html

[教學] pure-ftpd 安裝組態設定

pure-ftpd 安裝組態設定

$ /usr/ports/ftp/pure-ftpd

先下載 source 及套用 patch

$ make patch

修正中文(許功蓋)的問題
轉載自 http://netlab.cse.yzu.edu.tw/~statue/freebsd/zh-tut/pure-ftpd.html

修改 /usr/ports/ftp/pure-ftpd/work/pure-ftpd-1.0.20/src/ftpd.c

搜尋
代碼:
while (*namepnt != 0) {
if (ISCTRLCODE(*namepnt) || *namepnt == '\\') {
return -1;
}
if (dot_ok == 0) {
if (*namepnt == '/') {
namepnt++;

改成 (即加上紅色的字)
代碼:
while (*namepnt != 0) {
#if 0
if (ISCTRLCODE(*namepnt) || *namepnt == '\\') {
return -1;
}
#endif
if (dot_ok == 0) {
if (*namepnt == '/') {
namepnt++;


讓 log 中直接顯示中文....不再經過編碼
轉載自 http://bbs.openfind.com.tw/cgi-bin/x_list?VAL=2174780829&BOARD=tw.bbs.comp.386bsd&DISPLEN=15&NO=17

修改 altlog.c
搜尋
代碼:
if ((quoted_filename = urlencode(filename)) == NULL) {
return -1;
}


改成
代碼:
/*
if ((quoted_filename = urlencode(filename)) == NULL) {
return -1;
}*/
quoted_filename = filename;


開始安裝,加上繁體中文(訊息)支援

$ make WITH_LANG=traditional-chinese install clean

代碼:
┌───────────────────────────────────┐
│ Options for pure-ftpd 1.0.20_1 │
│ ┌────────────────────────────────┐ │
│ │ [ ] LDAP Support for users in LDAP directories │ │
│ │ [ ] MYSQL Support for users in MySQL database │ │
│ │ [X] PAM Support for PAM authentication │ │
│ │ [ ] PGSQL Support for users in PostgreSQL database │ │
│ │ [ ] PRIVSEP Enable privilege separation │ │
│ │ [X] PERUSERLIMITS Per-user concurrency limits │ │
│ │ [X] THROTTLING Bandwidth throttling │ │
│ │ │ │
├─└───────────────────────────────┘─┤
│ [ OK ] Cancel │
└───────────────────────────────────┘


1. 組態 /usr/local/etc/pure-ftpd.conf
代碼:
# 使用者被鎖在登入的目錄中,不能切換到上一層
ChrootEveryone yes

# 同時可連線的人數
MaxClientsNumber 5

# 每一個來源 IP 同時可連線
MaxClientsPerIP 2

# 不顯示以 . 為啟始檔名的檔案
DisplayDotFiles no

# 不允許暱名登入
AnonymousOnly no
NoAnonymous no

# syslogd 中的 log 對象
SyslogFacility ftp

# 不反查 ip
DontResolve yes

# 發呆 15 分鐘後,自動斷線
MaxIdleTime 15

# 儲存 virtual user 的帳號、密碼檔 (通常路徑會定在與組態檔同一個目錄)
PureDB /usr/local/etc/pureftpd.pdb
--login=puredb:/usr/local/etc/pureftpd.pdb

LimitRecursion 2000 8
AnonymousCanCreateDirs no
MaxLoad 4

# 指定 Passive mode 所使用的埠號範圍
PassivePortRange 40000 40100

# 指定使用 Passive mode 時的連線 IP (在 NAT 後面的 FTP Server 必須使用)
# 此處的 IP 是 FTP Server 的對外 IP
ForcePassiveIP 61.62.128.140

#
AntiWarez yes

# FTP Server 的服務埠號 (如 Server 上有多張網卡,逗號前面可指定要服務的 IP)
Bind ,2100

# 檔案遮罩 (檔案:目錄)
Umask 133:022

# 可登入 FTP Server 的最小 UID
MinUID 100

# 是否允許使用 FXP Protocol
AllowUserFXP no
AllowAnonymousFXP no

# 是否允許讀寫以一點為啟始檔名的檔案
ProhibitDotFilesWrite no
ProhibitDotFilesRead no

# 是否允許檔案自動更名
AutoRename no

# 是否允許暱名登入者上傳檔案
AnonymousCantUpload no

# 最大的磁碟使用量
MaxDiskUsage 99

#
CustomerProof yes

#
PerUserLimits 1

2. 組態 /etc/syslog.conf,讓 FTP Server 的 log 獨立於 syslog

2.1
找到 /var/log/messages 的那一行
在前一行加入
代碼:
ftp.* /var/log/ftplog

2.2
新增一個空白 log 檔

$ touch /var/log/ftplog

2.3
重新啟動 syslogd (重新讀取組態檔)

$ killall -HUP syslogd

3. 在系統中新增一個 FTP 帳號一個 FTP 群組給 virtual users 使用

$ pw group add FTP -g 5001
$ pw user add FTP -u 5001 -c FTP_USERS -d /nonexistent -s /nonexistent

4. 新增 virtual user

$ pure-pw useradd ftp001 -u FTP -g FTP -d /ftp/root/folder/for/ftp001/here -m
$ pure-pw useradd ftp002 -u FTP -g FTP -d /ftp/root/folder/for/ftp002/here -m

代碼:
useradd:新增一位使用者
-u:uid
-g:gid
-d:登錄後的根目錄
-m:即刻更新使用者資料檔


5. 列出 pure-ftpd 資料庫中的所有帳號

$ pure-pw list


6. 列出某一位使用者 (ftp001) 的所有設定

$ pure-pw show ftp001


7. 為某一位使用者加上下載檔案的頻寬限制

$ pure-pw usermod ftp001 -t 20 -T 100 -m

代碼:
usermod:修改已存在使用者的設定
-t:從 Server 下載檔案的頻寬限制 (單位KB/s)
-T:上傳檔案到 Server 的頻寬限制 (單位KB/s)
-m:即刻更新使用者資料檔

摘自:http://www.backup.idv.tw/viewtopic.php?t=1294

2010年6月2日 星期三

DNS設定專用名詞

反解
Domain Name TYPE Record IP Address
blogger.com PTR mail MailIP

網域
Domain Name TYPE Record IP Address
blogger.com A www ServerIP

Google Mail
XXX.com.tw MX ASPMX.L.GOOGLE.COM. 優先權:1
XXX.com.tw MX ALT1.ASPMX.L.GOOGLE.COM. 優先權:2
XXX.com.tw MX ALT2.ASPMX.L.GOOGLE.COM. 優先權:2
XXX.com.tw MX ASPMX2.GOOGLEMAIL.COM. 優先權:3
XXX.com.tw MX ASPMX3.GOOGLEMAIL.COM. 優先權:3
XXX.com.tw MX ASPMX4.GOOGLEMAIL.COM. 優先權:3
XXX.com.tw MX ASPMX5.GOOGLEMAIL.COM. 優先權:3

YYY.com.tw MX ASPMX.L.GOOGLE.COM. 優先權:1
YYY.com.tw MX ALT1.ASPMX.L.GOOGLE.COM. 優先權:2
YYY.com.tw MX ALT2.ASPMX.L.GOOGLE.COM. 優先權:2
YYY.com.tw MX ASPMX2.GOOGLEMAIL.COM. 優先權:3
YYY.com.tw MX ASPMX3.GOOGLEMAIL.COM. 優先權:3
YYY.com.tw MX ASPMX4.GOOGLEMAIL.COM. 優先權:3
YYY.com.tw MX ASPMX5.GOOGLEMAIL.COM. 優先權:3

wibiya widget