2007年12月26日 星期三

快樂製造機

吳金津 (中國時報 浮世繪 2007/09/22)

前幾天到內湖聽一場演講,讓我印象最深刻的是主講者朱平先生,分享如何讓自己做
個「快樂製造機」,

他談到他每天早晨都會去逛傳統市場,每天都會製造一些快樂給賣菜的老闆們。

比如他買了23元的菜,拿30元給老闆,說:「老闆,23元算25元,找我5元就好。」這些老闆們反應大致上有四種反應──

第一種:起初非常驚訝,之後非常開心地找了5元,說謝謝。
第二種:老闆堅持找7元,不佔客戶便宜,但老闆很開心。
第三種:是多送點蔥蒜,也很開心。
第四種:是最高竿的反應,「不然我幫你湊30元好了,一共是32元,算你30元就好。」

哇,真是高手,原本是要讓老闆佔便宜的,反過來卻讓客戶多買又有佔便宜的感受,更是個「快樂製造機」。

前日傍晚,我逛傳統黃昏市場時,決定玩一下朱先生的遊戲,暫時改了殺價習慣,想創造點快樂給老闆們。

我到一家以前常殺價、討斤兩的攤販前,買了157元的青菜,
結帳時,剛好聽到菜販老闆對旁人說了一個笑話,非常好笑,
我非常愉快地說:「老闆,你好幽默,你的笑話很好笑,157元算160元,這裡是160元,不用找了。」


老闆笑了,說:「這怎麼可以,不然妳還需要甚麼,我送妳。」
老闆便送我一大塊嫩薑。

後來到了另一家買甜不辣29元,拿30元給老闆,

我說:「阿伯,29元算30元,不用找了。」老闆有點訝異,一時之間反應不過來,還是找了1元給我,

我笑笑地把1元還給他,說不用找,他趕緊又多放了一塊甜不辣給我,從他驚訝轉而高興的表情,我知道我做到了。

回家的路上,我嘴角掛著微笑,哼著歌。睡前在日記裡寫下:「算一算,我多花了4元,賺到了甚麼?

1.賺到了好心情;
2.賺到了老闆的笑容;
3.賺到了老闆的謝意;
4.賺到了老闆的友誼;
5.賺到了一塊嫩薑和一塊甜不辣;
6.賺到了愉快的晚餐。」

當我們決心要當個「快樂製造機」時,就會感染對方,形成一個良性的影響,讓更多周遭的人像我們一樣,成為「快樂製造機」。

PHP wiki引擎在中文區域的流行度

根據百度收錄數量進行排序


