Subscribe to RSS Subscribe to Comments Blog of Roy Chan

Blog of Roy Chan

使用 vim 編輯 web textarea (Firefox or Kazehakase)

用了 vi/vim 十多年,其他 text editor 對我來說確實很麻煩。大部份事用 vi/vim 做都有說不出的爽!!! 就算多年前因工作需要在 windows 寫程式寫,也懶得用 UltraEdit 等,抓個 vim windows 爽很多。近年,經常要在網頁上的 textarea 打一大篇文章,結果還是受不了,很多時需要在 copy&paste 到 vim 執行仔細的編輯。簡潔的按鍵自然是我喜用 vi/vim 的主要理由,regular expression 更是我編輯時不缺的利器。

幾年來,我花了不少工夫企圖把 regular expression 或 vi/vim 式的編輯引入 web,包括寫了些 bookmarklet 等,但始終和 vi/vim 差很遠。嘗試過幾個令 Firefox 使用 external editor 的 extension, 不過都不太有效。近兩年前,找到了 It’s All Text,終於把我這個難題解決了。

It’s All Text 這個 Firefox extension 安裝後,會在每個 textarea box 的右下角浮現一個 “edit” 小按鈕,按下就會把 textarea 的內容送去指定的 text editor 進行編輯,絕對是 vi/vim 的必裝 extension。

然而,這年來因為安全問題,我經常會同時使用多個 browser,用不同 browser 執行不同安全級別的 web apps。(都是 ajax 惹的禍)。Prism, Epiphany, Kazehakase,甚至 Opera 都會常用來代替 Firefox 執些較低 reliability 的 web site/apps (Prism 一般用來跑重要的 webapp 如 gmail 和 online-banking),Noscript extension 則用來限制不明網站的 javascript。不過用其他 browser 時,就少了 It’s All Text 用 external editor 的爽便。早期才發現用了半年的 Kazehakase 其實內建使用 external editor 的功能,多了個可以便利使用 browser。

在 Kazehakase 設定使用 gvim 很簡單,首先 UI Level 要設定為 Expert (View -> UI Level -> Expert),在 Edit -> Preference 中的 External Program,設定 Editor command 為:

gvim -f %s

就搞定了。 (-f 選項是避免 gvim 自動 fork 入背景工作,令 Kazehakaze 不知 gvim 完成編輯)

往後在要編輯的 textarea 按右鼠鍵在選單選 Launch Editor 就可以了。(當然是經謹關閉了 gvim 才好 submit web form)


Share It: [del.icio.us] [Technorati] [Google Bookmark] [Yahoo MyWeb] [Furl]


GNU/Linux HSDPA (3.5G) 上網!?

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

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

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


Share It: [del.icio.us] [Technorati] [Google Bookmark] [Yahoo MyWeb] [Furl]


Ubuntu 7.10 和 Fedora 8

這大半年的時間都很懶寫 blog, 一來忙 MSc, 二來也多花時間去整理 OSWikiHK。順帶提一提 Ubuntu/Kubuntu/Edubuntu/Xubuntu 7.10 (Gusty Gibbon) 的安裝手冊 (桌面伺服器)早在個多月前已完成了。也有份教人由 Ubuntu 7.04 (Feisty)升級至 7.10 的文章Fedora 8 (Werewolf)才完成了幾個星期 (LiveCD 倒時未正式動手)


Share It: [del.icio.us] [Technorati] [Google Bookmark] [Yahoo MyWeb] [Furl]


New Gadget: Nokia N800

Nokia N800

Let see my new Gadget!!! It’s not iPhone! Not EeePC! Not even the latest N810 but the previous version of Nokia GNU/Linux Internet Tablet N810 which released nearly a year. Wow!!!!!


Share It: [del.icio.us] [Technorati] [Google Bookmark] [Yahoo MyWeb] [Furl]


在咖啡廳外使用其免費無線網絡是違法的!!!

