2009年9月29日 星期二

xhprof安裝

升級php5.2.11
更新yum

#additional packages that extend functionality of existing packages
[c5plus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=5&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5


#yum update php

#cd /usr/local/src
#wget http://pecl.php.net/get/xhprof-0.9.1.tgz
#tar -zxvf xhprof-0.9.1.tgz
#cd xhprof-0.9.1/extension
#phpize
#./configure --with-php-config=/usr/bin/php-config
#make
#make install
#make test
#vi /etc/php.ini

[xhprof]
extension=xhprof.so
;
; directory used by default implementation of the iXHProfRuns
; interface (namely, the XHProfRuns_Default class) for storing
; XHProf runs.
;
xhprof.output_dir=


#vi graphviz-rhel.repo

//http://graphviz.org/graphviz-rhel.repo
[graphviz-stable]
name=Graphviz - RHEL $releasever - $basearch
baseurl=http://www.graphviz.org/pub/graphviz/stable/redhat/el$releasever/$basearch/os/
enabled=1
gpgcheck=0

[graphviz-stable-source]
name=Graphviz - RHEL $releasever - Source
baseurl=http://www.graphviz.org/pub/graphviz/stable/SRPMS/
enabled=0
gpgcheck=0

[graphviz-stable-debuginfo]
name=Graphviz - RHEL - Debug
baseurl=http://www.graphviz.org/pub/graphviz/stable/redhat/el$releasever/$basearch/debug/
enabled=0
gpgcheck=0

[graphviz-snapshot]
name=Graphviz - RHEL $releasever - $basearch
baseurl=http://www.graphviz.org/pub/graphviz/development/redhat/el$releasever/$basearch/os/
enabled=0
gpgcheck=0

[graphviz-snapshot-source]
name=Graphviz - RHEL $releasever - Source
baseurl=http://www.graphviz.org/pub/graphviz/development/SRPMS/
enabled=0
gpgcheck=0

[graphviz-snapshot-debuginfo]
name=Graphviz - RHEL - Debug
baseurl=http://www.graphviz.org/pub/graphviz/development/redhat/el$releasever/$basearch/debug/
enabled=0
gpgcheck=0


#rpm -e graphviz-php
#yum update graphviz

2009年9月24日 星期四

【JavaScript】slice()、substring()、substr()的區別

stringObject.slice(startIndex,endIndex)
  返回字串 stringObject 從 startIndex 開始(包括 startIndex )到 endIndex 結束(不包括 endIndex )為止的所有字元。
  1)參數 endIndex 可選,如果沒有指定,則預設為字串的長度 stringObject.length 。
 var stringObject = "hello world!";
 alert(stringObject.slice(3)); // lo world!
 alert(stringObject.slice(3,stringObject.length)); // lo world!
  【注1】字串中第一個字元的位置是從【0】開始的,最後一個字元的位置為【stringObject.length-1】,所以slice()方法返回的字串不包括endIndex位置的字元。
  2)startIndex 、endIndex 可以是負數。如果為負,則表示從字串尾部開始算起。即-1表示字串最後一個字元。
 var stringObject = "hello world!";
 alert(stringObject.slice(-3)); // ld!
 alert(stringObject.slice(-3,stringObject.length)); // ld!
 alert(stringObject.slice(-3,-1)); // ld
  【注2】合理運用負數可以簡化代碼
  3)startIndex、endIndex 都是可選的,如果都不填則返回字串 stringObject 的全部,等同於slice(0)
 var stringObject = "hello world!";
 alert(stringObject.slice()); // hello world!
 alert(stringObject.slice(0)); // hello world!
  4)如果startIndex、endIndex 相等,則返回空串
  【注3】String.slice() 與 Array.slice() 相似
