Jan 09
有安裝 Gallery 2 作為相簿系統的人可能跟我一樣,會在 Apache 的 error log 裡面看到一大串如下的 log:
PHP Notice: Undefined index: sfPhotosRecursiveLimit in [Gallery目錄]/modules/rss/SimpleRender.inc on line 78
追了一下程式,發現是變數沒處理好。
於是,我修改了 modules/rss/SimpleRender.inc,加了以下這段程式碼處理變數:
if ( !isset($params['sfPhotosRecursiveLimit']) ) {
$params['sfPhotosRecursiveLimit'] = $params['sfPhotosRecurseLimit'];
}
修改過後的某個片段長這樣:
$params['feedDate'] = $params['sfDate'];
if ( !isset($params['sfPhotosRecursiveLimit']) ) {
$params['sfPhotosRecursiveLimit'] = $params['sfPhotosRecurseLimit'];
}
/* apply defaults */
跟我一樣,覺得那些 log 很礙眼的,就參考一下吧。
我把 patch 一併貼到官方論壇了(Problem fix for RSS module),不知道會不會被採用就是了。
Technorati Tags: error, Gallery, RSS
Tags:
error ,
Gallery ,
RSS
(Visited 1577 times)
Jan 07
Javascript 提供了 For ... In ... ,我用的還蠻高興的(雖然我很少撰寫 Javascript)。
今天遇到某種特殊需求,我才發現這個迴圈語法並非萬能。
從 array 裡隨機挑出不重複的值有兩種情況,一種很單純,For ... In ... 迴圈可以處理的很好:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var x;
while(fruits.length > 0) {
var r = Math.floor( Math.random() * fruits.length );
var n = fruits[r];
document.write("Choosen[" + r + "]: " + n + "<br />");
document.write("Array: " + fruits + "<br />");
for(x in fruits) {
if (fruits[x] == n) {
fruits.splice(x, 1);
}
}
}
若是 array 裡面已經存在重複的值,而且 array 的資料的來源不方便控制(例如是 HTML 裡面的 li 物件),For ... In ... 這種方便的迴圈語法就必須放棄,改用傳統的 for 迴圈:
var fruits = ["Banana", "Banana", "Orange", "Orange", "Banana", "Apple", "Apple", "Orange", "Mango"];
var i=0;
while(fruits.length > 0) {
var r = Math.floor( Math.random() * fruits.length );
var n = fruits[r];
document.write("Choosen[" + r + "]: " + n + "<br />");
document.write("Array: " + fruits + "<br />");
for(i=0; i<fruits.length; i++) {
if (fruits[i] == n) {
fruits.splice(i, 1);
i--;
}
}
}
Technorati Tags: array, For loop, Javascript, random
Tags:
array ,
For loop ,
Javascript ,
random
(Visited 2035 times)
Jan 04
前陣子,在工作上剛好需要對 wav 檔案格式進行判定,可是 NAudio 製作出來的格式用來作判斷又有錯誤,所以土法煉鋼寫了一個小 class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
public class Wave
{
public struct Format
{
public String FileName = String.Empty;
public Boolean PCM = false;
public uint Channel = 0;
public uint SampleRate = 0;
public uint BitsPerSample = 0;
public uint ByteRate = 0;
public uint BlockAlign = 0;
};
private Format _fmt;
private void fillUp()
{
_fmt.ByteRate = _fmt.Channel * _fmt.SampleRate * _fmt.BitsPerSample / 8;
_fmt.BlockAlign = _fmt.Channel * _fmt.BitsPerSample / 8;
}
public Format getType(String fileName)
{
_fmt.FileName = fileName;
try
{
FileStream fs = File.OpenRead(@fileName);
Byte[] readTmp = new Byte[36];
fs.Read(readTmp, 0, 36);
fs.close();
if (BitConverter.ToUInt16(readTmp, 20) == 1)
{
_fmt.PCM = true;
}
_fmt.Channel = BitConverter.ToUInt16(readTmp, 22);
_fmt.SampleRate = BitConverter.ToUInt32(readTmp, 24);
_fmt.BitsPerSample = BitConverter.ToUInt16(readTmp, 34);
fillUp();
}
catch (Exception e)
{
Console.WriteLine("Wave.getType(fileName) Error : " + e.ToString());
}
return _fmt;
}
}
- 檢查 FileName 是否為空字串,就知道是否成功呼叫 getType() 。
- 檢查 PCM 是否為 true,就知道該檔案是不是 PCM 格式的 wav 檔。
- wav 檔播放的時間會等於 ByteRate。
Technorati Tags: .NET, Audio, C#, file, NAudio, PCM, wav
Tags:
.NET ,
Audio ,
C# ,
file ,
NAudio ,
PCM ,
wav
(Visited 1770 times)
Dec 10
我們在開發 PHP 專案時,時常會把一些常用變數放在某個 PHP 檔案,接著用 require()、require_once()、incluce()、include_once() 等函式將之引入。
若系統目錄很複雜,就會在很多檔案裡面看到類似這樣的語法:
require_once('../../Config.php');
然而,當這種系統必須變動目錄結構與檔案所在目錄時,開發人員就得額外多花些時間來更改上述之程式碼。
其實,PHP 的設定檔中,有個很少被注意到的變數,就是 auto_prepend_file 。
假設目前有個 PHP 專案,專案根目錄之系統絕對路徑為 /var/www/html/Project,
共用設定檔為 /var/www/html/Project/Config.php 。
我們可以在 /var/www/html/Project 下建立 .htaccess 檔案,內容如下:
php_value auto_prepend_file "/var/www/html/Project/Config.php"
而 /var/www/html/Project 目錄下所有的檔案,以及所有子目錄中的檔案都會自行引入 /var/www/html/Project/Config.php 。
PS. 由於 auto_prepend_file 的設定是透過 require() 來實作,使用這種方法要特別注意以下兩點:
- 一旦設定了 auto_prepend_file ,該檔案就必須要存在,否則就會有 error ,導致該目錄下的所有 PHP 檔案無法正常執行。
- include_path 會影響 auto_prepend_file。
Technorati Tags: auto_prepend_file, htaccess, include, include_once, PHP, php_value, require, require_once
Tags:
auto_prepend_file ,
htaccess ,
include ,
include_once ,
PHP ,
php_value ,
require ,
require_once
(Visited 2754 times)
Oct 11
這是我的第一個 C# Windows Form 程式。
執行畫面:

