十二 05

用了JQuery,实在很方便。
但是很奇怪,评论小数字的click只有在展开了之后才会响应,路过的JS高手帮忙解释一下啊:)
已经上传到userscript.org,id63440,希望可以尽快修正上面提到的问题。

// ==UserScript==
// @name           QQMail Broadcast
// @namespace      QMBC
// @description    UI & Functional Improvement for Broadcast
// @include        http://*.mail.qq.com/cgi-bin/reader_article_list*
// ==/UserScript==
 
// Add jQuery
var GM_JQ = document.createElement('script');
GM_JQ.src = 'http://jquery.com/src/jquery-latest.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);
 
// Check if jQuery's loaded
function GM_wait()
{
    if(typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); }
    else { $ = unsafeWindow.jQuery; letsJQuery(); }
}
GM_wait();
 
function letsJQuery()
{
    $(document).ready(function () {
		var _div = $("<div style='float: right;'></div>");
 
		var _readMode = $("<a>Read Mode</a>");
		_readMode.bind("click", ReadMode);
 
		_div.append(_readMode);
 
		$("<span>|</span>").css("margin", "10px").appendTo(_div);
 
		var _commentMode = $("<a>Comment Mode</a>");
		_commentMode.bind("click", CommentMode);
 
		_div.append(_commentMode);
 
		$("#articlecontent").prepend(_div);
    });
}
 
function ReadMode()
{
	$("div.update a[id^=artTitle_]").click();
}
 
function CommentMode()
{
	var links = $("div.postInfo a[id^=artCommentListLink]:visible");
	links.click();
}
Tagged with:
15

偶尔发现了一个不错的Mac风格主题,可以把原来的Win7换掉了:)

icomes.net_macicomes.net_win7

Tagged with:
24

http://tf.nist.gov/tf-cgi/servers.cgi

28

放到了Google Code上
完成了File操作部分

Tagged with:
31

经典的代码:)

var k=[];
addEventListener("keyup",function(e){ 
   k.push(e.keyCode);
   if(k.toString().indexOf("38,38,40,40,37,39,37,39,66,65")>=0)      
       cheat()
},true);
Tagged with:
29

线程有另外一个名字叫Light Weight Process,
但是到底有多Light,我是一直没有太多直观感觉的。
根据书上所说,线程和进程的主要区别有二:
1. 创建开销
2. IPC代价

首先,创建线程的开销比进程低得多,
“线程的创建可能比进程的创建快10~100倍”(UNP),
这篇日志就是我对Linux下进程与线程创建速度测试的一个记录。

环境:
2.6.27-14-generic #1 SMP i686 GNU/Linux
进程用fork创建,而线程使用pthread库。

fork.c

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
 
int Fork(int i)
{
    if( fork() == 0 )
    {
        printf("%d\n", i);
        exit(0);
    }
}
 
int main(int c, char **v)
{
    if(c != 2)
    {
        fprintf(stderr, "Usage: %s count\n",v[0]);
        return 0;
    }
    int iCount = atoi(v[1]);
    int i = 0;
    while( i < iCount )
    {
        Fork(i);
        i++;
    }
    return 0;
}

pthread.c

#include <pthread.h>
#include <stdio.h>
 
void thread(void *p)
{
    printf("%d\n", *(int *)p);
}
 
int main(int c, char **v)
{
    if(c != 2)
    {
        fprintf(stderr, "Usage: %s count\n",v[0]);
        return 0;
    }
    int iCount = atoi(v[1]);
    int i = 0;
    while( i < iCount )
    {
        pthread_t pid;
        pthread_create(&pid, NULL, thread, (void *)&i);
        i++;
    }
 
}

下面是测试结果:
fork pthread
1 0.003 0.011
10 0.007 0.004
100 0.123 0.013
1000 0.277 0.152
10000 1.423 0.467

的确快很多,但也没达到100倍。
下次再比较一下调度的性能。

22

原因:
span标签的display属性默认是inline
解决方法:
span { display: inline-block;}
or
span { display: block;}

Tagged with:
17

http://taotao.qq.com/vc1/qz_first/firstjson?uin=953377400&num=3
http://taotao.qq.com/vc1/qz_first_utf8/def?uin=953377400&num=3

10

这是John Resig(jQ作者, 目前在mozilla工作)最近的两次演讲的ppt,

The DOM is a Mess @ Yahoo

视频:
http://video.yahoo.com/watch/4403981/11812238

幻灯片:
http://www.slideshare.net/jeresig/the-dom-is-a-mess-yahoo?nocache=5450&type=presentation

Performance Improvements in Browsers

视频:
http://www.youtube.com/watch?v=13-3VMzfU3Y&eurl=http://google-code-updates.blogspot.com/2009/02/john-resig-drop-in-javascript.html&feature=player_embedded

幻灯片:
http://www.slideshare.net/jeresig/performance-improvements-in-browsers?nocache=784

preload preload preload