Thursday, April 8, 2010

[.Net] execute directory

System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
 
Application.ExecutablePath  (windows form)

System.Reflection.Assembly.GetEntryAssembly();
Assembly.GetExecutingAssembly().CodeBase

Appliaction.StartupPath property

Wednesday, March 24, 2010

[PHP] 設定script執行時間限制

set_time_limit(0);

Tuesday, March 23, 2010

[miranda] google talk

google talk實際用的protocol是Jabber

http://miranda.wikia.com/wiki/Google_Talk

http://www.google.com/talk/otherclients.html


Gmail Multiple Notifier (Unicode) 0.4.0.10
http://addons.miranda-im.org/details.php?action=viewfile&id=3677

[AJAX] GET cache problem

避免cache的作法 (利用timestamp傳不同get參數)

 
在url後面加個 '?q=' +new Date().getTime()
 
 
    jQuery(".del").click( function() {
        delPicId = jQuery(this).attr("id").charAt(3);
        jQuery.getJSON("blah/"+delPicId +"?q="+new Date().getTime(),
            function(data){
                jQuery("#pic"+delPicId).attr("src", 'webroot?>img/blah.jpg');
            }
        );
    });

Monday, March 22, 2010

[CakePHP] validation

寫在model的 $validate array中

驗證方式
 1) 自己寫function
 2) 自己寫regex  (cake使用preg_match)
 3) 使用系統的rule

    var $validate = array(
        'nickname'=> array('rule'=>'checkNickname', 'required'=>false, 'message'=>'長度超過限制'),
        'gander'=> array('rule'=>'/^1|0$/', 'required'=>false, 'on'=>'update'),
        'height'=> array('rule'=>'numeric', 'required'=>false, 'allowEmpty'=>false, 'on'=>'update'),
);

    function checkNickname($check) {
        $value = array_values($check);
        $value = $value[0];
        $value = iconv('UTF-8', 'BIG5', $value);
        if ($value && strlen($value)<=16)
            return true;
        else
            return false;
    }

[MySQL]optimization

EXPLAIN (瞭解MySQL如何處理select)
   Ex: EXPLAIN select * from users.users

GROUP BY xxx,預設會對xxx欄位做sort,如果不希望sort要加ORDER BY NULL

Table欄位的順序也會影響到query的效率(primary key, unique index, index, normal columns)

[js] swap image

/*
    img jQuery object of img tag element
    new img suffix
    1/0 suffix or not
*/
function imgSwap(img, suffix, state) {
    //  ext/. -3 -1
    var img_src = img.attr("src");
    var suffix_pos = img_src.length -4 -suffix.length;
    var img_src_suffix = img_src.substr(suffix_pos, suffix.length);
    var img_src_ext = img_src.substr(img_src.length-4);

    if (state == 1 && img_src_suffix != suffix)
    {
        //prefix + suffix + ext
        img.attr("src", img_src.substr(0, img_src.length-4) + suffix + img_src_ext );
    }
    else if (state ==0 && img_src_suffix == suffix)
    {
        //prefix + ext
        img.attr("src", img_src.substr(0, suffix_pos) + img_src_ext );
    }
}
function a_blur() {
    jQuery("a").focus( function() { this.blur(); return false; } );
}


使用,1是over,0是mouse out
    jQuery(".swap").hover(
        function(){ imgSwap(jQuery(this), "-over", 1) },
        function(){ imgSwap(jQuery(this), "-over", 0) }
    );