WiFi on car! 這好像點在匪疑所思,不過早前美國密芝根州的一名市民就因在其坐駕上「盜」用附近一間咖啡廳的免費無線網絡而被起訴。

美國密芝根州的Sam Peterson習慣每天都駕車經過Union Street Cafe鄰近並使用其免費無線網絡收發電郵。他的「古怪」習慣行為引起了一位警員的疑心並上前查問。Peterson當時並沒有意會到其行在道德上有問題而照直說出原因。結果Peterson就因此而被捕,並以未經同意進入他人網絡罪被起訴。因為Union Stree Cafe的免費無線網絡只是提供給其客人使用,而Peterson從未光顧或進入Cafe內。

根據密州的法例,Peterson最高可以被罰一萬美元及入獄五年。不過法官考慮到Peterson一直未有意識到其行為是違法,所以只輕判四百美元和四十小時社會服務,亦不留案底。

除了Peterson外,Union Street Cafe的老板亦未有意識Peterson的行為是違法。拘捕Peterson的警員亦說當時只意識Peterson已觸犯某條法例但並不知是那條。不過事實上Peterson的案件並首宗例子,類似例子在美國而有不少個案。其中一宗,一名阿拉斯架的男子更在本年年頭在公共圖書館外使用其公開無線網絡玩遊戲而被捕。


Share It: [del.icio.us] [Technorati] [Google Bookmark] [Yahoo MyWeb] [Furl]


Beryl 在北京的”Wah” 電腦新體驗

Ubuntu 7.04 Beryl Cube

上星期在南京北京走了一趟,到現在才有時間寫寫這次出差的經驗。

為北京分公司做宣傳,這次北京短短兩天半的時間走訪了幾間北京的大學和高等學院介紹GNU/Linux和Computer Forensics。由於事忙,一直未有準備演講的內容,加上北京同事設提的壓力,隨手找了最簡單的Beryl作演示,結果反應好得令我出奇。Beryl獨有的火燒視窗環形視窗切換器(Ring Window Switcher)等固然引來哄動的徊響。然而,傳統的cube和橡皮糖視窗招來”Wah! Wah!”的驚嘆!

微軟在宣傳Vista時就用一系列所謂”Wow”體驗的故事和所謂”Wow”電腦新體驗的口號。三月時,我就曾和YPWong討論過利用Beryl製造一些”Yeah”/”Yo”體驗的故事和Vista打對台,後來因時間問題不了了之。但這次北京之旅,我們確實真的利用Beryl打造了”Wah”電腦新體驗的故事。


Share It: [del.icio.us] [Technorati] [Google Bookmark] [Yahoo MyWeb] [Furl]


Vista和網上銀行保安

Bunny剛剛提到早幾天聽一個電台節目訪問M$ 香港區產品經理,提及在韓國等地都有報告指Vista未能登入一些銀行的網站,主持人問M$經理香港會否出現同一現像。經理回答因為香港沒有用韓國等地所使用的保安技術,所以不會有這種情況。

那究竟是香港保安技術追不上人家還是比人強? 或是說Vista的安全性很切合香港銀行的程度呢?


Share It: [del.icio.us] [Technorati] [Google Bookmark] [Yahoo MyWeb] [Furl]


QEDWiki

年多前曾思考過WikiWikiWeb在商業上的應用,今天在Youtube打釘時找到去年有關QEDWiki的Demo,似乎是WikiWikiWeb商業他的實例之一。


Share It: [del.icio.us] [Technorati] [Google Bookmark] [Yahoo MyWeb] [Furl]


Google Mobile 個人化首頁和中國地圖

今天才發覺原來Google Maps都有中國地圖,不過不在原本的Google Maps站,而是在中国Google站底下的maps目錄才找到。基本主要幾個大城市如北京、上海、南京、廣州和深圳的地圖都有,也可以用『搜索地圖』找到主要城市的地方名和主要街道名。不過和主站的地圖不一樣的是,這個地圖是沒有衛星圖片的。原因大家都猜到…….。

