Jul 1st, 2009 by appleboy 參觀者:4,039Views 機器人:107Views
最近在寫 Perl 的程式,發現在正規比對的時候,print 出中文資料會出現 “Wide character in print at” 的 warning 訊息,在 google 找到一篇解決方法:Perl with UTF-8 mode,這篇提出的解決方法有很多種,comment 留言也有提供解法,可以去看一下,還蠻不錯的,那底下是我參考的解法:
只要在表頭加上:
use utf8
;
binmode(STDIN, ':encoding(utf8)');
binmode(STDOUT, ':encoding(utf8)');
binmode(STDERR, ':encoding(utf8)');
完整的檔案如下:
#! /usr/bin/perl -w
use Carp
;
use File
::Basename;
use LWP
::Simple;
use WWW
::Mechanize;
use LWP
::UserAgent;
use WWW
::Shorten '0rz';
use Getopt
::Std;
use DBI
;
use utf8
;
binmode(STDIN, ':encoding(utf8)');
binmode(STDOUT, ':encoding(utf8)');
binmode(STDERR, ':encoding(utf8)');
if($_ =~ m/\s*<div\s*class="title"><a\s*href=".+">(.+)<\/a><\/div>\s*/)
{
$pic_desc = $1;
print "desc: " .
$1 .
" \n" if $verbose;
}
Posted in Perl | No Comments »
Jun 26th, 2009 by appleboy 參觀者:7,353Views 機器人:205Views

Gallery 3.0 Beta 1 出來了,在 roga’s blog,看到這篇訊息,gallery 3 捨去 php smaty template engine,而改用 Kohana MVC Framework 這套 base on CodeIgniter 的 Framework,在 Gallery3:FAQ 裡面有提到為什麼會使用 Kohana 這套 MVC,gallery 團隊找尋了許多 MVC 的架構來幫助開發整個相簿系統,包含了 CakePHP、Zend Framework、Prado、Symfony、CodeIgniter,最後經過許多人的討論,選用了 Kohana 這套 MVC,原本打算考慮 CI 的,雖然 CI 支援 PHP4 跟 PHP5,以及它非常的小,對於效能方面也非常的好,但是並不支援 PHP5 的 exception,畢且有些少數的 Structure 只有支援 PHP4,所以就不被他們採納了,再來 Zend Framework 因為包含了 1705 個檔案,相當龐大,效能比 CI 少了 200-300%,雖然 ZF 文件相當豐富,不過沒有良好的 example 範例,所以導致 gallery 團隊遇到很多挫折,XDD。
最後選擇了 Kohana,雖然 Kohana 效能輸給 CI,不過這之間的差異極小,Kohana 也有 support PHP5 的 exception,Kohana 文件比 CI 還要少了些,不過對 gallery 團隊已經相當足夠了。底下有一篇各大 Framework 的效能比較:PHP framework comparison benchmarks,還有另一篇:Kohana vs CodeIgniter: Speed and Memory Usage Performance Benchmark
Posted in CodeIgniter, Zend Framework, php | No Comments »
Jun 20th, 2009 by appleboy 參觀者:9,007Views 機器人:211Views

