JeffHung.Blog

(My smile insists of having nose. :-)

big/little endian 的典故

在《C++ Primer 答客問 28~40》看到的 big/little endian 典故:

"The term big endian is derived from Jonathan Swift's Gulliver's Travels, in which the Big-Endians were a group of people who opposed the emperor's decree that eggs should be broken at the small end before they were eaten."
-- Microsoft Press Computer Dictionary 3/e p.49

User defined asertion in PHP

PHP 內建的 assertion 功能已經很強了,但有時候,就是差了這麼一點點,因此,也許我們需要自己做自己的 assertion。
自己做 assertion 怎樣做都可以,反正是自己做。只不過,有些東西還是不一定容易取得,好比說,發生 assertion failure 的 file name、line number。這些東西內建的 assert() 會印,但如果我們要自己做 assertion,那我們就得自己來。
在自己的 assertion function 裡面用 __FILE__、__LINE__ 這類 magic constants 也只會印出實做自己的 assertion function 那一處的檔案及行號,無效。幸好,PHP 裡有個和 Perl 內建的 caller() 功能更強一些的 debug_backtrace()。利用這個函式,我們就可以做自己的 assertion function,用法與內建的 assert() 幾乎一致:

function my_assert($expr)
{
eval('$eval_result__=('.$expr.');');
if (!$eval_result__) {
[...]

Declare struct in C/C++ enabled style

我都是這樣子 declare structure 的,當然,這樣子的 structure 必須要是單純的struct (ie. POD),不能有 member function 之類 members 存在:

#ifndef __cplusplus
typedef struct LinkList LinkList;
#endif /* __cplusplus */
struct LinkList
{
/* ... */
LinkList* next;
};

這樣一來,我們就可以像 C++ 一樣直接使用 type name 來 declare instances。幾個重點:

其實 C++ 也可以 struct Foo 或是 Foo 混著用來 declare instances,不過這樣總是難看了些,所以用上面那招,統一使用 C++ 的方法,包括在 structure 裡面的 member 在內。
在 C/C++ [...]

輸入網址,輸出以文字模式排版的網頁內容

既然有上一篇個技巧,當然就可以包成網頁,平常當成一個 utility 來用,這樣若是要轉文章到 bbs 上的話,就可以叫這個網頁出來排版,畫面就可以排得漂漂亮亮啦。:-)
呈現出來的效果如:http://www.jeffhung.idv.tw/html2text.php (目前無法使用)。
<?php
// Author: Chien-Chou Hung
// License: BSDL
?><html>
<head>
<title>html2text</title>
</head>
<body>

<form name="f" method="POST">
<b>Convert:</b> <input type="text" name="url" value="<?php

echo (empty($url) ? "http://" : $url);

?>" size="50" maxlength="255">
<input type="submit"><br>
Text browser:
<input type="radio" name="browser" value="links" checked>
[...]

抓網頁並以文字模式輸出

簡單的小 script,能夠抓任意網頁,然後以文字模式的方式排版輸出,用到 lynx 跟 awk。用的時候把 $url 代換成要抓的網址就可以了。
lynx -dump $url | awk ' /process$/ { print; exit } { print } '

PHP equivelent include guards

在 C/C++ 裡,可以用 #ifdef/#define/#endif 來做 include guard 避免重複引入,而在 PHP 裡則需要用 include_once() 及 require_once() 等 _once 系列的函式,來避免重複引入。比較麻煩的是,對於 PHP 而言,相對路徑的起點是程式碼執行起點所在的那個檔案的目錄,而不是呼叫 include_once()、require_once() 的程式檔案所在的目錄。
舉個例子來說:被執行的 a.php 裡引入了 lib/b.php,然後 lib/b.php 又引入了 c.php,此時,PHP 會到 a.php 所在的目錄尋找 c.php,而非 b.php 所在的目錄尋找。
這個問題,對於 library writer 會產生相當大的困擾,除非使用者將 library 安裝至 PHP 的 library 目錄 (例如在 FreeBSD 下用 ports 安裝 PHP,其 library 目錄即為 /usr/local/lib/php),直接以該目錄為相對路徑起點,才不會有此困擾。
因此,我寫了下面這些 functions 來解決這樣的問題:

////////////////////////////////////////////////////////////////////////
// Hacks for include [...]

令人傻眼的 reject letter

學弟投稿論文被退回,退回也就算了,回信竟然如下,令人傻眼。

由於會議時程安排的因素以及接受的論文數有限,無法收錄您的論文『xxxxxx: xxxxxxxx xx xxxxxxxx xxxxxxxxxxxxx xxxxxxxxx xxxxx xxxxxxxxx』, 實有遺珠之憾。謹將審查意見附於信件中,供您參考。
Review:
對於前人的方法提出有效的攻擊(即,original signer 可模仿proxy signer的簽章),並且提出了一個簡單有效的改善方法來抵禦此攻擊。不過前人的方法本身的數學式非常地複雜。」

(已徵求同意,並將論文名稱已施以馬賽克處理)

令人噴飯的新式身份證照相規格範例

既然 edwardc 長輩都在噴了,大家一起來噴吧:《身份證照片超龜毛》。

Bloglines Plumper

用 bloglines 用到一半,跑出這個畫面來。

希望會更好。 :-)

Google 沒頭頭很久了

一樣在 Search Engine Watch Blog 看到這篇《After More Than A Year, Google Remains Without Chair》,用比較俚俗的話來說,就是「Google 沒頭頭很久了」。最後的 comment 頗令人玩味:

Google's strong performance is noted as one reason why investors might not be concerned.

實際上,其實還是有頭頭的,只是沒掛名而已。沒掛名就真的可以不必聽董事會的話嗎?看來,好像也沒多少董事要去打擾 Google 的運作。

 Prev 1 2 3 ...90 91 92 93 94 ...98 99 100 Next