另外很多人都知Google個人化首頁在本月中開始提供Mobile版,大家以後可以透過手機一次過看很多內容。不過我在個人化首頁一直都找到自訂Mobile版首頁的方法,找了好一些時間才在Google的Cache中取會一篇Google Mobile舊文,才知道你可以在桌面電腦上到訪http://www.google.com/ig/cp來自訂Mobile版首頁。

P.S. 這大概算是bug,Top Stores(頭條報導)在桌面電腦上顯示中文版的,在Nokia的電話中卻變成了英文和外國新聞。

P.P.S. 企鵝佬修正Google中国地圖的url 是 http://ditu.google.cn/ ,Bunny亦修正Google Mobile版首頁的link可以在正常個人首頁底的Mobile字找到。


Share It: [del.icio.us] [Technorati] [Google Bookmark] [Yahoo MyWeb] [Furl]


Fix the MySQL character set problem after MySQL 4.1 forever!

I suppose many people had mention it before. It is talk about the output of your database become rubbish after you upgrade from older MySQL to 4.1. Experience people should senses that it is the problem because MySQL 4.1 get more support on multi-language and charset. You or me may already got the same experience in Oracle/Java and know that we should correct the charset of the MySQL server and client. However, the solution in people’s blog is in chaos.

Some ask you to “SET NAME utf8″ after each connection. Oh, that you need to search “mysql_connect” or “mysql_pconnect” in all your PHP application and put “mysql_query('SET NAME utf8')” after them. You may look through your php.ini or httpd.conf and see if you change the default client charset in PHP/apache but the fact is that the default client charset is fixed libmysql before compilation. You don’t want to compile libmysql again by yourself, right? Some ask you to put init-connect='SET NAME utf8‘ in my.cnf but it never works. Some said it should be init_connect instead of init-connect but still no luck. Some ask you to set default-character-set in section [mysql] of my.cnf but you want PHP will connect with UTF-8 by default too. Ok, here is the solution. What you need is add “default-character-set=utf8 in both [client] and [mysqld] sections in your my.cnf:

[client]
default-character-set=utf8

[mysqld]
default-character-set=utf8

The MySQL will use UTF8 after restart it. You can check it by typing the following in mysql:

SHOW VARIABLES LIKE 'character_set%';
SHOW VARIABLES LIKE 'collation%';

Reference


Share It: [del.icio.us] [Technorati] [Google Bookmark] [Yahoo MyWeb] [Furl]


Use this to teach your younger brother what is Pi (π)

Just saw this from digg.com:

You can show this GNU-free image to your younger brother/sistor when your mom ask you to teach them what is π -P


Share It: [del.icio.us] [Technorati] [Google Bookmark] [Yahoo MyWeb] [Furl]


One line shell command to show the top referer of your WWW site

First show you the big monster:

egrep ‘HTTP/[0-9.]*” *[23][0-9][0-9]’ access.log | \
  egrep -iv ‘\.(js|css|jpg|jpeg|png|gif)[” ]’ | \
  sed -e ’s/^.*HTTP\/[0-9.]\+”\?[[:space:]]\+[0-9]\+[[:space:]]\+\(-\|[0-9]\+\)[[:space:]]\+”\?//i’ \
    -e ’s/”.*$//’ | \
  egrep -v ‘^-’ | egrep -v ‘blog\.xychen\.org’ | \
  sed -e ’s/^http:\/\/[^\/]*\(\.google\.\|google\.pchome\|google\.sina\).*q=\([^&]*\).*$/[Google]:\2/i’  \
    -e ’s/^http:\/\/[^\/]*search\.yahoo\..*[^a-z0-9]p=\([^&]*\).*$/[Yahoo]:\1/i’ \
    -e ’s/^http:\/\/[^\/]*\.soso\..*[^a-z0-9]w=\([^&]*\).*$/[SoSo]:\1/i’ \
    -e ’s/^http:\/\/[^\/]*\.baidu\..*[^a-z0-9]wd=\([^&]*\).*$/[Baidu]:\1/i’ \
    -e ’s/^http:\/\/[^\/]*\.hisearch\.hinet\..*[^a-z0-9]k=\([^&]*\).*$/[Hinet]:\1/i’ \
    -e ’s/=/=3D/g’ -e ’s/%\([0-9A-F][0-9A-F]\)/=\1/gi’ | recode /QP.. | \
  sort | uniq -c | sort -nr | head

