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

2008年6月17日 星期二

茱蒂口琴樂團

茱蒂口琴樂團 - http://www.judys.idv.tw/

Judy's口琴樂團2007年度公演影片


剛老妹丟了一個連結給我,是茱蒂口琴樂團上我猜的表演,好久沒聽到讓人那樣感動的音樂。不過因此我猜的節目比較有版權的關係,建議自行到YoutuBe搜尋一下囉,當天在我猜表演的曲目是「喋喋不休的波卡」,只要打上曲目應該會很快就找到了。

逛了一下官網,很有 fu !前陣子有人一直抱怨我不唱歌,大概是自己唱得不好聽,所以很難開口,不過說起歌唱以外的方式,我還滿想玩樂器的,像是幼稚園、國小玩的直笛,那時感覺自己玩得還滿不錯的,無聊時就是吹直笛,另外還有口琴吧,只是隨著歲月的增減、場地的變換,忙錄的、干擾的、來亂的,漸漸地根本沒什麼時間享受生活了。

若這學期課程都 all pass 的話,之後我只剩兩門課要修,開始有更多的時間規劃生活。