2008年6月25日 星期三

暑假尚未開始

碩班的生活,沒想到期末考都很早地考完,唯一的缺點是我修了一門期末要上台報告的課,必需搞到七月初才能正式結束這學期的課程。

一不留意,已經在中正待了接近一年,去年我是在七月底進宿舍的。仔細回想,這一年嘛,說沒學到東西也不是,但總覺得心中有點空虛的感覺,大概是學了不少我認為出去工作再學就好的東西吧?說真的,我有種很想趕快畢業的念頭,同時也思考自己是不是適合往博班發展?總覺得博班才是做研究的開始,碩班像極打雜的掃地僧,各憑本事混吃混喝。前陣子猶疑,最近比較定下心了,我想,出去工作才是我想要的生活,未來若沒經濟壓力,加上能申請上的話,再回學校吧?

說得好像已經畢業似的。

下學期我還是想把行銷管理的課程好好地上過一遍,碩一上期中後因為常常膩於程式中,不久也作罷了。除此之外,還有不少課想去聽聽,不曉得未來的生活是否還能抓的穩步調呢?

2008年6月24日 星期二

[C] long long & printf

    long long x;

    Windows:
                printf( "%I64d\n" , x );
    Unix:
                printf( "%lld\n" , x );

--
    "%qd" ?

2008年6月22日 星期日

[C] fopen with 'a' & fseek

            fopen with 'a' 無法使用 fseek 對檔案指標進行倒退嚕
            這兩天運氣不怎好  總是卡在奇怪的 bug 中
            真的是太嫩了  還差得遠

                =========================================================
                = By finwater (cheer up) @ Mon Jun 23 20:15:07 2008
                =
                fopen with flag 'a' 的 'a' 是 append 的意思
                所以 write 的 data 會被自動 append 到檔案的最後
                無論此時 offset 在哪
                但還是可以使用 fseek 對 file pointer 的 offset 進行操作
                =========================================================

    @ code 1 : fopen with 'ab+'

        #include <stdio.h>
        #include <stdlib.h>

        int main(int argc, char *argv[])
        {
                FILE * fd = fopen ("dd" , "ab+");
                fd = fopen ("dd" , "w+");
                fclose ( fd );

                fd = fopen ("dd" , "ab+");
                fprintf( fd , "0123456789" );

                fseek( fd , -5 , SEEK_CUR );

                fprintf( fd , "0123456789" );

                fclose ( fd );
                return 0;
        }

        結果: 01234567890123456789

    @ code 2 : fopen wtih 'rb+'
        #include <stdio.h>
        #include <stdlib.h>

        int main(int argc, char *argv[])
        {
                FILE * fd = fopen ("dd" , "ab+");
                fd = fopen ("dd" , "w+");
                fclose ( fd );

                fd = fopen ("dd" , "rb+");
                fprintf( fd , "0123456789" );

                fseek( fd , -5 , SEEK_CUR );

                fprintf( fd , "0123456789" );

                fclose ( fd );
                return 0;
        }

        結果: 012340123456789

2008年6月21日 星期六

大量縮圖 By Irfan View

    http://www.irfanview.com/
    http://www.irfanview.com/main_download_engl.htm

    Step 1 :
        [File] -> Batch Coversion/Rename

    Step 2 :
        透過右上角視窗,可以挑選待處理的照片
        記得請將[檔案類型]改成 All files (*.*)
        選好照片後,請點選 [Add] 或是對指定目錄點選 [Add all]
        接著就會在右下角視窗記錄著

    Step 3 :
        目前打算將原始檔 jpg 檔轉成較小的圖檔
        [Batch conversion settings] -> Output format: JPG - JPG/JPEG Format
        勾選 [Use advanced options] -> Advanced

    Step 4 :

        設定 Advanced 參數,我常用的是將照片的寬設成 1024
        [RESIZE] -> Set long side to: 1024
        勾選常用選項
        [Preserve aspect radio(proportional)]
        [Use Resample function(better quality)]
        [Don't enlarge smaller images]

    Step 5 :
        選擇輸出的位置
        [Output directory for result files]

    Step 6 :
        [Start Batch]

2008年6月19日 星期四

[C] IO 處理測試 - fopen with "w" or "a"

    結論:

        沒事不要 truncate !

        若一天有 80 萬封信且九成是 spam mail
        代表一天 86400 秒  =>  平均 1秒需處理約 10 次動作

        目前若採用 truncating

            FreeBSD 6.2-RELEASE-p1
            Intel(R) Pentium(R) 4 CPU 3.00GHz (2992.51-MHz 686-class CPU)
            1GB Ram

        25000 次花費近 120 秒  =>  1秒可處理 200 次
        這個數字不曉得撐不撐得住最大量的時候  :P

        若改掉的話
        25000 次僅需 0.46 秒  => 1 秒可處理 54347 次
    =======================================================
    @ code 1 : fopen with "w"
    int main()
    {
            int i;
            FILE * fd;
            for( i=0; i< 25000 ; i++ )
            {
                    fd = fopen( "t_d.txt" , "w" );
                    fprintf(fd,"%d\n",i);
                    fclose( fd );
            }
            return 0;
    }
    # time ./a.out
    0.127u 1.589s 1:57.61 1.4%      5+177k 0+25000io 0pf+0w
    ======================================================
    @ code 2 : fopen with "a"
    int main()
    {
            int i;
            FILE * fd;
            for( i=0; i< 25000 ; i++ )
            {
                    fd = fopen( "t_d.txt" , "a" );
                    fprintf(fd,"%d\n",i);
                    fclose( fd );
            }
            return 0;
    }
    # time ./a.out
    0.052u 0.410s 0:00.46 100.0%    5+188k 0+0io 0pf+0w
    ======================================================

--
    觀看硬體資訊:
    # cat /var/run/dmesg.boot
    還在只靠 dmesg -a 已經落伍了  XD