Here is the output of My blog:

     15 [Google]:中文字型
     12 [Yahoo]:速成字碼表
      9 [Google]:Beryl
      9 [Google]:beryl
      8 http://planet.debian.org.hk/
      7 [Google]: scim
      6 [Google]:色弱
      6 [Google]:任性
      5 http://www2.shoutmix.com/?sidekick
      4 http://www2.cbox.ws/box/?boxid=1129960&boxtag=9722&sec=main

It show me that 15 visits came to my site while searching “中文字型” with Google. 12 visits from searching “速成字碼表” with Yahoo. You can write a program to analyze the referer entry in your WW site log to obtain the above result. But I just show you how to do that with one line shell command. Sure, it might better to rewrite it with Perl while the one line shell command involve too many utilities and become too complex. But I had already finish it, why not share it.

First, I would like to filter out those unsuccessful visits and requests that only getting the images/javascript code/stylesheets:

egrep 'HTTP/[0-9.]*” *[23][0-9][0-9]‘ access.log | \
  egrep -iv ‘\.(js|css|jpg|jpeg|png|gif)[” ]

Then I need to dig out the referer from the log. I try to filter out the characters before and after the referer:

sed -e 's/^.*HTTP\/[0-9.]\+"\?[[:space:]]\+[0-9]\+[[:space:]]\+\(-\|[0-9]\+\)[[:space:]]\+"\?//i' \
  -e 's/".*$//' access.log >referer.log

Sure I don’t want to count the referer from my own site and request without referer:

 egrep -v '^-' referer.log | egrep -v 'blog\.xychen\.org'

Up to now, you can already pipe the result to the old shell trick - “sort | uniq -c | sort -nr | head” to show the top 10. However, being a crazy guy, I would like to group the refer from search engine (This part is complex and should be better using perl to handle it):

sed -e 's/^http:\/\/[^\/]*\(\.google\.\|google\.pchome\|google\.sina\).*q=\([^&]*\).*$/[Google]:\2/i'  \
  -e 's/^http:\/\/[^\/]*search\.yahoo\..*[^a-z0-9]p=\([^&]*\).*$/[Yahoo]:\1/i' \
  -e 's/^http:\/\/[^\/]*\.soso\..*[^a-z0-9]w=\([^&]*\).*$/[SoSo]:\1/i' \
  -e 's/^http:\/\/[^\/]*\.baidu\..*[^a-z0-9]wd=\([^&]*\).*$/[Baidu]:\1/i' \
  -e 's/^http:\/\/[^\/]*\.hisearch\.hinet\..*[^a-z0-9]k=\([^&]*\).*$/[Hinet]:\1/i' referer.log

While I’m insane, I even don’t want see those “%2F%e6“. Pls give me the “real” characters.

  sed -e 's/=/=3D/g' -e 's/%\([0-9A-F][0-9A-F]\)/=\1/gi' | recode /QP.. referer.log

I convert the URI encoding to Quota-Printable and decode it with recode. OK, now, I can use the old shell magic to get the top 10. First I sort it to group the same referer.

sort referer.log

Kick out the repeated line, left one only and the number of it had repeat.

sort referer.log | uniq -c

Sort the result with no. of repeat:

sort referer.log | uniq -c | sort -nr

Show only the top 10:

sort referer.log | uniq -c | sort -nr | head

Known problem

  1. It only a quick trick. I haven’t optimize it yet. Any recommendation?
  2. Fail to show the search keyword with the correct encoding. Most search engine use UTF8 but CN engine love GB2312 and some TW engine seems still using stupid Big5. Ummm… I nearly forget the zh-autoconvert…. Oops, zh-autoconvert can’t distinguish the UTF8 with Big5 or GB2312.

