RSS
 

Archive for 08月, 2009

两种精辟的Swap写法

12 Aug

这两种写法都没有使用传递变量。

#define swap(x,y)  x = x + y;y = x - y;x = x - y
#define swap(x,y)   x^=y^=x^=y
 
No Comments

Posted in c

 

INPUT中attribute和property的差异

11 Aug

今天在firefox下遇到一个奇怪的问题。

html中有下面一个INPUT元素

<input id="q" name="q" value="123"/>

使用input.getAttribute可以取得该input的值

document.getElementById("q").getAttribute("value"); //return 123

但是当通过界面输入将INPUT的值改为456之后,在通过input.getAttribute的方式取值,仍然返回123,但是使用input.value可以返回456.

document.getElementById("q").getAttribute("value"); // return 123
document.getElementById("q").value;          //return 456

下面的网页中有对该问题的完整的分析和测试(已被墙,请用代理访问)

http://updatepanel.net/2008/12/31/more-on-getattribute-setattribute-and-the-value-attribute/

参考上面的分析可以还原出firefox下的实现

假设

  • “value” property is element.value;
  • “value” attribute is element.getAttribute(”value”);
  • HtmlElement中存在_properties[]和_attributes[]两个关联数组来存放propertie和attribute属性

那么在firefox中

htmlElement.value作为等式右值时等价于

function(){
return this._properties["value"]||this._attributes["value"]
}

htmlElement.value作为等式左值时等价于

function(right_value){
this._properties["value"]=right_value;
}

htmlElement.getAttribute(“value”)等价于

function(){
return this._attributes["value"];
}

htmlElement.setAttribute(“value”,”123″)等价于

function(name,value){
this._attributes[name]=value;
}

而在IE中property和attribute的值是完全等价的不存在差异。

 
 

JFace Text Framework资料汇总

10 Aug
 
No Comments

Posted in eclipse, JTF

 

CentOS 5.3 bash completion

09 Aug

1.下载bash-completion-20060301-1.noarch.rpm

$ wget http://www.caliban.org/files/redhat/RPMS/noarch/bash-completion-20060301-1.noarch.rpm

或者下载下面文件

servconf.cservconf.c (已下载268次)

2.安装rpm包

$ rpm -ivh bash-completion-20060301-1.noarch.rpm

3.在~/.bashrc中添加如下内容

$ vi ~/.bashrc
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi

4.重新载入配置

$ . ~/.bashrc
 
No Comments

Posted in bash, linux

 

CentOS 5.3 修改 hostname

08 Aug

1.修改/etc/hosts

sudo vi /etc/hosts

修改为

127.0.0.1 myhostname localhost.localdomain localhost

2.修改/etc/sysconfig/network

sudo vi /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=myhostname
GATEWAY=61.67.71.126

3.使用hostname命令

hostname myhostname

4.重新登录

 

Firefox 3.5.2 中文语言包

07 Aug

http://releases.mozilla.org/pub/mozilla.org/firefox/releases/3.5.2/linux-i686/xpi/zh-CN.xpi

或者下载安装下面文件

readconf.creadconf.c (已下载226次)
 
1 Comment

Posted in firefox

 

通过SSH连接XDMCP

05 Aug

在CentOS5.3下配置了XDMCP,但是从外网始终没法连上,本机可以连接,google了2天,未果。

SSH的方式可以连接上远端的服务器,于是想到了可以使用SSH X11 转发的方式,连接

1.首先开始服务器上XDMCP服务和远程连接

$ sudo /etc/gdm/custom.conf

修改内容如下

[security]
DisallowTCP=false
[xdmcp]
Enable=true

2.使用-X参数开始SSH X11 Forwarding

$ ssh -X -l LOGINUSER REMOTEHOST

3.使用Xnest打开X桌面

$ Xnest :1 -ac -once -query localhost

第二步和第三步可以合并为

$ ssh -X -C -l LOGINUSER REMOTEHOST -n Xnest :1 -ac -once -query localhost
 

Ubuntu中的XDMCP客户端

03 Aug

远程登录到linux可以使用VNC或者XDMCP的方式,windows下有一个很有名的XDMCP客户端Xmanager,其实UBuntu下默认也安装了该客户端,一次打开[应用程序]-[internet]-[终端服务客户端(Terminal Server Client)]或者在命令行输入tsclient,在常规标签中的协议选项可以看到XDMCP,只不过是灰色的无法选择,需要先安装协议支持。

$ sudo apt-get install xnest

装完后就可以使用了。

 
No Comments

Posted in linux, ubuntu