歡迎來到小豬圈!

2009-12-19

終於把陽台的欄杆鋸掉了

  • 第一次用砂輪機,習慣了就沒那麼可怕。
  • 鋸沒幾根老爸就搶著接手,老爸動作起級豪邁的,完全不怕破片的樣子,超猛。

2009-12-03

DNS 查詢除了走 UDP 外,還有 TCP 協定!

  • 如題,寫這篇是因為我用的 COMODO Firewall 裡,預設的規則是僅限走 UDP 的 DNS 查詢。

Win XP 小技巧

  • http://www.sysinternals.com/
  • fsutil.exe
  • NTFSDOS Professional 5.0
  • 修改 C:\WINDOWS\inf\sysoc.inf 把 hide 刪掉
  • tasklist /SVC
  • Gpedit.msc
  • msconfig
  • set devmgr_show_nonpresent_devices=1
  • HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders 改變預設目錄
  • RunDll32 advpack.dll,LaunchINFSection %windir%\INF\msmsgs.inf,BLC.Remove

2009-11-30

便利箱真方便

2009-08-11

Array 、 ArrayAccess 與 ArrayObject

  • PHP5 有提供 ArrayAccess Interface 讓自製的 Classes/Objects 也有如陣列 (Array) 型別用 [] 取存方式。 SPL 也有實作 ArrayObject 。
  • 但有一個關鍵的差異是新增陣列項目,一般陣列在無鍵值時是新增一個鍵值為最大整數的項目,鍵值為 null 時則新增一個鍵值為空字串的項目,自製物件是分不出兩者的差異的(無鍵值與 null 都視為 null)。請看下面範例:
    
    <?php
    class ArrayAccessObject implements ArrayAccess{
      private $position 0;
      private $_array = array();
    
      /* impements ArrayAccess */
      public function offsetSet($offset$value) {
        var_dump($offset);
        $this->_array[$offset] = $value;
      }
      public function offsetExists($offset) {
        return isset($this->_array[$offset]);
      }
      public function offsetUnset($offset) {
        unset($this->_array[$offset]);
      }
      public function offsetGet($offset) {
        return isset($this->_array[$offset]) ? $this->_array[$offset] : null;
      }
    }
    
    $a = array();
    $b = new ArrayObject();
    $c = new ArrayAccessObject();
    
    $a[] = 'nothing';
    $b[] = 'nothing';
    $c[] = 'nothing';
    
    $a[null] = 'null';
    $b[null] = 'null';
    $c[null] = 'null';
    
    
    var_dump($a);
    var_dump($b);
    var_dump($c);
    
    /* output */
    
    NULL
    NULL
    array(2) {
      [0]=>
      string(7"nothing"
      [""]=>
      string(4"null"
    }
    object(ArrayObject)#1 (1) {
      ["storage":"ArrayObject":private]=>
      array(2) {
        [0]=>
        string(7"nothing"
        [1]=>
        string(4"null"
      }
    }
    object(ArrayAccessObject)#2 (2) {
      ["position":"ArrayAccessObject":private]=>
      int(0)
      ["_array":"ArrayAccessObject":private]=>
      array(1) {
        [""]=>
        string(4"null"
      }
    }
    
    
    

2009-08-03

base_convert 的限制

  • 剛稍微測試 PHP 函數 base_convert() ,數字約大於 2^54 以上轉換就會出現錯誤。
  • 2009-08-06 更新:數字超過十進位的 9,007,199,254,740,992 即 2^53 以上,轉換就會出現錯誤。
  • 2009-08-09 更新:MySQL 有提供相同功能的函數 CONV(),文件指出最大值為 2^64 (十進位的 18,446,744,073,709,551,615,輸入大於這個值都會傳回相同於這個值的結果),目前測試轉換沒有問題。另外有一點差異是輸出結果為英文大寫字母。

2009-08-01

Apache HTTPD 預設的 .ht* 小技巧

  • httpd.conf 預設都有下列這一段,避免 .ht 開頭(無檔名)的檔案被讀取
    #
    # The following lines prevent .htaccess and .htpasswd files from being 
    # viewed by Web clients. 
    #
    <FilesMatch "^\.ht">
        Order allow,deny
        Deny from all
        Satisfy All
    </FilesMatch>
  • 雖然從網址無法存取,但依然可以從程式讀取。利用這一點,可以將設定檔取為 .htconfig 之類的。

2009-07-26

在 Windows 下編譯 Sphinx PHP 擴充模組

  • PECL :: Package :: sphinx 下載的原始碼,還無法直接編譯,從 config.w32 看來還需要 libsphinxclient.lib 和 sphinxclient.h。
  • 雖然從 Sphinx 中 (在原始碼的 api\libsphinxclient 目錄裡) 自行編譯了 libsphinxclient.lib ,但還是派不上用場。
  • 後來是修改了 config.w32 ,把這行:
    EXTENSION("sphinx", "sphinx.c");
    改寫成
    EXTENSION("sphinx", "sphinx.c sphinxclient.c");
    加在一起編譯才成功的。
  • Sphinx PHP Extension 似乎沒辨法編成獨立的 DLL 檔。將上述那行加上第三個參數為 true 就行了:
    EXTENSION("sphinx", "sphinx.c sphinxclient.c", true);
  • Sphinx 原始碼也有提供 PHP 腳本版本的 API (api/sphinxapi.php) ,直接 include 即可。

2009-07-25

Sphinx 全文檢索引擎

  • Sphinx 0.9.8.1 加上 MySQL 5.1 在建立索引時會出現 column number 1 has no name 的錯誤訊息,改用目前最新 Sphinx 0.9.9 就行了。
  • 安裝成 Windows Service 時要明確指定 sphinx.conf 的路徑:
    searchd.exe --install --config C:\sphinx\sphinx.conf --servicename SphinxSearch
    不然會無法啟動並出現 service terminated unexpectedly 錯誤訊息。
  • 另外也要記得建立 log 、 query_log 、 pid_file 所指定的目錄。

  1. 下載 Sphinx 並壓縮至 C:\sphinx
  2. 依 sphinx.conf.in 或 sphinx-min.conf.in 編輯設定檔,並另存為 sphinx.conf 。
  3. 將工作目錄移至 cd \sphinx\bin
  4. 安裝成 Windows Services
    searchd.exe --install --config C:\sphinx\sphinx.conf --servicename SphinxSearch
  5. 建立索引
    indexer.exe --config C:\sphinx\sphinx.conf --all
  6. 測試搜尋,假設搜尋目標為 target-word
    search.exe --config C:\sphinx\sphinx.conf --any target-word
  7. 若要移除 Windows Services
    searchd.exe --delete --servicename SphinxSearch

2009-07-24

在 Windows 上自行編譯 PHP

  • 自行編譯 PHP 比想像中簡單多了,PHP wiki 已經整理的很完善。文末的編譯步驟是從 PHP 文件 (PHP: Building from source - Manual) 提供簡易指南中,依我個人情況修改而來。
  • 比較麻煩的地方是要收集 Library 與 Header 檔,像 Apache httpd 得選自訂安裝才有附那些檔案。「PHP: internals:windows:libs [PHP Wiki]」這裡整理了大部份的檔案。
  • 我初次編譯使用的是 Windows SDK for Windows Server 2008 and .NET Framework 3.5 ,在執行 nmake 時出現下列錯誤訊息
    "" -h win32\ -r ..\Release_TS\ -x ..\Release_TS\ win32\build\wsyslog.mc
    '-h' is not recognized as an internal or external command,
    operable program or batch file.
    查看 Makefile 發現是少了 MC - Message Compiler (MC.exe) 這個東東,“mc.exe is missing in the Visual Studio 2008 Express SDK | Microsoft Connect”這篇指出似乎是該版本的 Windows SDK 沒附的關係。
  • browscap.c 出現幾個 § (section sign) 符號造成編譯中斷,用 Firefox 瀏覽後轉存即可(我遇到?字元的問題都是這樣解決的)。

  1. 下載並安裝 VC ,Microsoft Visual C++ 2008 Express Edition
  2. 下載並安裝 Windows SDK ,Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1: RC
  3. 複製 C:\Program Files\Microsoft SDKs\Windows\v7.0\Include\WinResrc.h 並更名為 winres.h 到同一目錄下。舊的文件有這條項目,似乎是用來解決某些問題,但我並沒有遇到就是了。
  4. 建立一個工作目錄,這裡以 C:\php-sdk 為例。
  5. 下載 PHP 原始碼並解壓縮至 C:\php-sdk ,這裡以 php-5.3.0 為例。
  6. 下載 http://pecl2.php.net/downloads/php-windows-builds/php-libs/binary-tools.zip 並解壓縮至 C:\php-sdk 。
  7. 依預設的搜尋路徑 (參見原始碼中 php-5.3.0\win32\build\config.w32 第 227 行,也可以自訂 --with-php-build=..\deps) 建立一個存放相關檔案的目錄 C:\php-sdk\deps 。並至 http://wiki.php.net/internals/windows/libs 下載所需檔案解壓至該目錄。
  8. 從開始功能表裡執行 Windows SDK - CMD Shell ,並輸入下列指令。
  9. SetEnv.cmd /x86 /xp /release 設定編譯模式。
  10. SET PATH=%PATH%;C:\php-sdk\bin;
  11. cd \php-sdk\php-5.3.0 (接下來的指令必須在 PHP 原始碼的根目錄下執行)
  12. cscript.exe /nologo win32\build\buildconf.js
  13. cscript.exe /nologo configure.js --help (非必要,查看可用參數)
  14. cscript.exe /nologo configure.js --enable-object-out-dir=.. --disable-all (這裡參數依需求而有所不同)。
  15. nmake (開始編譯,需要一段時間)。
  16. 最終的目錄結構會類似下列這樣:
    +-C:\php-sdk
    | +-bin
    | | --bison.exe
    | | --bison.simple
    | | --...
    | +-deps
    | | +-bin
    | | +-include
    | |   --httpd.h (來自 Apache httpd)
    | |   --...
    | | +-lib
    | |   --libiconv.lib (來自 GNU libiconv)
    | |   --libxml2.lib
    | |   --...
    | +-php-5.3.0 (PHP 原始碼)
    | | +-build
    | | +-win32
    | | +-...
    | +-Release_TS (輸出編譯結果的目錄)
    | | +-...
    
  17. nmake install (安裝編譯的結果,預設安裝至 C:\php5)。

2009-07-15

榨乾硬碟效能 只用外圈

  • 爬文時看到的,我自已沒有實測過,但還滿合理的,所以先記下來。
  • 就是分割硬碟前幾個百分比的部份來用,只用硬碟碟片的最外圈,可以減少存取時間,只是很浪費就是了。
  1. PCDVD數位科技討論區 - [疑問]請問WD3000迅猛龍型號GLFS與HLFS差異

不認本人只認印章的詭異地方

  1. 中文鉛字 | zonble’s promptbook

2009-07-07

The Sims 3 意外的好玩

  • 因為遊戲主題並不合我胃口的關系,我並沒有玩過前面兩代,沒想到三代一玩就停不下來。不過大部份時間都在蓋房子就是了。
  • 官方的人物模組做不出日式虛擬人物的風格(瓜子臉)。
  • 遊戲操縱的角色在以家庭為單位,意指一個家有多少小人,你就要控制多少小人。雖然一次控制一個小人是有點少,但一次兩個(或以上)就有點麻煩了。
  • 很多飾品真是只是裝飾用的,能多一點可互動的物件會更好。
  • 上下班的共乘車不能取消,也不能設定成慢跑或開車。
  • 目前東西還不算多,期待資料片的發行。
  • 我對遊戲的評價分級:
    1. 好玩:玩完一遍會想繼續再玩的,就像 The Sims 3 和前陣子的 Fallout 3。
    2. 普通:玩過一遍就好,像是“Tom Clancy's H.A.W.X”
    3. 不好玩:連一遍都玩不下去,最近的例子是“Tom Clancy's End War”和“King's Bounty: The Legend”。
  • 這遊戲某方面來說真實的令人感到恐怖,即便創立的角色都與我本人迥異,但還是常有在過現實生活的錯覺…
    1. Blog.XDite.net » [心得] 模擬市民 3 之 做自己 — 一個阿宅的無限 loop
    2. Blog.XDite.net » [心得] 模擬市民 3 之 人生快轉的震撼教育

2009-06-23

[已解決] 安裝 Apache HTTPD 時出現 Installation Wizard Interrupted

  1. Davis's tech blog: Problems installing Apache HTTP Server

2009-06-21

關於生物特徵辨識

  • 想起之前玩過的眾多遊戲,只要是得用指紋、虹膜等個人特徵作為鑰匙才能開啟的門,最後一定得勞駕後人將當事者的手指頭、眼珠血淋淋地送到門面前開門。到底,人類要什麼時候,才會學到教訓?
    出自“扁蟲窩: 戰神(God of War)十大衰尾路人”一文。
  • 如果要避免被截肢的情況,做手掌的指紋及靜脈辨識的同時要測量脈搏,虹膜及視網膜辨識時要順便驗一下光之類的。

2009-06-20

[碎碎唸] 說謊

當一個人說他一輩子都沒有說過謊時,那麼,他就是在說謊。

2009-05-13

在 Windows Apache 上同時執行 PHP4 與 PHP5

  • 將 PHP4 與 PHP5 分別以 CGI 和 Apache module 模式執行,以副檔名 .php4 與 .php 分辨執行的版本。
  • 在 httpd.conf 加入
    <Directory "C:/php4">
        AllowOverride None
        Options None
        Order allow,deny
        Allow from all
    </Directory>
    
    # PHP 4
    #"C:/php4/" 這裡尾端必須要加上斜線
    ScriptAlias /php/ "C:/php4/"
    AddHandler php4-script .php4
    Action php4-script "/php/php.exe"
    
    
    # PHP 5
    LoadModule php5_module "C:/php5/php5apache2_2.dll"
    AddType application/x-httpd-php .php
    PHPIniDir "C:/php5"

標籤分類

Labels

Google Analytics Tracking Code

About Me

My photo
Keelung, R.O.C, Taiwan
一個不學無術、混吃等死的傢伙…