Search

1/30/2007

bookmarklet: getTitle()

一個簡單的 bookmarklet,可以快速的複製某個網頁的 title,這樣如果要寫 blog 的話比較方便,設定position是因為怕版型亂調,設定zIndex是怕被網頁的內容蓋住。點一下可以取消。
要注意的是 if(input.parentNode){input.parentNode.removeChild(input);},這邊如果寫 if(input) 會 always true,even被從DOM tree remove 掉,所以這邊檢查的是 input.parentNode
genTitle


<a href="javascript:
var title = document.getElementsByTagName('title')[0];
titleText = (typeof title == 'undefined')?
'Error: no title element': title.innerHTML;
if(typeof input=='undefined')
input = document.createElement('input');

var _scrolltop;
if (document.documentElement && document.documentElement.scrollTop){
_scrolltop = document.documentElement.scrollTop;
}
else if(document.body){
_scrolltop = document.body.scrollTop;
}
input.style.fontFamily = 'arial';
input.style.border= '1px solid gray';
input.style.padding = '1px 5px';
input.style.fontSize = '1em';
input.style.width = '20em';
input.style.backgroundColor = '#eee';
input.style.position = 'absolute';
input.style.left = '0';
input.style.top = _scrolltop+'px';
input.style.zIndex = '999';
input.value = titleText;
if(document.body)
document.body.insertBefore(input, document.body.firstChild);

input.select();
document.onclick = function(e){
if(input.parentNode){
input.parentNode.removeChild(input);
}
document.onclick = null;
};
void 0; ">genTitleNew</a>

Reverse proxy

Reverse proxy - Wikipedia, the free encyclopedia

Typically, reverse proxies are utilized in front of webservers. All connections coming from the Internet addressed to one of the webservers are routed through the proxy server, which may either deal with the request itself or pass the request wholly or partially to the main webserver.

1/29/2007

event.d

Ubuntu不知道從哪一版就沒了 /etc/inittab,最近要改 runlevel 找不到原來是改成 /etc/event.d/rc-default 來管理,修改 runlevel 就修改 /etc/event.d/rc-default 即可
rc-default 也是會去檢查是否存在 /etc/inittab

start on rcS/stop

script
runlevel --reboot || true