使用方法:
- 點選 Browse 按鈕,選擇並輸入 reg 檔存放位置與檔名。
- 點選 Backup 按鈕就能將 putty 的登錄檔輸出。
下載:
Downloads: 172 File Size: 0.0 KB
Technorati Tags: backup, C#, putty, registry, Windows Form
Tags:
backup ,
C# ,
putty ,
registry ,
Windows Form
(Visited 3358 times)
Oct 08
最近在玩 C#,寫個小軟體。
不過,我發現我產生出來的 exe 檔就是很醜,看起來的感覺就好像是病毒檔... 
用 MSDN 跟上網搜尋,solution 也不算好找,所以寫這篇順便幫自己紀錄一下。
Windows Form 有兩種圖示可以設定:
- Form 的圖示:只要在 Form 的屬性中,更改 Icon 屬性的 Value 就好,設定的圖示會顯示在執行的視窗的左上角。
- Application 的圖示:在 Visual Studio 2008 中,最上方工具列的 專案 -> [專案名稱]屬性,開啟的分頁中的 應用程式 有個 圖示與資訊清單 項目。在此便可設定軟體圖示。
By the way,我覺得目前寫這個小軟體應該還算實用,寫完後再丟上來~
Technorati Tags: icon, Visual Studio, Windows Form
Tags:
icon ,
Visual Studio ,
Windows Form
(Visited 3624 times)
Sep 27
以下是在 PTT 的 PHP 板看到某篇文章後的心得,以及小小的經驗分享。
對 Smarty 稍有經驗的人,應該都知道樣板內可使用 {include} 這個 tag 來嵌入其他 template file。
然而,因為 Smarty 內的變數都是全域變數,所以我對這個 tag 的看法是「能不用,就不用」。
用常見的網站論壇系統舉個簡單的例子:
若 B 設計師在其 template file 中使用了 {include} 來嵌入 A 設計師的 template file,就可能會產生預期之外的顯示結果。
當然,若是開發團隊已事先溝通好各項變數的命名,就不會有這種情況。
但為了減少此類風險,降低 debug 的難度,我們會選擇使用這種方式:
- 在系統全域共用的函式檔案中增加負責顯示 HTML header 的 function,例如 function page_header($title) { ...} ,並在 function 中 assign 變數,引入 A 設計師開發的 template file。
- 在論壇文章內容顯示的程式檔中,呼叫 page_header($title),再 assign 文章標題的變數,引入 B 設計師開發的 template file。
當然,若嵌入的 template file 內沒有任何變數,就不須考量以上的狀況,開發/設計人員可以大膽地隨意使用。
Technorati Tags: include, PHP, Smarty
Tags:
include ,
PHP ,
Smarty
(Visited 3740 times)
Sep 09
昨晚,有個學長透過 MSN 問我有無簡單好用的 PHP 圖形驗證碼,又讓我想到 reCAPTCHA。
上一次使用時,reCAPTCHA 僅提供顏色變更;如今,reCAPTCHA 已經開始支援多國語言了。
剛才稍微玩了一下,寫了這個簡單的網頁。
reCAPTCHA 的多國語言化相關資訊可以參考 這裡,而我使用的中文化程式碼片段為:
<script type="text/javascript">
var RecaptchaOptions = {
custom_translations : {
visual_challenge : "取得圖形驗證碼",
audio_challenge : "取得音效驗證碼",
refresh_btn : "重新整理圖形",
instructions_visual : "輸入兩個英文單字:",
instructions_audio : "輸入您聽到的聲音:",
help_btn : "獲得協助",
play_again : "重新播放音效",
cant_hear_this : "將音效下載為 MP3",
incorrect_try_again : "錯誤! 請再試一次"
}
};
</script>
Technorati Tags: CAPTCHA, il8n, localization, PHP, reCAPTCHA
Tags:
CAPTCHA ,
il8n ,
localization ,
PHP ,
reCAPTCHA
(Visited 4283 times)
Sep 04
以往我撰寫 PHP 的兩個工具是 vim 跟 jEdit(vim 比較常用)。
當時會選 jEdit 是因為 jEdit 提供了 FTP 遠端存取的功能,更改或新增的程式檔可以自動上傳到遠端主機。
昨天在 PTT 的 PHP 板看到有人提到 Aptana Studio,今天想到就抓來玩看看。
令我驚豔的是,Aptana Studio 也提供了遠端存取的功能,包括 FTP、FTPS、SFTP,以及各種版本控制系統。
不過,試了一下之後,發現它沒有辦法自動讓更改或新增的程式檔上傳到遠端主機,只能儲存後,再手動作 upload。
在網路上搜尋解決方法後,我卻發現工具列上的 Scripts -> Synchronize -> Upload Current File On Save 是壞掉的。
在即將放棄使用 Aptana Studio 時,我發現了 這個討論串,而且也順利解決自動上傳的問題。
討論串的內容有點亂,所以把解法整理在這邊,順便幫自己留個備份(以免以後又要找解法):
- 在 Aptana Studio 安裝的資料夾找出 upload_current_file_on_save.js 這個檔案,並編輯它。
- 在 header 的部份補上這兩行:
Listener: commandService().addExecutionListener(this);
Key: M1+S
補完之後的 header 大概像這樣:
/* Listener: commandService().addExecutionListener(this);
* Currently an example script (disabled)> Copy as your own script, and modify
* the Listener command as shown below
*
* Menu: Synchronize > Upload Current File On Save
* Key: M1+S
* Kudos: Ingo Muschenetz
* License: EPL 1.0
* DOM: http://localhost/com.aptana.ide.syncing.doms
* DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.eclipsemonkey.lang.javascript
*/
- 在檔案最後面補上這段:
function main() {
sync.uploadCurrentEditor();
}
- 存檔並重新執行 Aptana Studio。
之後只要按下 Ctrl + s 儲存檔案,該檔案就會自動上傳到遠端主機囉。
Technorati Tags: Aptana
Tags:
Aptana
(Visited 4170 times)
Jul 18
這兩天在處理 RoundCube 的郵件中文夾檔問題。
原本覺得情況很詭異,因為 Firefox 都很正常,可是 IE 有這兩種狀況:
- 直接以左鍵點選,中文檔名的附帶夾檔無法下載。
- 以滑鼠中鍵(開新的 Tab),就正常了。
坦白說,RoundCube 的程式架構實在很難摸,所以追了蠻久的..
我幫忙追問題的 RoundCube 版本是 0.1-STABLE 。
最後追到的解法是去修改 program/steps/mail/get.inc , diff -u 生出來的檔案內容是這樣:
--- program/steps/mail/get.inc.orig 2008-07-18 02:01:46.000000000 +0800
+++ program/steps/mail/get.inc 2008-07-18 15:45:37.000000000 +0800
@@ -106,9 +106,19 @@
}
else
{
- header(sprintf("Content-Disposition: %s; filename="%s";",
+ $HTTP_USER_AGENT = $_SERVER["HTTP_USER_AGENT"];
+
+ if (strstr($HTTP_USER_AGENT, "compatible; MSIE ") !== false &&
+ strstr($HTTP_USER_AGENT, "Opera") === false) {
+ header(sprintf("Content-Disposition: %s; filename="%s";",
+ $_GET["_download"] ? "attachment" : "inline",
+ $part->filename ? rawurlencode(abbreviate_string($part->filename, 55)) :
+ rawurlencode("roundcube.$ctype_secondary")));
+ } else {
+ header(sprintf("Content-Disposition: %s; filename="%s";",
$_GET["_download"] ? "attachment" : "inline",
$part->filename ? abbreviate_string($part->filename, 55) : "roundcube.$ctype_secondary"));
+ }
// turn off output buffering and print part content
$IMAP->get_message_part($MESSAGE["UID"], $part->mime_id, $part, true);
關鍵就在... 給 IE 吃的話,要先用 rawurlencode() 處理一遍。
Technorati Tags: IE, RoundCube
Tags:
IE ,
RoundCube
(Visited 8984 times)
Recent Comments