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

Ajax Debugging with Firebug

Ajaxian » Ajax Debugging with Firebug


Ajaxian » Joe Hewitt Firebug power user demo - Firebug的作者的教學

53 CSS-Techniques You Couldn’t Live Without

53 CSS-Techniques You Couldn’t Live Without - 可以當作 CSS 字典來用了,真詳細

flickr的外連

轉自 PTT Blog 版 R: 給那些濫用flickr的blogger們

<a href="http://www.flickr.com/photos/xxxxx@N00/xxxxx/" title="Photo
Sharing"><img src="http://photos8.flickr.com/xxxxxx_xxxxx_o.jpg"
width="450" height="306" alt="xxxxxxx" /></a>

這樣圖片本身就會變成hyperlink,可以讓觀看者按圖片進到Flickr的photo page裡

或者是另外放個hyperlink讓觀看者可以連到放置相片的Flickr photo page去

而不能只是取用

<img src="http://photos8.flickr.com/xxxxxx_xxxxx_o.jpg"
width="450" height="306" alt="xxxxxxx" /></a>

這樣的語法來把Flickr當作免費的放圖空間

總之就是要有<a href=....這樣的語法啦

1/21/2007

Greasemonkey script: google at yahoo

讓 http://tw.yahoo.com 的搜尋改成google的,
重點是 form1.id='Form1nnew'; 如果不把form1的id換掉,只改form的action是不行的。

// ==UserScript==
// @name google search at yahoo
// @namespace http://birdegg
// @description
// @include http://tw.yahoo.com/
// ==/UserScript==

function googleAtYahoo(){
form1=document.getElementById('Form1');
form1.action='http://www.google.com.tw/search';
form1.id='Form1nnew';

i=document.getElementById('p');
i.name='q';

fr=document.getElementById('fr');
fr.parentNode.removeChild(fr);

ei=document.getElementsByTagName('fieldset')[0].getElementsByTagName('input')[2];
ei.parentNode.removeChild(ei);
}

(
function(){
googleAtYahoo();
}
)();

1/19/2007

小改版

這次改版重點是整齊,清潔,簡單,樸素,迅速,確實

  1. navbar弄掉,太礙眼,也太慢了
  2. quote的圖片改成date: URI,之前放在googlepages太慢了
  3. 因為navbar弄掉,所以弄了個search bar在左邊,code也簡單
    <form action="/search" name="f">
    <input value="" name="q" size="25" title="站內搜尋"/>
    <input value="search" type="submit"/>
    </form>

  4. 燒了一個RSS Feeds在左邊,順便學一下feedburner
  5. 無圖片化,只剩下feedburner的圖片,改天再弄掉

1/16/2007

Autocmd 與 modeline

Autocmd 與 modeline

假設我希望在開啟每一個 .py 檔的時候都執行上面 modeline 的那些指令,可以設定一個以下的 autocmd (寫在你的 .vimrc 或 Windows 下的 _vimrc 裡):

au BufRead *.py set ai et nu sw=4 ts=4 tw=79


Unix 基本指令: script 抓取 Terminal 資料, 存成檔案
* script [filename] # 開始記錄(Terminal 中的內容)
* exit # 此時就會將 Terminal 的內容寫入 [filename] 中

1/15/2007

greasemonkey script: auto refresh

var numMinutes = 20;
window.setTimeout("document.location.reload();", numMinutes*60*1000);

IBM - Speaking Unix series

putty ssh

Windows 下的 coLinux 環境設置

另外,我們可以把設定過的 putty session 存起來,這樣只要在桌面上建立一個新的 putty 捷徑,並在命令列的地方加上 “-load ” 就會自動載入設定,使用起來就更方便了。

利用公私鑰進行ssh login: server端
  1. cd ~
  2. mkdir .ssh
  3. cd .ssh
  4. ssh-keygen -t rsa (全按enter跳過, 產生兩個檔案id_rsa私鑰, id_rsa.pub公鑰)
  5. cat id_rsa.pub >> authorized_keys
  6. rm id_rsa.pub
  7. chmod 600 *
  8. copy 私鑰id_rsa到client端(PC)

利用公私鑰進行ssh login: client端
  1. puttygen->Load->id_rsa->save private key->private.ppk
  2. putty->SSH->auth->Browse->select private.ppk -> done.

再把ip or dns設成user@ip_or_dns就不用再輸入使用者名稱了.
最後設定putty的捷徑為"C:\Program Files\pietty0327.exe" -load session_name

1/13/2007

1/12/2007

【食】上華鹽酥雞

【食】上華鹽酥雞
新竹市~上華鹽酥雞....超好吃推薦
鳥窩看到的:

1. 請於晚上八點後再去,早到是沒有開的!
(有鑒於上次推薦延平大飯店時,有鳥友中午殺過去而煞羽而歸,把這點放最前面)
4. 我女友喜歡點甘梅薯條,但我覺得味道太鹹,不過真的很好吃!
5. 炭烤雞排可以請老闆剪開,這樣比較好吃,不過就比較容易軟掉喔~
6. 個人喜好不同,不過甜不辣炸的很酥、米血和米腸也很夠味,雞屁股是一定都會點。

1/05/2007

Bribing Bloggers

Bribing Bloggers
Joel寫出他對微軟送出預先安裝vista的acer法拉利notebook的看法.
下面是他對vista的看法

1. Do not, under any circumstances, consider upgrading an XP system to Vista... even if it's fairly new and even if it's Vista Supremo Premium Ultra-Capable.
2. When you get a new computer, if it comes with Vista pre-installed, that's when you'll upgrade.
3. Don't buy a new computer now just to get Vista. If your current system meets your needs, stick with it until you really need a new system. Vista is not reason enough for a new PC.
4. Need more details? Read Paul Thurrott's review.

第二點很有道理阿. 重點就是winxp is "good enough"
windows vista 各版本的比較: Understanding the Vista Product Editions

我的面試經驗談....

我的面試經驗談....
http://ln.twbbs.org/ln.html

Mastering AJAX

Mastering Ajax, Part 1: Introduction to Ajax
Mastering Ajax, Part 2: Make asynchronous requests with JavaScript and Ajax
Mastering Ajax, Part 3: Advanced requests and responses in Ajax
Mastering Ajax, Part 4: Exploiting DOM for Web response
Mastering Ajax, Part 5: Manipulate the DOM
Mastering Ajax, Part 6: Build DOM-based Web applications

掌握 Ajax,第 1 部分: Ajax 简介
掌握 Ajax,第 2 部分: 使用 JavaScript 和 Ajax 发出异步请求
掌握 Ajax,第 3 部分: Ajax 中的高级请求和响应
掌握 Ajax,第 4 部分: 利用 DOM 进行 Web 响应
掌握 Ajax,第 5 部分: 操纵 DOM

bookmarklet

Thinker: Right Click


javascript:function k(){document.oncontextmenu=null;}; k()

Jesse's Bookmarklets Site
This is freaking insane

javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.images; DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position='absolute'; DIS.left=Math.sin(R*x1+i*x2+x3)*x4+x5; DIS.top=Math.cos(R*y1+i*y2+y3)*y4+y5}R++}setInterval('A()',5); void(0);

1/04/2007

湘鼎坊:令人感動的平價美味

湘鼎坊:令人感動的平價美味

MoAB (Month of Apple Bugs)

Month of Apple Bugs 開跑
Application Enhancer (APE)
the Month of Kernel Bugs (MoKB) archive
1. MOAB-01-01-2007: Apple Quicktime rtsp URL Handler Stack-based Buffer Overflow
2. MOAB-02-01-2007: VLC Media Player udp:// Format String Vulnerability

兩個都差不多, 用過長的url造成buffer overflow. 下面強者是利用Application Enhancer的解法.
檢查url的長度, 太長就改成另外一個安全的url, 然後再送給本來的handler

static const char safeURL[] = "http://rtsp.example.com/example.mov";
void *guard_INet_ParseURLServer(char *url, uint32_t length) {
if (length > RTSP_MAXLENGTH) {
apeprintf("Someone probably just attempted to exploit CVE-2007-0015, url=%s\n", url);
return orig_INet_ParseURLServer((char *) safeURL, sizeof(safeURL)-1);
}

return orig_INet_ParseURLServer(url, length);

1/03/2007

機車

from PTT biker版

  • [輪胎]
    : 只是希望有一個可以在市區比較不會下雨那麼滑的輪胎而已..
    前馬吉斯 6012
    後B02應該就滿好用的了

  • [問題] 請問"好順"及G4的輪胎
    → ayumistory:前 BT39,後 B02。
    corlos:6012+6029,兩張小朋友就搞定,很好用
    kenchenx:6012 + B02 2張應該也可以搞定

    前輪建議:M6012(r或s都不錯)、bt39
    後輪建議:b02(耐磨但會翻胎)、6103(半熱熔但價錢較高)、6029(平價選擇)
    推 ilanman:B02不顧胎壓會翻很快
  • [安全帽]
    [問題] 華王入手17s 戴著安全帽po文
  • [機車行]
    : 話說高雄左營日財是家大家都推薦的店
    : 今日想過去換個皮帶
    : 不想白跑一趟想先打電話確認一下
    : 不過東機掛了,我實在查不到它的電話號碼
    : 有板友可以熱心提供一下嗎?

    日財機車精品
    老闆:陳清郎
    手機:0930103911
    市話:07-5570400
    地址:高雄市左營區天祥二路81號
    營業時間:週一到週六
    早上8點到晚上9點