stringObject.substring(startIndex、endIndex)
  返回字串 stringObject 從 startIndex 開始(包括 startIndex )到 endIndex 結束(不包括 endIndex )為止的所有字元。
  1)startIndex 是一個非負的整數,必須填寫。endIndex 是一個非負整數,可選。如果沒有,則預設為字串的長度stringObject.length 。
 var stringObject = "hello world!";
 alert(stringObject.substring(3)); // lo world!
 alert(stringObject.substring(3,stringObject.length)); // lo world!
 alert(stringObject.substring(3,7)); // lo w,空格也算在內[l][o][ ][w]
  2)如果startIndex、endIndex 相等,則返回空串。如果startIndex 比 endIndex 大,則提取子串之前,調換兩個參數。即stringObject.substring(startIndex,endIndex)等同於stringObject.substring(endIndex,startIndex)
 var stringObject = "hello world!";
 alert(stringObject.substring(3,3)); // 空串
 alert(stringObject.substring(3,7)); // lo w
 alert(stringObject.substring(7,3)); // lo w
  【注4】與substring()相比,slice()更靈活,可以接收負參數。
  stringObject.substr(startIndex,length)
  返回字串 stringObject 從 startIndex 開始(包括 startIndex )指定數目(length)的字元字元。
  1)startIndex 必須填寫,可以是負數。如果為負,則表示從字串尾部開始算起。即-1表示字串最後一個字元。
  2)參數 length 可選,如果沒有指定,則預設為字串的長度 stringObject.length 。
 var stringObject = "hello world!";
 alert(stringObject.substr(3)); // lo world!
 alert(stringObject.substr(3,stringObject.length)); // lo world!
 alert(stringObject.substr(3,4)); // lo w
  3)substr()可以代替slice()和substring()來使用,從上面代碼看出 stringObject.substr(3,4) 等同於stringObject.substring(3,7)
  【注5】ECMAscript 沒有對該方法進行標準化,因此儘量少使用該方法。

JQuery How to check if an element exists

A common question comes up very frequently - "how do I know if XXX exists". The XXX could be a particular DIV with a class, or it might be an ID. The issue is common enough that it has been listed in the jQuery FAQs (http://docs.jquery.com/Frequently_Asked_Questions#How_do_I_test_whether_...).

Some people attempt to just check the jQuery object for the specified selector:


//This will not work

if ( $("#myid") ) {

//do something

}


This will fail. The jQuery object will ALWAYS return something. When we say $( ) we are asking for a jQuery object. So we get one back. The above code will always equate to TRUE.

The jQuery object contains a list/array of the elements that match our selector. So we can ask for the length of this internal list. The jQuery kindly exposes this length for us as the .length property. If the length is greater than zero then we have at least one object that matches our selector.


if ( $("#myid").length > 0 ) {

//do something

}


So now the only question is what we are testing. This is defined by the selector we use. If we want to know if a particular ID exists, we would use a selector of "#theID". If we were trying to determine if a DIV with a particular class existed, we would use the selector of "div.theClass".


if ( $("#theID").length > 0 ) { alert("The ID exists"); }

if ( $("div.theClass").length > 0 ) { alert("The DIV exists"); }


In this way we can check to see if ANY element exists.

2009年9月23日 星期三

吴迪西羽毛球技术入门

http://v.youku.com/v_show/id_XMTUxOTcwNDQ=.html

2009年9月22日 星期二

javascript for loop json


var json = { "glossary": { "title": "example glossary" } };
alert(json);
alert(json.glossary.title);
for (var x in json) { alert(x); alert(json[x].title); }

用YUM升级CentOS系统中PHP和MySQL

用上umVPS后,很多时候在虚拟主机不用自己动手的事情都要自己搞定了,例如:PHP和MySQL的升级。因为不用自己动手,也动不了,所以冰古不太清楚虚拟主机的PHP和MySQL是不是会及时地更新。但用VPS,可以动手玩一下也保证安全,冰古是很乐意进行更新的。以下就是用YUM升级CentOS系统中PHP和MySQL的过程:

yum是CentOS系统自带的用于方便地添加/删除/更新RPM包的工具,它能自动解决包的倚赖性问题。
用yum更新PHP,只需用一条命令就可以搞定:

#yum update php
但问题来了,使用此命令后,系统告诉我,没有发现可更新的包。而当前的PHP版本只是5.2.1,PHP官方已经更新到5.2.6了。
经过一番询问,才知道原来CentOS系统的源里PHP仍旧是5.2.1,需要额外的源才能升级PHP。
根据外国网友的介绍,冰古添加了额外的源:
登录SSH后依次运行下列命令:

#rpm --import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
#vi /etc/yum.repos.d/utterramblings.repo #文中这里是使用nano,但VPS不能启动nano,用vi代替也是可以的
在打开的文档中加入下面内容:

[utterramblings]
name=Jason's Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
保存。
再次运行下面的命令就可以完成php的升级了

#yum update php
同理,运行下面命令,升级mysql

#yum update mysql

摘自:http://bingu.net/508/upgrade-php-mysql-of-centos-system-use-yum-command/

[Debug]Cannot load libphp5.so No such file or directory

#locate libphp5.so
/usr/lib/httpd/modules/libphp5.so

#cp -a /usr/lib/httpd/modules/libphp5.so /opt/httpd/modules/

即可

wibiya widget