最近想說幫之前替代役單位來把全文檢索的中文部份搞定,所以找了一些全文檢索的 open source,挑了這套網路上評價還不錯的 Sphinx,目前 Sphinx 支援的作業系統如下:
- Linux 2.4.x, 2.6.x (various distributions)
- Windows 2000, XP
- FreeBSD 4.x, 5.x, 6.x
- NetBSD 1.6, 3.0
- Solaris 9, 11
- Mac OS X
雖然上面寫 FreeBSD 只支援到 6.X,但是我測試是在 FreeBSD 7.1-RELEASE-p6 的環境,所以相當 ok 的,底下是我安裝在 FreeBSD 的心得筆記,PHP 官網上面有支援 Search Engine Extensions 的介紹,包含了 mnoGoSearch、Sphinx — Sphinx Client、Swish — Swish Indexing,可以利用 pecl 來安裝 Sphinx,目前版本:0.9.9-rc1。
Continue Reading »
Posted in FreeBSD, php | 1 Comment »
Jun 17th, 2009 by appleboy 參觀者:3,804Views 機器人:118Views
在 MySQL Performance Blog 裡面發現這篇:How to pretty-print my.cnf with a one-liner,利用一行 perl 指令把 my.cnf 的註解拿掉:
perl -ne 'm/^([^#][^\s=]+)\s*(=.*|)/ && printf("%-35s%s\n", $1, $2)' /etc/my.cnf
輸出為:
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
key_buffer = 256M
max_allowed_packet = 1M
table_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 16M
thread_concurrency = 8
log-slow-queries = /var/log/mysql/mysql-slow.log
當然同樣的,你也可以利用在 php.ini 或者是其他設定檔上面,提供我平常用 bash 指令來做的,只是沒有經過排版:
cat /usr/local/etc/php.ini | grep -v '^$' | grep -v '^[;]'
上面同樣的把空白行,以及開頭為 ; 的註解拿掉,同樣是可以做到。
Posted in mysql | No Comments »
Jun 16th, 2009 by appleboy 參觀者:2,144Views 機器人:64Views
驗證 form 表單屬於前端的工作,非常重要,避免使用者填錯格式,當然在 jQuery Plugin 可以找到專門驗證表單的外掛:jQuery plugin: Validation,此外掛不能相容於 IE 6,會沒辦法呈現效果,google 到一篇解決方法:Validating not happening in IE6 & no error removal on keyup,這篇裡面提到,必須使用 un-packed and un-minified 的版本,也就是沒有壓縮過的 javascript 檔案,不過我自己沒有試過就是了,底下針對表單的 checkbox select input radio 欄位做檢查的筆記,可以讓大家參考看看。
在 jQuery 1.3 裡面正式拿掉 [@attr] 的寫法,所以以前寫 $(”input:radio[@name=reg_sex]“) 都要改成 $(”input:radio[name=reg_sex]“),這樣才是正確的,可以參考 jQuery Selector 這篇的 Attribute Filters 部份,先來一篇網路上實做提示說明在 text 來未:jQuery: show plain text in a password field and then make it a regular password field on focus
作法很簡單:建立兩個輸入 password 的 text input 欄位:
<form>
<div>
<input class="default-value" type="text" name="email" value="Email Address" />
</div>
<div>
<input id="password-clear" type="text" value="Password" autocomplete="off" />
<input id="password-password" type="password" name="password" value="" autocomplete="off" />
</div>
</form>
Continue Reading »
Posted in jQuery | No Comments »
Jun 14th, 2009 by appleboy 參觀者:4,272Views 機器人:107Views
Posted in 生活日記 | No Comments »
Jun 11th, 2009 by appleboy 參觀者:4,811Views 機器人:215Views
Posted in www | No Comments »
Jun 9th, 2009 by appleboy 參觀者:2,889Views 機器人:83Views
我想這已經是網站最基本的技術,防止機器人大量註冊,或者是灌爆留言板,之前寫了兩篇製作認證碼的教學:[PHP]製作類似 google 網頁認證碼,[PHP] 好用的留言板 驗證碼 功能,這篇是要寫如何實做把第一篇教學整合到 CodeIgniter 系統裡面,來筆記一下,以後用到就相當方便了,CodeIgniter 在 path 路徑上面有小 bug,查了國外討論區發現了這篇 Path to CSS doesn’t work a second time,不過這並沒有解決我的問題,主機的網址是 http://xxxxx.xxx/path/,所有的 CI 檔案都是放在 path 目錄底下,包含圖片是 http://xxxxx.xxx/path/images/,在 View 裡面基本上只要寫 <img src=’/images/xx.gif’> 這樣就可以顯示圖片了,但是要改成 <img src=’/path/images/xx.gif’> 才能,但是我的 index.php 是放在 /path/ 裡面,以絕對路徑跟相對路徑來想,都是不太合理的,所以後來用 <img src=”<?=base_url();?>public/images/find.png” alt=”" /> 來解決,不過這是暫時的問題,我比較龜毛,喜歡寫短一點的 code。
如何裝上類似 google 的認證碼呢,首先打開 index.php 檔案
/* 算出 index.php 根目錄 */
define('Document_root',dirname(__FILE__));
Continue Reading »
Posted in CodeIgniter, php | No Comments »
Jun 6th, 2009 by appleboy 參觀者:5,860Views 機器人:188Views
最近在 Gmail Lab 看到發布了許多新功能,都蠻好用的,加速搜尋郵件內容,收件者,寄件者,郵件內容語言轉換,匯入其他郵件的通訊名單…等,進階搜尋是這之前就開發好得功能,可以在 search operators 這篇裡面找到相關的用法,簡單來說底下有個例子:
- “to:me is:starred” 搜尋寄信給您所標記的郵件
- “is:chat from:heather” 搜尋與heather使用者對話的內容
- “is:starred -in:inbox” 搜尋所有信件夾內未標記郵件
- “from:elliot filename:pdf” 搜尋 elliot 寄來信件附件檔帶有 pdf 檔案
上面例子看了很複雜吧,因為你還要記的很多相關的語法,才可以正確搜尋到,所以 google 很貼心的設計了 Search Autocomplete,之前我有寫一篇:New in Labs:Gmail search autocomplete 快速找尋使用者 email 跟附件檔案,造福了使用 Gmail 的大眾。
預覽收件夾這功能可以參考:New in Labs: Inbox preview,這功能用在當開啟 gmail 網頁時,會有 loading 的畫面,那針對速度慢得使用者,可以預先看到新的郵件標題,而不需要整個載入之後才看的到,目前還沒有遇到這種狀況,不過大家可以試試看。
郵件內容語言轉換(New in Labs: Automatic message translation),這功能相當不錯,可以利用 google translate tool 進行轉換您所想要的語言,如下圖:

蠻多好玩的功能,都可以去 Gmail Lab 去開起來喔,大家試試看吧
Posted in mail | No Comments »
Jun 2nd, 2009 by appleboy 參觀者:8,695Views 機器人:131Views

好久沒來寫篇美食了,最近吃了一家還不錯的焗烤飯,那就是在高雄市文化中心附近的拉斐爾,這間價位真的算可以投資的喔,還蠻便宜的,焗烤飯價位都介於 100~150 元之間,義大利麵也都在100元以下,加上 39 元就可以享用套餐系列喔,有烤麵包,飲料,濃湯。大家可以來這裡吃看看,除了一樓之外還有地下室可以用餐,地下室還蠻適合開同學會的,上面那張圖就是地下室的照片。

Continue Reading »
Posted in 高雄美食 | 1 Comment »