Share It: [del.icio.us] [Technorati] [Google Bookmark] [Yahoo MyWeb] [Furl]


店鋪老闆們!請讓我們在iPhone登陸香港後可以容易點找到你們~~~~~~

Google Map最近終於有香港地圖了,雖然仍Search不到香港地方名,但看到一大堆香港街道路名,感覺很好。希望各香港的店鋪老闆快點到Google Map登記一下你的店鋪位置和其他資訊,讓我們在iPhone登陸香港時可以像Steve Jobs早幾天在MacWorld 2007 Keynote上般用iPhone隨時可以用Google Map找到周圍同類型的店鋪並致電說:「噢,對不起!打錯電話!」


Share It: [del.icio.us] [Technorati] [Google Bookmark] [Yahoo MyWeb] [Furl]


本週新聞


Share It: [del.icio.us] [Technorati] [Google Bookmark] [Yahoo MyWeb] [Furl]


No SkypeCast

Somebody ask me if HKLUG can provide SkypeCast service for members to discuss things with Skype on the last LinuxTalk. I really concern if the GNU/Linux version Skype support that at that time (Indeed, I doesn’t comfortable with using proprietary software and proprietary standard on HKLUG stuff) Unfortunately, as what I guess, SkypeCast require Skype 1.4 while the latest Skype for GNU/Linux is 1.3. Therefore, ………


Share It: [del.icio.us] [Technorati] [Google Bookmark] [Yahoo MyWeb] [Furl]


亞太IT大災難

慘過世界末日!!


Share It: [del.icio.us] [Technorati] [Google Bookmark] [Yahoo MyWeb] [Furl]


是日新聞

以下是這兩天我留意的新聞:


Share It: [del.icio.us] [Technorati] [Google Bookmark] [Yahoo MyWeb] [Furl]


HP如何追蹤電郵

近期IT界熱門話題少不了HP調查機密外涉醜聞。其中HP追蹤電郵的方法頗有趣。HP在整個調查及以住的調查事件中都曾使用ReadNotify.com的服務。這間公司可以幫顧客把一個追蹤小圖殖入要追蹤的文件中(可以是MS Office 或 PDF文件)。當顧客把做了手腳的文件寄出去,就可以可以播過ReadNotify.com的網站追蹤到文件何時及在何IP地址被開啟過。HP的保安職員表示他們亦用這項服務追蹤被盜產品的位置。

說穿了,這種技術和以住一些公司或Spammer追蹤HTML電郵的手法差不多,做法亦很簡單。不過現時這種追蹤手法的合法性正被收質疑。

P.S. 無聊看看台灣CNET的翻譯,爛得很!


Share It: [del.icio.us] [Technorati] [Google Bookmark] [Yahoo MyWeb] [Furl]


What religion do you fit in with?

似乎正路過頭!十年都無乜變過!

You fit in with:
Atheism


Your ideals mostly resemble those of an Atheist. You have very little faith and you are very focused on intellectual endeavors. You value objective proof over intuition or subjective thoughts. You enjoy talking about ideas and tend to have a lot of in depth conversations with people.

60% scientific.
60% reason-oriented.

Take this quiz at QuizGalaxy.com


Share It: [del.icio.us] [Technorati] [Google Bookmark] [Yahoo MyWeb] [Furl]


How Do People See You?

Slow and Steady
Your friends see you as painstaking and fussy.

They see you as very cautious, extremely careful, a slow and steady plodder.

It’d really surprise them if you ever did something impulsively or on the spur of the moment.

They expect you to examine everything carefully from every angle and then usually decide against it.
How Do People See You?

Share It: [del.icio.us] [Technorati] [Google Bookmark] [Yahoo MyWeb] [Furl]


Based on Fluidity© 1998-2007 Roy Hiu-yeung Chan