1、让每个程序就做好一件事。如果有新任务,就重新开始,不要往原程序中加入新功能而搞得复杂。
2、假定每个程序的输出都会成为另一个程序的输入,哪怕那个程序还是未知的。输出中不要有无关的信息干扰。避免使用二进格式输入,而是坚持使用文本流,不要坚持使用交互式输入。
3、尽可能早地将设计和编译的软件投入使用,对于拙劣的代码别犹豫,扔掉重写。
4、优先使用工具减轻编程任务,工欲善其事,必先利其器。
5、花哨的算法复杂度大,并比简单的算法更容易出bug,更难实现,理解和维护。尽量使用简单的算法配合简单的数据结构。
6、编程的核心是数据结构,而不是算法。
7、不确定的时候就用穷举。
8、小就是美,在确保任务完成的基础上,程序功能尽可能少。
Unix 原则
1、模块原则:使用简洁的接口拼合拼合简单的部件。
2、清晰原则:清晰胜于机巧。
3、组合原则:设计时考虑拼接组合。
4、分离原则:策略同机制分离,接口同引擎分离。
5、简洁原则:设计要简洁,复杂度能低则低。
6、吝啬原则:不要编写庞大的程序。
7、透明性原则:设计要可见,以便审查和调试。
8、健壮原则:健壮源于透明和简洁。
9、表示原则:要求逻辑质朴而健壮。
10、通俗原则:即最小惊异原则,接口设计避免标新立异。
11、缄默原则:如果一个程序没什么好说的,就沉默。
12:补救原则:出现异常时要给出足够的错误信息。
13、经济原则:宁花机器一分钟,不花程序员一分钟。
14、生成原则:避免手工hack,尽量编写程序去生成程序。
15、优化原则:原型设计,先求运行,再求正确,最后求快。
16、多样原则:决不相信所谓“不二法门”的断言。
17、扩展原则:设计着眼未来,未来总比预想来得快。
Unix 哲学之总结
所有Unix的哲学用一句话来概括就是“KISS”原则:
Keep It Simple, Stupid!
Sunday, August 23, 2009
Thursday, August 20, 2009
Element Data in jQuery
Added in jQuery 1.2
Attaching data to elements can be hazardous.
Store data: jQuery.data(elem, "name", "value");
Read data: jQuery.data(elem, "name");
All data is stored in a central cache and completely garbage collected,
as necessary.
Added in jQuery 1.2.3
Can handle namespacing:
$("div").data("test", "original");
$("div").data("test.plugin", "new data");
$("div").data("test") == "original"; // true
$("div").data("test.plugin") == "new data"; // true
Advanced data handling can be overridden by plugins:
$(element).bind("setData.draggable", function(event, key, value) {
self.options[key] = value;
}).bind("getData.draggable", function(event, key) {
return self.options[key];
});
Attaching data to elements can be hazardous.
Store data: jQuery.data(elem, "name", "value");
Read data: jQuery.data(elem, "name");
All data is stored in a central cache and completely garbage collected,
as necessary.
Added in jQuery 1.2.3
Can handle namespacing:
$("div").data("test", "original");
$("div").data("test.plugin", "new data");
$("div").data("test") == "original"; // true
$("div").data("test.plugin") == "new data"; // true
Advanced data handling can be overridden by plugins:
$(element).bind("setData.draggable", function(event, key, value) {
self.options[key] = value;
}).bind("getData.draggable", function(event, key) {
return self.options[key];
});
Special Events in jQuery
Added in jQuery 1.2.2
Can create whole shadow event system
New events: mouseenter, mouseleave, ready
$("li").bind("mouseenter", function(){
$(this).addClass("hover");
}).bind("mouseleave", function(){
$(this).removeClass("hover");
});
Can create whole shadow event system
New events: mouseenter, mouseleave, ready
$("li").bind("mouseenter", function(){
$(this).addClass("hover");
}).bind("mouseleave", function(){
$(this).removeClass("hover");
});
Non-DOM Events in jQuery
>>> function User(){}
>>> var u = new User
>>> u
Object
>>> $(u)
[Object]
>>> $(u).bind('login', function(){console.log('login')})
[Object jQuery1250738637761=27]
>>> var j = $(u).bind('login', function(){console.log('login')})
>>> j
[Object jQuery1250738637761=27]
>>> $(u).trigger('login')
login
login
[Object jQuery1250738637761=27]
>>> var u = new User
>>> u
Object
>>> $(u)
[Object]
>>> $(u).bind('login', function(){console.log('login')})
[Object jQuery1250738637761=27]
>>> var j = $(u).bind('login', function(){console.log('login')})
>>> j
[Object jQuery1250738637761=27]
>>> $(u).trigger('login')
login
login
[Object jQuery1250738637761=27]
Tuesday, August 11, 2009
Convert ^M to newline character in text files
If the ^M character is showing up in files while opening the file
concerned, then follow these steps to convert it to a new line.
In vi use the following:
concerned, then follow these steps to convert it to a new line.
In vi use the following:
:%s/^M/\n/g
or with perl on the command line:
$ perl -pi.bak -e 's/^M/\n/g'
NOTE: Be sure to create the ^M by typing ctrl V followed by ctrl M.
^M is ASCII 13 (Ctrl M), which is the carriage return.
Different operating systems use different symbols to set the end of a
line/new line.
Unix uses newline (\n)
Mac uses carriage return (\r)
And Windows/DOS use both (\n\r)
To prevent the ^M from showing up in files, be sure to use the ASCII
(text) mode when transfering text files.
Source article link:
http://blog.eukhost.com/webhosting/convert-m-to-newline-character-in-text-files/
Thursday, August 06, 2009
todo list on linux
1. devtodo
2. tudu
3. remind
4. todo.txt
5. awn todo list applet
使用之后觉得devtodo最为好用,tudu也不错,有vi类似的操作快捷键,用起来很顺手。
awn todo list applet结合awn一起用,做为桌面工具可以即时看到任务数量,操作也非常简单。
2. tudu
3. remind
4. todo.txt
5. awn todo list applet
使用之后觉得devtodo最为好用,tudu也不错,有vi类似的操作快捷键,用起来很顺手。
awn todo list applet结合awn一起用,做为桌面工具可以即时看到任务数量,操作也非常简单。