2008年6月25日 星期三

Combination Generator for PHP

之前需要寫個組合產生器,
寫來寫去, 也跟網路上找到的寫法一樣, 就順便用了他的注解嚕...
/*                                                                                                                            
 * Date   : 2008-06
 * Name   : getCombinationOutput
 * Usage  : Generate all combinations of the elements in the array
 * Input  : @param array   input array contains all elements
 *          @param integer number of choosing
 *          @param string  output file name
 * Output : a text file contains all combination
 *
 * Example :
 * $array = array( 684, 1056, 1066, 1274 );
 * getCombinationOutput( $array, 2, "test.out" );
 *
 * test.out :
 * 684 1056
 * 684 1066
 * 684 1274
 * 1056 1066
 * 1056 1274
 * 1066 1274
 */

function getCombinationOutput( $input_array, $select, $output )
{
    $_number = sizeof($input_array);

    if ( !($_fp = fopen( $output, "a") ) ) 
    {   
        echo "can't open file!\n\r";

        return 0;
    }   

    $_array = array();

    for ( $_i=0; $_i<$select; $_i++ )
    {
        $_array[$_i] = $_i + 1;
    }

    while (1)
    {
        $_temp = array();

        for ( $_i = 0; $_i < $select; $_i++ )
        {
            $_index = $_array[$_i];

            fwrite ( $_fp, $input_array[$_index -1]." " );
        }

        fwrite ( $_fp, "\n" );

        // generate next combination in lexicographical order
        // start at last item
        $_i = $select - 1;

        // find next item to increment
        while ( $_array[$_i] == ( $_number - $select + $_i + 1 ) )
        {
            $_i--;
        }

        // all done
        if ( $_i < 0 )
        {
            break;
        }

        // increment
        $_array[$_i] = $_array[$_i] + 1;
        // do next
        for ( $_j = $_i + 1; $_j < $select; $_j++ )
        {
            $_array[$_j] = $_array[$_i] + $_j - $_i;
        }
    }

    fclose ( $_fp );

    return $output;
}                                                  

2008年5月20日 星期二

Cisco Certified Network Associate

話說 還在抱怨近來的不爭氣,
"馬上"就又去考了CCNA...
不過接下來將開始做點正事了,
下半年將會硬梆梆, 真是由硬入軟易, 由軟入硬難...

2008年5月7日 星期三

Google台灣演說

以前很少聽到台灣Google的人發言,
但最近有幸聽到幾場演說, 在此筆記一下...

林一平@TANET 2007: Issues on Mobile All-IP Networks
Ray Chen@OSDC 2008: Google Gears
李開復@NTU: Cloud Computing
翟本喬@EAF嵌入式應用論壇: 消費性電子設備的網路服務

2008年5月6日 星期二

辣妹英文課

前兩天在Starbucks搭訕了一個女生,
會去認識主要是因為聽到她的英文發音不錯,
想說有專業的指導, 也許可以洗刷Coke的恥辱...

以後辣妹英文課每週二準時開講 :Q

2008年3月31日 星期一

FreeBSD Services

其實service和daemon我是混著用的 :Q

在FreeBSD, service有兩種啟動方式, stand-alone和super-server(inetd), 兩種方式各有優缺點, 看個人需求而定... 而這兩種服務的設定分別由rc.d system和inetd.conf來控制
根據手冊所說, "從2002年起, FreeBSD 整合了NetBSD的 rc.d機制來作為系統服務啟動機制..."

rc.d system是Stand-Alone模式的設定, 包含
/etc/rc
  • # 系統啟動所執行之script, 並執行/etc/rc.subr
/etc/rc.subr
  • # 使/usr/local/etc/rc.d/*下的script作用
/usr/local/etc/rc.d/*
  • # 透過ports或packages所安裝的軟體, 通常會新增*.sh在此目錄下(須配合/etc/rc.conf)
/etc/rc.conf
  • # 系統網路設定與開機所要啟動的服務
/etc/defaults/rc.conf
  • # 預設之系統服務設定
/etc/rc.d/*
  • # 個別服務啟動之script
/etc/rc.shutdown
  • # shutdown命令所執行之script

而Super-Server透過/etc/inetd.conf來控制, 但是服務名稱需參考/etc/services

2008年3月18日 星期二

Microsoft Certified Systems Engineer

話說 之前才通過RHCE的考試,
這兩個月又很不爭氣的把MC$E的考試考完...
接下來呢?


唉, 好歹我也是堂堂XX大學XX所畢業的咧!!(~消音, 太丟臉了)

2008年3月3日 星期一

在VMware上使用SoftICE

本來想說Windows98環境比較單純,
結果不知怎麼的, 光是symbol loader都無法載入,
後來只能在WindowsXP上安裝... 但抓了八百個版本, 好像都不太靈光 @@a

最後的環境是在VMware5.5 + WindowsXP Pro(未patch) + DriverStudio3.2安裝成功的...
小小微調一下設定:
  • Screen Resolution: "800x600"
  • Initialization Settings:"FAULTS OFF;CODE ON;LINES 40;WD 10;WC 20;SET FONT 2;X;"
  • VMware vmx: "svga.maxFullscreenRefreshTick = 5"