Wednesday, March 24, 2010
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
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
Labels:
miranda
[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');
}
);
});
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;
}
驗證方式
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;
}
Labels:
CakePHP
[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)
Ex: EXPLAIN select * from users.users
GROUP BY xxx,預設會對xxx欄位做sort,如果不希望sort要加ORDER BY NULL
Table欄位的順序也會影響到query的效率(primary key, unique index, index, normal columns)
Labels:
mysql
[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) }
);
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) }
);
[CakePHP] use model in component or model
$a = ClassRegistry::init('a');
$options['fields'] = array('a.eventname', 'a.event_pic');
$options['joins'] = array(
array('table' => 'soul_match_event_join',
'alias' => 'b',
'type' => 'INNER',
'conditions' => array( 'a.id = b.event_id'),
)
);
$options['conditions'] = array( 'b.uid' => $uid);
$options['order'] = array( 'a.id DESC');
$result2 = $a->find('first', $options);
if ($result2){
$res[$this->name]['event_name'] = $result2['a']['eventname'];
$res[$this->name]['event_pic'] = $result2['a']['event_pic'];
}
$options['fields'] = array('a.eventname', 'a.event_pic');
$options['joins'] = array(
array('table' => 'soul_match_event_join',
'alias' => 'b',
'type' => 'INNER',
'conditions' => array( 'a.id = b.event_id'),
)
);
$options['conditions'] = array( 'b.uid' => $uid);
$options['order'] = array( 'a.id DESC');
$result2 = $a->find('first', $options);
if ($result2){
$res[$this->name]['event_name'] = $result2['a']['eventname'];
$res[$this->name]['event_pic'] = $result2['a']['event_pic'];
}
Labels:
CakePHP
Subscribe to:
Posts (Atom)