名稱 收錄數量 檢測時間 運行環境 中文支援 版權 編輯器 備註
MediaWiki42.6萬 2006.12.31PHP+資料庫 優秀(UTF8 開源GPL wiki文本 影響最大的wiki程式
Drupal Wiki8.2萬 2006.12.31? ?  ? ? Drupal CMS系統的wiki模塊,支持MySQL或PostgreSQL。
TikiWiki4.6萬 2007.01.02? ?  ? ? CMS/Groupware -- 功能豐富完善的成熟wiki系統。 http://tikiwiki.org"
PukiWiki2.9萬 2006.12.31? ?  ? ? 在日本廣泛使用,易於安裝,特性豐富。用於XOOPS的插件版本稱為PukiWikiMod
DokuWiki2.9萬 2006.12.31? ?  ? ? 一個簡單的wiki程式,適合小公司的文檔需要。使用平面文字檔案存儲,無需資料庫。 http://www.splitbrain.org/dokuwiki/"
PmWiki2.9萬 2006.12.31? ? 開源GPL ? 具有版本記錄、群組功能的wiki程式,可以進行頁面和群組密碼保護。安裝簡單,定製容易,皮膚美觀。 http://www.pmichaud.com/pmwiki"
PhpWiki1.13萬 2006.12.31? ? 開源GPL ? 第一個公開發佈的php wiki程式,運行於relational資料庫上,平面檔,或者DBM。1999.12誕生。 http://phpwiki.org/"
CoWiki0.56萬 2006.12.31? ?  ? ? 遵循 loose wikis 的傳統,with easy and intuitional markup, 增加Unix式的訪問管理,目錄/文檔體系,以及plugin API for your functionalities and enhancements. All documents are parsed to XML for further export and transformation. coWiki是一個模塊化的程式,基於範本,支援多語言 ... 需要PHP5和MySQL
WikiX0.27萬 2007.01.02 ? ?  ? ? 基於PHP/MySQL/PostgreSQL的wiki程式。致力於讓用戶能夠重新定義語法,通過使用 wikiXmacros 和PHP plugin的各種 stages 來實現。 http://wikix.org/"
WakkaWiki0.26萬 2007.01.02 ? ?  ? ? 非常小巧的PHP/MySQL Wiki程式,安裝迅速,有頁面訪問控製表,完善的版本控制、頁面評論等。已不再維護。
Bitweaver0.20萬 2006.12.31? ?  ? ?  
GetWiki0.19萬 2006.12.31? ?  ? ? mediawiki的一個分支
WikkiTikkiTavi0.16萬 2007.01.02 ? ?  ? ? PHP/MySQL。
IWiki0.13萬 2006.12.31? ?  ? ?  
WikiDoc0.09萬 2007.01.02 ? ?  ? ? PHP/MySQL。開源,以wiki為基礎的文檔管理系統。
PWiki0.06萬 2006.12.31? ?  ? ? 可附加檔,有版本功能。運行於文件系統,無需資料庫 http://wiki.2gn.com/" 或 http://2gn.com/source.html"
Cardboard wiki0.05萬 2006.12.31? ?  ? ?  
YaWiki0.05萬 2007.01.02? ?  ? ? 重量級的PHP/PEAR wiki。基於一些新的PEAR庫(Auth, Benchmark, Cache_Lite, Date, DB, DB_Table, HTML_QuickForm, which itself depends on: HTML_Common, Var_Dump) http://wiki.ciaweb.net/yawiki/index.php?area=Yawiki&page=HomePage"
WikyBlog0.05萬 2007.01.02? ?  ? ? 強調簡單化,安裝時無需配置,不需要資料庫。 http://www.qwikiwiki.com/" PHP/MySQL 具有ajax增強的tab介面,支援google maps。 http://www.wikyblog.com"
QWiki0.04萬 2007.01.02? ?  ? ? 強調簡單化,安裝時無需配置,不需要資料庫。 http://www.qwikiwiki.com/"
WikkaWiki0.03萬 2006.12.31? ?  ? ? (110K) 輕量級PHP/MySQL wiki引擎,WakkaWiki的分支作品,註重速度、擴展形、安全等,有許多特性擴展和錯誤修訂。
ErfurtWiki0.03萬 2006.12.31? ?  ? ?  
MoniWiki0.03萬 2006.12.31PHP ? 開源GPL ? 幾乎完全相容於MoinMoin。英語、法語、韓語。RCS後臺。http://moniwiki.sourceforge.net/wiki.php"
WackoWiki0.02萬 2007.01.02? ?  ? ? WakkaWiki的一個分支,有英語、德語、俄語及更多翻譯,以及大量新的特性。
TipiWiki0.02萬 2007.01.02? ?  ? ? 系統簡單,安裝容易。alpha stage
UniWakka0.01萬 2007.01.02? ?  ? ? 一個WakkaWiki的分支。致力於提供科學類網站內容的協作和認證(authoring)工具。支持WikiFarm安裝、MathMl、腳註、內容表格、bibtex導入/導出、latex導出、latex類似的引用、openoffice導出等等。
Wiclear0.01萬 2007.01.02? ?  ? ? (http://wiclear.free.fr") -- PHP/MySQL下的wiki程式,開發中。具有 easy themability 支援,多語言支援,評論頁、ACL等等。
WikePage0.01萬 2007.01.02? ?  ? ? (http://www.cyrocom.com/") (~25K) -- 小巧的wiki程式,具有密碼保護模式或wiki模式,支援多語種,簡單的banner支援,支援表格、圖片加鏈接,支持CSS。使用平面檔系統存儲數據。
WikiNi0.0001萬 2007.01.02? ?  ? ? WakkaWiki的一個分支,法語。增加了一些新特性(頁面刪除、文字差異對比等)。
CoMaWiki0.000001萬 2006.12.31? ?  ? ? WakkaWiki的變種,有顯著變化
CoTeia0.00萬 2006.12.31? ?  ? ?  


摘自:http://www.allwiki.com/index.php?title=Php_wiki%E7%A8%8B%E5%BA%8F%E7%9A%84%E6%B5%81%E8%A1%8C%E5%BA%A6&variant=zh-hk

2007年12月25日 星期二

Using distinct and count with CakePHP

This post is the answer to Mandy Singh’s comment to the article Select distinct with CakePHP in which he asked how to use “count” with “distinct”. The answer I gave then — to use a custom query — works, but there exists a more Cake-like solution.

The obvious solution — using findCount() — doesn’t work, as there is no way to specify that you want to use “distinct”.

So to get the desired result we have to use a find() or findAll() statement as shown in the following example:

$this->User->find(null, "COUNT(DISTINCT User.city) AS 'count'");

Redirect with exit

If you do a redirect in CakePHP 1.1 you often have to add an exit() after the redirect statement to stop the script execution:

$this->redirect('controller/action');
exit();


Thanks to a small enhancement in CakePHP 1.2 in the form of an additional parameter for the redirect() function you can now do:

$this->redirect('controller/action', null, true);

It’s the same functionality as in the previous code snippet, but with the advantage that your code becomes testable (you cannot test a function which contains an exit(), as the exit() also stops the execution of the test).

Writing an installer for your CakePHP application

If you write an application which the user must install on his own server, you have to think about the installation process of your application. In this article I will describe the approach I have used in my application.

This approach is heavily inspired by the one used by WordPress. That means the user has to create the database and to define the database settings in app/config/database.php himself. When this is done, the user must run the installer, which then creates the tables and does some application-specific stuff like creating a default user.

The installer is a usual controller, which is automatically called when the user accesses the application for the first time. For this purpose I added a bit of logic to app/config/routes.php:

if (file_exists(TMP.'installed.txt')) {
// the routes for when the application has been installed
} else {
Router::connect('/:action', array('controller' => 'installer'));
}


So as long as there is no “installed.txt” file, the user gets the first page of the installer when he requests the url of the application. The consequence of this logic is that we have to create such a file at the end of the installation process (see below).

The installer controller itself is straight-forward, each action is one step in the installation process. You can find a minimal version of the installer below:

// app/controllers/
uses('model' . DS . 'connection_manager');


class InstallerController extends AppController {
var $uses = array();

function beforeFilter() {
if (file_exists(TMP.'installed.txt')) {
echo 'Application already installed. Remove app/config/installed.txt to reinstall the application';
exit();
}
}

function index() {
}

function database() {
$db = ConnectionManager::getDataSource('default');

if(!$db->isConnected()) {
echo 'Could not connect to database. Please check the settings in app/config/database.php and try again';
exit();
}

$this->__executeSQLScript($db, CONFIGS.'sql'.DS.'app.sql');

$this->redirect('/installer/thanks');
}

function thanks() {
file_put_contents(TMP.'installed.txt', date('Y-m-d, H:i:s'));
}

function __executeSQLScript($db, $fileName) {
$statements = file_get_contents($fileName);
$statements = explode(';', $statements);

foreach ($statements as $statement) {
if (trim($statement) != '') {
$db->query($statement);
}
}
}
}

It is a pragmatic solution with the drawback that it is not really reusable,..

wibiya widget