if grep -q -w -- "-s\|single\|S" /proc/cmdline; then
telinit S
elif [ -r /etc/inittab ]; then
RL="$(sed -n -e "/^id:[0-9]*:initdefault:/{s/^id://;s/:.*//;p}" /etc/inittab || true)"
if [ -n "$RL" ]; then
telinit $RL
else
telinit 2
fi
else
telinit 2
fi
end script

程式者的胡言亂語 : 一個程式者的胡言亂語

程式者的胡言亂語 : 一個程式者的胡言亂語

  • Bytecode - Wikipedia, the free encyclopedi
    Bytecode is a binary representation of an executable program designed to be executed by a virtual machine rather than by dedicated hardware. Since it is processed by software, it is usually more abstract than machine code.
    After compiling to bytecode, the resulting output may be used as the input of a compiler targeting machine code, or executed directly on a virtual machine.
    bytecodes encode the results of semantic analysis such as the scope of each variable access (that is, whether the variable is global or local). Thus, performance is usually better than interpretation of source code.
    Some systems, called dynamic translators, or "just-in-time" (JIT) compilers, translate bytecode into machine language as necessary at runtime.
    For example, Java and C# code is typically stored in bytecoded format, which then uses a JIT compiler to translate the bytecode to machine code before execution. This introduces a delay before a program is run, when bytecode is compiled to native machine code, but improves execution speed considerably compared to interpretation - normally by several times.

  • Common Language Infrastructure - Wikipedia, the free encyclopedia

  • Common Intermediate Language - Wikipedia, the free encyclopedia

  • Just-in-time compilation - Wikipedia, the free encyclopedia
    just-in-time compilation (JIT), is a technique for improving the runtime performance of a computer program. It converts, at runtime, code from one format into another, for example bytecode into native machine code. The performance improvement originates from caching the results of translating blocks of code, and not simply evaluating each line or operand separately.
    The goal is to combine many of the advantages of native and bytecode compilation: Much of the "heavy lifting" of parsing the original source code and performing basic optimization is handled at compile time, prior to deployment: compilation from bytecode to machine code is much faster than from source.
    However, JIT may have a drawback by causing a slight delay in initial execution of an application, due to the time taken to compile the bytecode. Sometimes this delay is called "startup time delay".
    JIT compilation is considered advantageous in many scenarios because of its portability, flexibility and performance. The only major drawback probably is the startup time delay.

  • Universal binary - Wikipedia, the free encyclopedia
    Universal binaries typically include both PowerPC and x86 versions of a compiled application. The operating system detects a universal binary by its header, and executes the appropriate section depending on the architecture in use. This allows the application to run natively on any supported architecture, with no performance impact.

  • Managed code - Wikipedia, the free encyclopedia

    In Microsoft Windows terminology, managed code is computer instructions — that is, "code" — executed by a CLI-compliant virtual machine, such as Microsoft's .NET Framework Common Language Runtime, or other CLI implementations from The Mono Project or the DotGNU Project.
    Before the code is run, the Intermediate Language is compiled into native machine code. Since this compilation happens by the managed execution environment's own runtime-aware compiler, the managed execution environment can guarantee what the code is going to do. It can insert garbage collection hooks, exception handling, type safety, array bounds, index checking, etc.

  • Java 相關的編譯技術

1/27/2007

本週閱讀2006.01.27-2006.02.02

看看老外怎么做乘法 - 檔主席精心挑選 - 優仕網共產檔
Mobile01-[吉田鞄勸敗網站] 想入手日本吉田鞄的各位非看不可~~[Cool Cat購物流程圖解]
Getting Rich with PHP 5中文翻譯
YouTube - Lightsaber Strikes Back
一隻貓在洛杉磯: Big Game - l老鼠媽媽的故事
一隻貓在洛杉磯: 殺鼠人迷魂曲 (上)。
一隻貓在洛杉磯: 殺鼠人迷魂曲 (下)。

這些老鼠可是一隻價值四十美金的基因轉殖老鼠呢,住的是有衡溫衡濕自動空調每間只能住四隻的標準老鼠套房,每個禮拜有專人固定打掃,喝的是滅菌過的水,吃的是特製的飼料,生病了有富士蘋果可以吃,每個房間每天還要付一塊美金! 實驗室有三個老鼠房,大概三四百個老鼠小套房,最高紀錄每個月要為老鼠付出大約三萬美金的生活費!

法蘭西實驗室:The Inner Life of a Cell - 天空部落
Don't be misled by these 10 Windows Vista myths
比房地產更賺錢 "熊貓燒香"病毒產業鏈揭秘

1/26/2007

greasemonkey script: blogger little toys

使blogger的編輯畫面增加三個按鈕,第一個可以把選取範圍的內容的 < >換成相對應的HTML entities,第二個可以把選取的範圍加上 <pre class="code"> <>,第三個可以把選取的範圍加上<blockquote><div> </div></blockquote>,因為我的blockquote有兩張底圖,所以要<blockquote>裡面要用<div>多包一層。算是第一個稍具實用性的script。


code部分參考兩篇,主要是 text selection的部分:

blogger

// ==UserScript==
// @name blogger little toys
// @namespace http://birdegg
// @description add useful editing tools to blogger
// @include http://*.blogger.com/post-create.g?blogID=*
// @include http://*.blogger.com/post-edit.g?blogID=*
// ==/UserScript==

function replaceLtGt(){
var f = document.getElementById('textarea');
var s1 = f.value.substring(0, f.selectionStart);
var s2 = f.value.substring(f.selectionStart, f.selectionEnd);
var s3 = f.value.substring(f.selectionEnd, f.textLength);
s2 = s2.replace(/</ig, '&lt;').replace(/>/ig, '&gt;');
f.value = s1+s2+s3;
}
function wrapSelection(left, right){
var f = document.getElementById('textarea');
var s1 = f.value.substring(0, f.selectionStart);
var s2 = f.value.substring(f.selectionStart, f.selectionEnd);
var s3 = f.value.substring(f.selectionEnd, f.textLength);
s2 = left + s2 + right;
f.value = s1+s2+s3;
}
function wrapSelectionWithBlockquote(){
return wrapSelection('<blockquote><div>', '</div></blockquote>');
}
function wrapSelectionWithPre(){
return wrapSelection('<pre class="code">', '</pre>');
}

function run(){
var f = document.getElementById('textarea');
var htmlbar = document.getElementById('htmlbar');
var btn1 = document.createElement('input');
btn1.value = '&lt;&gt;';
btn1.type = 'button';
btn1.addEventListener("click", replaceLtGt, false);
var btn2 = document.createElement('input');
btn2.value = '<BlockQuote>';
btn2.type = 'button';
btn2.addEventListener("click", wrapSelectionWithBlockquote, false);

var btn3 = document.createElement('input');
btn3.value = '<Code>';
btn3.type = 'button';
btn3.addEventListener("click", wrapSelectionWithPre, false);

btn1.style.padding = btn2.style.padding = btn3.style.padding = '0';
btn1.style.border = btn2.style.border = btn3.style.border = '1px solid black';
btn1.style.backgroundColor = 'white';
btn2.style.backgroundColor = 'white';
btn3.style.backgroundColor = 'white';
anchor = document.getElementById('key_commands');

anchor.appendChild(btn1);
anchor.appendChild(btn3);
anchor.appendChild(btn2);
}
(
function(){
run();
}
)();

1/22/2007

Javascript Literals

  • Function Literals
    var squares = function(x){ return x*x; }
    var square = new Function("x", "return x*x;");

    Object Literals
    var point = new Object({x:2.3, y:-1.2});var point = {x:2.3, y:-1.2};
    var point = new Object({x:2.3, y:-1.2});

    Array Literals
    var a = [1.2, "Javascript", true, {x:1, y:3}];
    var a = new Array(1.2, "Javascript", true, {x:1, y:3});

IMHO

最近常看到 IMHO,查了一下才知道是 In my humble opinion
List of Internet slang phrases - Wikipedia, the free encyclopedia - 有完整的列表

IMO/IMHO/IMNSHO/IMAO - In my (humble / honest / not so humble / arrogant) opinion