Thursday, October 30, 2008

Python 與 Zope 入門

Python 與 Zope 入門

前言

如果你是程式語言的新手,恭喜你,因為這裡介紹的正是合適入門的開放源碼語言工具;如果你是其他語言的老手,同樣恭喜你,因為這裡介紹的內容,很可能是你正在尋找的出路…


對於已經愛上開放源碼的朋友來說,每個人都有屬於自己和開放源碼之間的機緣與情愫,以我為例,當初是因為對搖滾樂的熱愛,而一步一步地走進這片自由開放的天地。

先讓時間回到 1995 年,那時候我是一個泡在電腦教室裡,一待就是十小時的政大學生,除了迷上 TANet 所流行的校園 BBS 之外,Internet 上有趣的新鮮玩意,還有 Gopher、Newsgroup、IRC 等。在新學期開始沒多久,我依舊快樂地享受網路世界的冒險之旅,無意間看到在電腦教室外行色匆匆的鳥合 (陳彩合),他跟我說道「等一下我會介紹 World Wide Web,你有沒有興趣來聽?」當然囉,難得鳥合不再開口閉口講我聽不懂的 sendmail,當下跟著進教室聽他介紹 WWW 這個「網路新名詞」。

初見 WWW 的感受,對我啟迪很大,原本想要拜師學 C 語言以及當 BBS 站長的我,沒多久就跟師父 - 黃志中講,「我覺得 WWW 才是值得投入的千秋大業啊」。現在來看,猶能感受當初那股「不知天高地厚」的傻勁。

沒多久,我就利用自己在學校宿舍的 486 PC,以 Linux 和 Apache 架起了一個陽春的 Web Server,內容就是介紹我最喜愛的搖滾樂團,期間還收到一些令我驚訝的回應與鼓勵。接著,我和網友死黨們,在政大校園裡組了「網路應用推廣社團」,打 算仿照交大 CCCA 運作模式,以政大學生宿舍、學生社團、行政服務為先期焦點,介紹各式網路應用並協助其普及。

後來的事就不難想像啦,因為自己花了一些時間在玩電腦網路,大學畢業前,就打算從財管系再換跑道到資管研究所,而且從原本想要當 Unix 維修工程師,變成現在的 Open Source 工作者。好啦,如果要用 500 字講自己和開放源碼的因緣,就是這些了。

初識 Python 與 Zope

在 2000 年底之際,我想要尋找一個 WebDAV 伺服器的開放源碼實作品,無意間遇上了 Zope 這套 Web Application Server,在 Zope 的簡介資料中,發現它是以 Python 程式語言所開發完成,因此機緣,讓我踏上學習與享受 Python 的這條路。Python 與 Zope 都是非常值得介紹及推廣的開放源碼工具,我很高興能夠利用這個機會,將自己所知的心得經驗分享給同好。相信 Python 的易學易用,能讓新手輕鬆上路,享受撰寫程式的樂趣和成就感,Python 廣大的模組功能支援,能讓擁有「懶惰美德」的程式人員,快速搞定原本惱人的開發需求。如果你是尋求大型網站系統解決方案的程式人員、資料庫管理人員,或是 內容管理人員,Zope 系統絕對是值得你留意及投入的開放源碼應用工具。

難以寫出優美程式碼的語言,勢必也難以寫出優秀的程式碼。
A language that makes it hard to write elegant code makes it hard to write good code. -- Eric S. Raymond

什麼是 Python ?

從技術層面來看,Python 是一種物件導向式 (object-oriented) 程式語言的名稱,它具備直譯式 (interpreted)、互動式 (interactive)、模組化 (modular) 的功能及特色,經常被拿來與 Visual Basic、Perl、Java 等程式語言相提並論。Python 語言的作者是Guido van Rossum,最早在 1990 年之際開始進行發展,其程式實作迄今已普遍存在於各式作業平台上,例如 Linux、UNIX、Windows、Mac、OS/2 等。其他相關的延革資訊,請參考列表1所示。

圖1 Python 語言之父 -- Guido van Rossum

Python 同時也具備動態定型 (dynamic typing) 的特性,程式人員不需要宣告變數型態,其內建物件型態 (built-in object type) 包括 list、dictionary、string、tuple等,能夠滿足最常見、最重要的應用需求,其內建的工具 (built-in tool) 包括 slicing、concatenating、sorting、mapping 等,能夠協助程式人員專注於處理最關鍵的技術議題,其內建的函式庫包括網路服務 (http、ftp)、檔案處理 (regular expression、HTML、XML、socket) 等,在圖形介面的選擇上,較引入注目的包括有 wxPython (如圖2所示)、PyGTK (如圖3所示)、PyQt 等,此外還有豐富的線上文件,可參見列表2。

圖2 以 wxPython 示範 Unicode 應用服務

圖3 PyGTK 程式示範畫面

Python 語言的執行檔格式 (常見之執行檔副檔名為 .pyc),與 Java 語言的 byte code 格式類似,byte code 執行檔具跨平台特性,例如可從 Windows 上複製到 Linux 直接可用,反之亦然。值得一提的是,它可以和其他語言進行結合,具有良好的「黏膠」(gluing)功能,例如透過「擴充機制」(extending) 來讓 Python 執行另一個 C++ 程式,透過「內嵌機制」(embedding) 來讓 Python成為 C/C++ 等應用軟體的一部份。如此一來,開發大型應用軟體時,使用 Python可以達到快速開發 (rapid model and development) 的效果,同時也內嵌 C/C++ 程式,以便改善執行效率的瓶頸點。

從 Python 2.1 開始,其核心納入了 PyUnit 模組,協助程式人員利用它來體驗 Extreme Programming (XP),同時,XP 的精神也很自然地能夠吸引 Python 程式人員。以 Zope 開發社群為例,程式人員經常巡迴舉辦世界各地的「衝鋒編程聚會」(Sprint Coding Party),由資深的核心軟體開發人員擔任「教練」,透過小組型式,讓程式人員在最短的時間內完成特定的程式開發目標。[註1]

從非技術的角度來說明,Python 是一種高階的通用式 (general purpose) 手稿 (scripting) 語言,藉由包裝良好的套件檔案 (如 Windows 的 Installer 或 Linux的 rpm 工具程式),新手很容易就能安裝最新版的 Python 工具,如圖4所示。對於一時之間離不開 Windows 平台的朋友,我特別推薦使用 cygwin 工具軟體,其內附的 Python 程式及操作環境,能夠提供相當完整的基本服務,如圖5所示。

圖4 Windows 平台上的 PythonWin 示範畫面

圖5 cygwin 裡的 Python 操作示範畫面

Python 具有語法簡易、結構清楚的特色,在撰寫 Python 程式碼的過程中,很容易享受到「碼隨意至」的直覺快感,不會有思路阻塞的困擾。同時,它利用縮排方式,協助程式人員能夠對原始碼有一目瞭然的感受,有助於 新手快速入門起步。如果你想要找尋類似 Perl 社群的 CPAN 程式碼倉庫,參考許多 Python 好手所貢獻的原始碼,那麼別錯過 SourceForge.net、Freshmeat.net、Starship.Python.net 或 Vaults of Parnassus 網站,對於想要學習程式的朋友而言,裡頭稱得上是知識的大寶山呢。

開放源碼授權

絕大部分的 Python 程式為 Python 軟體基金會 (Python Software Foundation )所有,但整個 Python 程式皆受 Python License 規範 [註2]。其授權方式主要特色包括:

  • 自由使用: 商業或非商業皆可,內嵌或擴充都不用付授權費。
  • 自由散佈: 以原始碼或二進位元 (binary) 方式散佈原版或修改過的 Python 都可以,也可以用二進位元方式散佈你的 Python 擴充模組。
  • 在你散佈的版本中,不可以移除 Python 軟體基金會的版權宣告。
  • 開放源碼創進會 (Open Source Initiative) 已認證 Python License 為開放源碼的授權條款。
  • 自由軟體基金會 (Free Software Foundation) 也認定 Python License 和 GPL 相容。

    開放源碼世界的程式語言選項很多,Python 確實只是其中的一個優秀選擇,對我而言,選擇它最關鍵的原因有二,一來 Python 是「極佳的入門踏腳石」,二來 Python 具有殺手級應用軟體 - Zope (甚至是 Plone 這樣的工具)。

    我個人稱不上是一位軟體工程師,平常若有編寫程式的機會,大抵是自己餘暇的娛樂享受,但我能夠體會程式人員想要與人分享編寫程式甘苦的心情。Python 與 Zope 社群所營造的活潑、和諧、開放氣氛,是促使我要把這個好工具介紹給身邊朋友的動力。

為什麼要學 Python ?

長期以來,台灣以資訊硬體的代工生產成就聞名於世,但在軟體方面的發展,目前仍位居全球的邊緣化位置。全球的華人都很聰明勤奮,台灣人也呈現類似的 特質,如何從這樣的良好特質出發,讓台灣的軟體發展現況有所改善呢? 此刻來看,華人在軟體部份的投入,主要也是以「代工型式」進行,拿美國的大型軟體公司或網路公司做例子,其軟體工程部門,很多就是印度或華人工程師,他們 在美國的創業環境中,以優異的「數理能力」與「語文溝通訓練」為基礎,成為軟體公司裡「編程部隊」的主要成員。

對照上述的例子,在台灣有心投入軟體發展的朋友,還能多做些什麼呢? 至少有個工作項目,就是推廣程式語言的學習與應用,而 Python 語言就是我認為極佳的入門選擇。一個軟體工程師的養成,大抵需要從「數理邏輯基礎」、「語文溝通能力」紮根,並且具備「樂於不斷學習與創作」的人格特質, 應用 Python 語言及其開發環境,能夠讓一位軟體工程師立於非常理想的學習起點。

從教育紮根

老師對學生具有相當大的潛移默效果,台灣的資訊教育工作人員,多數期望能夠引導學生「合情合理合法」地獲得學習工具及資源,但坊間能夠提供給老師的 教材種類及型式還不夠多樣,以致老師們只能牽就於特定廠商所提供的教材手冊,甚至間接影響學生使用了非法取得的程式開發工具,造成老師與學生雙方的困擾。 這部份的問題,可以嘗試改用開放源碼的程式開發環境及工具來避免,因為開放源碼授權的軟體,非但可以免費或低價取得,也歡迎再複製、修改、散佈給其他人, 非常有利於教學研究的場合。

不過,開放源碼的程式設計工具書,大抵也還有不足之處,目前坊間以 PHP 或 Perl 的應用類書籍居多,英文版的 Python 書籍 (參見列表3),質與量雖然也開始增加,但中文的書籍、網路資源及介紹專文,都有許多值得提昇之處。在此,這篇文章算是我個人的棉薄貢獻,真心期盼有拋磚 引玉之效,邀請更多同好共同投入,可以參與的項目包括翻譯計畫、同好聚會、技術交流、訓練課程等。[註3]

Python 這項工具擁有許多迷人的特色,整理如列表4所示,目前在開放源碼世界裡相當受到好評,許多活躍的 Python開發人員,是來自於歐洲、美加、澳洲等地,大陸地區最近也開始活絡起來。雖然台灣的市場現況,Visual Basic 或 Java 似乎還是商業主流選擇,但仍然並未影響我個人的願望,就是要在華人地區推廣 Python 程式語言,當作中學生的程式設計入門工具,因為從 Python 入門之後,要進一步去學習與應用 C/C++ 或 Java,也都是相當輕鬆自然的事,不會有學習成果浪廢的顧慮。

如果,你對於 Python 的教育推廣議題有興趣,歡迎參加「全國中小學校園自由軟體應用諮詢中心」的通信論壇區 [註4],這個通信論壇是由軟體自由協會(Software Liberty Association of Taiwan, SLAT) 在教育部的補助下所建置,目前已有包括 Python、Zope、PHP、MySQL 在內的課程在進行。

哪些人在用 Python ?

若參考 Python 在各大軟體開發單位的實際應用狀況,知名的例子包括有:Yahoo! 網站的 Maps 與 Groups 服務,都使用 Python 來進行開發;Google 網站從創業之初,其工程師就利用 Python 來開發搜尋引擎功能,目前他們公司仍然急需更多 Python 工程師;美國太空總署 (NASA) 利用 Python 來實作下一代新式的 CAD/CAE/PDM 大型應用系統,他們認為 Python 提供的強大功能與彈性,完全能滿足目前的需求。

幾個常見的 Python 應用程式,諸如 mailman 通信論壇、Red Hat Linux 的安裝程式 Anaconda、PyGame遊戲軟體模組群等。除此之外,Python 在各行各業中也被廣泛應用,著名的成功案例,包括生物資訊產業、製藥業、半導體製造業、電影動畫產業、電腦遊戲產業、金融銀行業、太空科學領域等。其他更 多的應用資訊,可以在 Pythonology 網站 [註5] 上看到。

進一步來看,程式語言是軟體開發過程中的底層工具之一,上層的開發環境與框架 (framework) 也常是程式人員關心的議題,以網頁應用軟體開發 (Web Application Development) 這個領域為例,Zope 就是目前多數 Python 程式人員共同參與的開發框架及實作軟體,同時,在歐洲就興起許多靠 Zope 這套開放源碼軟體,所衍生出顧問、訓練、客製化服務的商業模式,知名的例子有 Beehive、Zope Magazine、Ingeniweb、Nuxeo、REFLAB、Zettai.net 等。

類似的服務及商業模式,此刻也在大陸地區興起,潤普科技 (ZopeChina) 就是其中的一例,而且同樣伴隨有 Python 與 Zope 的社群,稱為「中國 Zope 用戶組」(CZUG.org)。相對來看,目前台灣的 Python 與 Zope 開發人員,其凝聚力仍未跨過組成商業公司的門檻,還有待強化程式人員之間的連結。值得一提的是,在學術界倒有展開一些開發及應用實例,諸如中研院資訊所的 ShareTone 專案,是一個以 Zope 為開發平台的協同溝通系統;而長庚大學黃朝錦老師的 LiveZope 專案,則是採用 Knoppix 為基礎的 Zope 應用光碟。上述兩項專案,都在開放源碼軟體競賽中獲獎,具有應用示範的效果。

什麼是 Zope 及 Plone ?

Zope 指的是 Z Object Publishing Environment,它是以 Python 程式語言為基礎的 Web Application Server 框架及實作品,其框架概要如圖?所示。每次我用技術性的方式展示 Zope,效果總是有限,因此這裡想要倒回來介紹。簡單地說,有了 Zope,就可以讓人快速擁有一部「架站機」開發平台,類似的例子有 WebSphere、Enhydra 等,如果你希望馬上有個又炫又貼心的快速架站機,即類似XOOPS 這樣的軟體工具,那麼還可以使用以 Zope 及 CMF (Content Management Framework) 為基礎所強化的 Plone 工具軟體。

圖6 Zope 系統框架概要示意

簡言之,Python 的殺手級應用是 Zope,而 Zope 的殺手級應用是 Plone,從 O'Reilly 在「開放源碼社群送進 COMDEX」競賽中 [註6],Plone 與Zope 的勝出結果來看,目前社群朋友對 Plone 的喜愛與支持正在熱頭中。另外值得一提的是,第一屆 Plone 研討會也在 2003 年十月間舉辦,會場中揭示了許多 Zope及 Plone 的最新發展規劃,包括 Subversion 與 Plone 的結合,以及 XML 使用者介面的搭配。

Plone 是一個整合過的軟體工具,最容易上手的方式,就是下載 Plone 在 Winodws 平台上的安裝程式,如圖7所示,然後過程中「按下一步」即可,如圖8所示。

圖7 Winodws 平台上的 Plone 安裝畫面

圖8 完整安裝 Plone 的選項畫面

Zope 與 Plone 的發展歷史

在 1996 年之際,Zope 的作者 Jim Fulton 受邀擔任 Web CGI 程式設計的講師,原本不大懂什麼是 CGI (Common Gateway Interface) 的他,在不滿意 CGI架構方式下,重新以 Python 語言開發了幾個提供網頁物件出版功能的模組,這些模組分別稱為 Bobo、Document Template、BoboPOS,後來在繼續擴充模組的情況下,Zope 的前身於焉誕生,Jim Fulton 並組成一家 Digital Creations 公司展開 Zope 的開發及商業化路程,現在,Digital Creations 公司已經正式更名為 Zope 公司,宣示 Zope 在商業化市場上更堅定的腳步。

Zope 系統最早是針對新聞媒體界的應用需求所設計,因此除了一般的會員管理 (membership management)、安全機制 (ACL management)、內容物件管理 (content object management)、搜尋引擎與索引 (catalog and indexing) 之外,也很快納入版本管理 (version control management) 以及工作流程管理 (workflow management) 等服務。這些大型入口網站所必備的服務功能,Zope 公司的工程人員,特別以一個稱為 CMF (Content Management Framework) 的開放源碼專案獨立開發,由於 CMF 擁有良好的擴充及延伸彈性,引發更多奠基在 CMF 之上的改善計畫,Plone 就是這類專案計畫中的佼佼者。

CMF 是一個在 Zope 開發環境之上的入口網站服務架框,由於它的開發焦點是在基礎服務模組的研發與測試,長久以來都有不夠穩定,介面不夠美觀、易用度不高的缺點,Plone 專案計畫的主持人 - Alan Runyan 與 Alexander Limi,便接手解決上述的問題,沒想到這樣的改善構想,迅速吸引廣大開發者的認同與參與,Zope 與 CMF 便退居 Plone 這顆閃亮巨星幕後了。

中文支援狀況及其他

提 Zope 及 CMF 的同時,真的得好好介紹 Plone 一番,因為我們所關心的「中文化議題」,Plone 開發團隊照顧得相當貼心,這也是 Plone 在歐洲地區廣受歡迎的主因之一。

Plone 與 Zope 都是以 Python 語言為基礎所開發,因此 Python 本身的多國語文支援能力,也就變成「天生限制」了。新版的 Python 早已經支援 Unicode 內碼,加上我們也下載得到 Chinese codedec 檔案,Python 底層的內碼轉換工作大抵沒問題,且讓我們觀察一段 Python 的測試,以瞭解其基本的運作原理,如列表5所示。值得一提的是,「許功蓋」問題要注意到反斜線。

大陸地區的社群朋友貢獻了 ChinaPack 及 CJK Splitter 工具,用以協助處理Zope 系統裡的中文斷字斷詞問題。最後,再搭配 Page Template 的 I18N 支援,Plone 使用者只要利用合適的本地化模組 (localizer),就可以輕鬆地擁有多國語文版本的入口網站系統。簡單地說,因前人的努力,後人就可以乘涼,這也是開放源碼開發模式的優勢所在。有 興趣參加 Plone 的多國語文工作小組 (I18N Team) 的朋友,別忘了到 http://plone.org/development/teams/i18n/ 網址找尋更多資訊。

另外,如果有朋友想知道 Python 及 Zope 開發環境下,是否具有不錯的整合開發工具 (IDE tool),在此優先推薦 WingIDE 這套軟體,但它並不是開放源碼軟體,其操作介面如圖9所示。

列表 5 Unicode 物件的指定及操作方式

>>> big5str = 這是 Big5 中文字串
>>> ucsstr = unicode(big5str, big5-2003)
>>> ucsstr
u'\u9019\u662f Big5 \u4e2d\u6587\u5b57\u4e32'
>>> print ucsstr.encode(utf-8)
\xe9\x80\x99\xe6\x98\xaf Big5
\xe4\xb8\xad\xe6\x96\x87\xe5\xad\x97\xe4\xb8\xb2

>>> print ucsstr.encode(big5-2003)
這是 Big5 中文字串

圖9 WingIDE 執行偵錯模式的畫面

後記

在本文中,我刻意讓內容摻雜技術與人文的元素成份,因為,我相信「科技始終來自於人性」,電腦網路只是人們進行溝通與創作的工具,程式語言是人類與 機器的溝通型式,軟體是人們模擬現實世界的創作成果。謹將本文獻給我的父母,當我還是個國三學生時,很幸運地家裡就有一台宏碁 PC,是它讓我開啟通往電腦世界的窗。

這篇文章是一系列 Python 與 Zope 介紹的開端,希望你會喜歡它,下期我們將進一步介紹如何以 Plone 工具軟體,快速建置入口網站系統,並進行客製化。

Python 之發展延革

  • 一九九一年由 Guido van Rossum 於阿姆斯特丹大學創作及發展。
  • 二○○○年至二○○三年七月間,Python 語言由 Zope 公司支援的 PythonLabs 所維護開發,開發團隊的領導人仍為 Guido,但目前他已離開 Zope 公司。
  • 早期 Python 以 C 語言為基底撰寫而成。
  • 以 Java 語言為基底的 Python 語言實作 - Jython 正在發展,並整合 Microsoft .NET 架構。

學習 Python 的網頁資源

如果你是 Python 初學者,可以從下列的 Python 學習資源列表挑選幾篇來閱讀,這些資源都可在網路上免費取得:

  • Python 簡介 -- Python.org 網站上的教學列表。 http://www.python.org/doc/Intros.html
  • Python 教學手冊 -- Guido van Rossum 所撰寫的 Python 教學手冊。 http://www.python.org/doc/tut/
  • 編程學習手冊 -- Alan Gauld 所撰寫的編程教學手冊,除了強調 Python 語言之外,也包含其他程式語言。 http://www.freenetpages.co.uk/hp/alan.gauld/
  • 電腦科學家是這樣想的 (Python 版本) -- http://www.ibiblio.org/obp/thinkCSpy/
  • 深入學習 Python -- 針對有經驗程式人員的免費教學手冊。 http://diveintopython.org/

學習 Python 的四本好書

坊間已出現越來越多 Python 書籍,不過,中文版本的還不算多,有賴更多社群好手投入。

  • The Quick Python Book -- by Daryl D. Harms, Kenneth McDonald, Manning Publications Company 2000
  • Practical Python -- by Magnus Lie Hetland, Apress 2002
  • Text Processing in Python -- by David Mertz, Addison Wesley 2003

Python 的特色

    和其他知名的手稿語言 (script language) 相比,Python 具有下列特色:

  • 物件導向式 (Object Oriented)
  • 直譯式、交談式 (Interpreted, Interactive)
  • 跨平台 (Cross Platform)
  • 容易安裝 (Easy Installing)
  • 易學易用 (Easy Learning)
  • 語法結構清晰 (Clear Syntax and Structure)
  • 延伸與內嵌 (Extended and Embedded)
  • 開放源碼 (Open Source)

說明 網址

Python 資源列表

  • Python 主網站 http://www.python.org/
  • wxPython http://www.wxpython.org/
  • PyGTK: GTK+ for Python http://www.pygtk.org/
  • PyQt http://www.riverbankcomputing.co.uk/pyqt/
  • Vaults of Parnassus: Python Resources http://www.vex.net/parnassus/
  • PyGame http://www.pygame.org/
  • 葉平老師的 PythonCourse Wiki http://wiki.scicos.net/PythonCourse

Zope 資源列表

  • Zope.org http://www.zope.org/
  • Zope Magazine http://www.zopemag.com/
  • Content Management Framework http://cmf.zope.org/
  • Plone http://www.plone.org/
  • 全國中小學校園自由軟體應用諮詢中心 http://www.ossacc.org/
  • ShareTone Project http://www.sharetone.org/
  • LiveZope Project http://zope.org/Members/cchuang/LiveZope-0.1.2_released
  • Zope China http://www.zopechina.com/
  • Zope Newbies http://www.zopenewbies.net/
  • ZopeLabs http://www.zopelabs.com/
  • Zettai.net http://www.zettai.net/
  • WingIDE http://www.wingide.com/
  • Beehive http://www.beehive-eu.com/
  • tcchou http://blog.tcchou.org/
註1: Zope 3 UI Sprint
http://www.zope-europe.org/sl2003/uisprint

註2: Python 授權條款的細節
http://www.python.org/psf/license.html


註3: Python 於教育領域之推廣應用
http://www.python.org/sigs/edu-sig/


註4: 全國中小學校園自由軟體應用諮詢中心 PyZope 通信論壇
http://list.ossacc.org/mailman/listinfo/ossacc-pyzope


註5: 在 Pythonology 網站上整理有成功案例
http://www.pythonology.com/success


註6: O'Reilly 的 "Open Source Goes to COMDEX" 投票競賽結果
http://www.oreillynet.com/contest/comdex/


作者簡介

胡崇偉,現職是中研院資訊所研究助理。專長是技術文件撰寫、Linux 系統整合、數位學習系統,興趣是英式搖滾、認知心理學、佛學、開放源碼,想要到北歐旅行。電子郵件:marr @iis.sinica.edu.tw。

Making a simple web server in Python

Making a simple web server in Python.

written by Jon Berg

The great thing about Python is what they call "batteries included", that means a lot of functionallity is bundled with the programming language. And the functionallity is fairly straight to use.

Today we are going to demonstrate how to build a web server in less than 30 min. using the classes from the Python library. We are also going to have some "advanced" functionallity in this server. We want to do dynamic content serving (ala what ASP or PHP do), and be able to take POST from forms. This may sound as a complex task, but as you will see every body can acomplish this through some high level programming interfaces. You don't have to know much about the HTTP protocol at all. Except some basic that when the client request something it is a "GET", and when the client sends something it is in our case a POST. Some basic responce codes like 200 is OK for GET, and 404 is file not found, 301 is OK for a Post.

The web server is implemented as an extention of the BaseHTTPRequestHandler. This means that we define a class an implemenet some methods that will be called when the web server gets requests. There are two methods one for GET requests and one for POST requests.

Lets look at the code:


The main() tries to start the server at port 80 with a reference to the class we just implemented. To quit the server you can press ctrl-c. And the server will close the socket and quit.

The do_GET() gets invoked when you do a GET request. It do checking to see what type of file is requested. If it is a html file it tries to open it and send it to the client. If it is a esp file, our dynamic content, it will print out the current day and year.

The do_POST() gets invoked when you do a POST request. It then displays the content that is uploaded. The name of the formelement is hardcoded to be "upfile".

Running the example:
start the webserver with python webserver.py
Then you can open your web browser and type in http://localhost/index.html or http://localhost/index.esp
To test the upload, you open the upload.html, press browse, open a small text file, click "press", the server will echo back the file.

Download the example code. (webserver.py, index.html, upload.html)


Pointers to related stuff on the hypertext transfer protocol (http) and web servers:

Making a simple web server in Java. (a bit lower level) This is a tutorial I did on how to do somewhat the same but in Java. This implementation is much more bottom up, with sockets and not that many short cuts as you can do in Python.

HowStuffWorks This is a very basic introduction for the novice on how web servers works. Has also other text about Internet and Routers, in easy to understandable language. Nice if you are starting out learning.

HTTP Made Really Easy Here is some nice text that goes through the main points in HTTP. A little more technical. It's recommended that you know these things to understand the above tutorial.

Apache the best and most widely used web server on the Internet today, check it out. If you want to run your own web server this is the one to get, you can get binaries for both Windows and Unix. You can download the entire sourcecode if you want to check how it was made.

Mozilla / Netscape is a nice web browser. Get rid of the Explorer.

RFC-1945 RFC describing Hypertext Transfer Protocol -- HTTP/1.0

RFC-2616 RFC describing Hypertext Transfer Protocol -- HTTP/1.1

RFC webpage The Request For Comment webpage, RFC are technical documents describing all sorts of protocols on the Internet.

Python webpage Download Python for windows or linux.



Google
Let Google Handle Email for your Domain Name
Page Rank banned by Google
Google's highest ranked web pages
SEO intelligent spam causes irrelevant search results
Google Sandbox
Google ranking factors
How to not give out page rank in web page links

Web Server Programming
Simple Java web server
Simple Python web server
Configuring Apache webserver with .htaccess file

Windows
Turn off the loginscreen in XP, after installing .NET .

Turn off xp login screen unread mail count
What is .NET

Web (webmastering)
Introduction to Cascading style sheets (CSS)
The value of Alexa traffic rank
HTML META tag, not a search engine optimization tool
Create a maintainable webpage with modularization
The www prefix in your domain name
What is RSS and cool things RSS can be used for
MySql backup and restore with phpMyAdmin

Mix Computer related text
Doing business (making money) with Information Technology
Business with Computer Science
Research in Computer Science
Current and future possibilities of Medical Informatics
Tasks that make sense to have automated
Programming handheld mobile devices (overview)
Security tips for the web surfer
Price and Capacity in computer hardware
Java RMI Tutorial.

Microsoft Word
Page numbering in Word
Numbering headers or outlines in Word
Create a List of Figures
Turn off the default collapsing menus in Word

Symantec Antispam 100% cpu CPU-hog Windows 2003

Symantec Antispam 100% cpu CPU-hog Windows 2003

I recently upgraded a customers' installation of Symantec Antivirus with Groupware Protection to Symantec Endpoint Protection (including Symantec Antispam).

After the upgrade the customer complains about slow network-response from the server. I investigated this problem and I came across two process conduit.exe and SMSUtilityService.exe.

Both process regurly consume above 50 percent of CPU, and for a considerable time. My customer is not happy with the slowdown of his network.

What's the problem with version 6 of Symantec Antispam? Why does Symantec accept that fact that version 6 is broken in several ways?

My solution to this problem was to disable the SPAM-function of MailSecurity and install GFI MailEssentials.

Please Symantec fix this problem, because it's going to hurt your success with Symantec MailSecurity.

Back up files that have been changed or modified seven days ago


' This script would backup all folders (including their subfolders) and files
' that are under the path specified in the objStartFolder variable.
'
' Only those files that have been modified today would be backed up.
'
' Note: if you don't want the files in .zip (or .rar) to be full path as where
' the files were original stored (using relative path in .zip file), make sure you put this script in the same
' directory of the files you want to back up. Otherwise, you would need to
' modify this script to suit your need.
'
' You can run this script in more than three ways:
' Way 1: cmd > cscript.exe script_name.vbs
' Way 2: double click on the script_name.vbs
' Way 3: run the script in scheduled tasks.

Dim MyParentPath
Dim MySubFolderFilePath

MySubFolderFilePath = ""

Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\Danny\Scripts_Tools\Backup_Scripts"

' Specify the full path where the .zip will be stored, including .zip file extension and .zip file name.
ZipFileExtension = ".zip" ' can be either .zip or .rar
ZipFileName = "C:\DB_Backup_" & Year(Date()) & Month(Date()) & Day(Date()) & ZipFileExtension

dateNow = Date()

' We would like to zip the log files that have been modified from seven days ahead to the day before today (not include today)
SevenDaysAhead = shortDate( DateAdd( "d", -7, dateNow ) )

Set objFolder = objFSO.GetFolder(objStartFolder)
MyParentPath = objFolder.Path

'Wscript.Echo MyParentPath & "___"

Set colFiles = objFolder.Files
For Each objFile in colFiles
' Wscript.Echo """" & objFolder.Path & objFile.Name & """"
' Wscript.Echo """" & objFolder.Name & "\" & objFile.Name & """"
If CDate( objFile.DateLastModified ) >= CDate( SevenDaysAhead ) And CDate( objFile.DateLastModified ) < mysubfolderfilepath =" MySubFolderFilePath" wshshell =" WScript.CreateObject" wshshell =" Nothing" objfolder =" objFSO.GetFolder(Subfolder.Path)" colfiles =" objFolder.Files">= Date() Then
MySubFolderFilePath = MySubFolderFilePath & """" & Mid( objFile.ParentFolder & "\" & objFile.Name, Len(MyParentPath) + 2 ) & """" & " "
End If
Next
ShowSubFolders Subfolder
Next
End Sub

Function shortDate( theDate )
shortDate = formatdatetime( theDate, 2 )
End Function

PHP vs. Python

> I think he means, "scale to larger programs," not "scale to more
> processors."

Yes. I will try to be more specific. There is several reasons why Python
scales better than PHP.

(1) Python uses namespaces, PHP - not. The bigger programm the bigger
probability of conflict among names in PHP.

(2) Not only PHP lacks namespaces. It has one big inconsistent mess with
its function naming! Inconsistent prefixes, order of parameters. Mess. It
is difficult to memorize it. Python programming need less interupting for
reading manual.

(3) Python uses modules, PHP - not. Python can download single or some
classes from many big modules (eg. from module1 import class1, var1, fun1).
PHP is primitive in its copy-paste *all* included files! So Python uses
less memory than PHP and do not need to parse so many lines.

(4) Python automatic compile every imported modules into bytecode, PHP has
to parse all those mess. Without accelerators PHP is much slower for bigger
applications. This is the reason why PEAR is so slow. This is the reason
why ezPublish is so slow. The bigger code (more included files), the slower
PHP works.

(5) Python compile its modules automatic and do not need to parse them for
every browser request like PHP do.

(6) Pythonic application server (eg. Webware) do not need to load and parse
any files from filesystem at all! It loads them once, compile it and store
compiled scripts in memory. PHP has to load files from filesystem, parse
them and execute. From my own experience: when I moved from PHP to Webware
and I compared its performance with (similar scale) php appplications, my
webware was almost 6 times faster!

(7) Python has much better free IDE editors with graphic debugger inside.
PythonWin, Boa, SPE, Eric3 etc. It is much easier debug in Python than i
PHP for larger programmes.

(8) And last but not least. Python is truly object oriented, general
purpose language. PHP is not general purpose language. PHP4 has very poor
OO. (PHP5 has better, but has also some useless new features like private
variables. They have sense for static compiled languages like C++ or Java ,
not for dynamic ones.) Python also uses sofisticated exception handling,
uses namespaces, has module import, has better unicode support, has more
consistent api etc.
One more example from my experience. I always have problem with converting
string among iso-8859-2, cp1250, mac-ce and utf-8. PHP utf8 functions are
poor, implements useless (for me) iso-8859-1 only. iconv library for PHP is
even worse, when it cannot convert some characters it deletes the following
characters! PHP has no such like: unicode(txt, 'cp1250').encode('cp1250',
'xmlcharrefreplace'). When some characters exists only in cp1250 but not in
iso-8859-2 that function convert them into xml entity &#number; Cute!

Wednesday, October 29, 2008

程式設計師的格言

程式設計師的格言

呵!! 看到有趣的文章 轉一下!!
裡面應該不少都是做程式設計新有戚戚焉的

-----
程式設計師的格言
http://www2.biglobe.ne.jp/~oni_page/other/etc/pr03.html

(翻譯beta r2 by but=HO)

http://buttaiwan.wordpress.com/2008/10/12/programmers_rule/

譯註:
PG = Programmer (剛進去只負責聽命寫程式的)
SE = System Engineer (日本說的 SE 算是 team leader ? 還是工程師不過自己不寫 code)
=======================================
譯註
SE是日本軟體公司裡程式設計師的頭子。自己不太寫程式,主要工作是跟客戶確認規格。
程式設計師多半自己不面對客戶。
在台灣隨公司不同,比較接近SA或PM。
總之就保留原樣寫SE囉。
=======================================

1
每天有24小時。
所謂的「今天之內」,是指到明天早上為止。

2
程式不會照自己所想的跑。只會照所寫的跑。

3
需求規格在程式寫完後才會敲定。
基本規格要客戶看到成品後才會決定。
詳細規格要使用者用過後才會確定。

4
我對軟體設計的方式導出的結論,有兩種方式。
一是把軟體設計得單純到很明顯不會有缺陷,
不然就是把軟體設計得複雜到沒有明顯的缺陷。
- C.A.R.Hoare

5
程式碼不要在開發現場寫! 去客戶那寫!
除錯不要在期限前做! 上線後再做!

6
畫面藍了。

7
先說「沒辦法」的人贏。

8
有意見的話你寫

9
要殺一個程式設計師不需要刀,改三次規格就好

10
首先要先懷疑別人,被懷疑的人或許會把問題解決掉。
(註:通常會「先懷疑自己」)

11
開發沒有終點。只有釋出(release)。

12
無論規格多晚才能確定,結案期限永遠不會變。
這是所謂的「期限守恆定理」。

13
客戶總是覺得水跟追加需求是不用錢的。

14
付錢愈計較的客人愈囉唆。

15
在排定開發行程時,總是視而不見一些連小學生都會的算數。
業務部門總是一堆不知道1+1=2的人。

16
一個人掛了大家都掛了。

17
bug過了一晚可能就變成規格了。

18
好的規格找一個天才不如找三個凡人。
爛的規格找一百個凡人不如找一個天才。

19
客製軟體中30%的價格用在確認規格上。
30%用在修改規格上。
30%用在找bug。
結果初期規格反映在價格上占的比例只有10%。

20
對客戶來說SE是部下,程式設計師是家畜。
對SE來說客人是錢,對程式設計師來說顧客是看不見的病毒。
除了弄完程式以外,沒有其他驅除的辦法。

21
顧客想受SE喜歡,要自己了解到系統開發需要時間與金錢,早點確定規格。
SE想受顧客喜歡,則要讓程式設計師討厭自己。

22
很多SE跟程式設計師都暗自想著有錢有閒的話什麼系統都想自己動手做,
不過都沒這種機會。

23
品質的劣化程度依規格改變的次數與規模而定。

24
業務是認為空想能夠實現的夢想家。
SE則是深信任何障礙都能突破的冒險家。
程式設計師則是被夢想家和冒險家拋到漆黑海裡的漂流者。

25
有才能的程式設計師第一次看到設計細節時,要先理解程式的目的。
接下來要設法讓SE了解到以指定的方法、工時並無法完成這個工作。

26
程式是運氣與直覺堆砌而成的奇蹟。
若不具備這兩者,不可能以這樣的工時實現這樣的規格。
修改規格是對奇蹟吐槽的褻瀆行為。
而追加修改則是相信奇蹟還會重現的魯莽行動。

27
程式設計師聽了「把自己當作顧客去著想!」而開始思考。
啊,像夢一樣。

28
對於因為興趣而寫程式的人來說,所謂的技術是程式語言能力。
對於因為工作而寫程式的人來說,所謂的技術是邏輯思考能力與人際溝通能力。
程式語言可以看著手冊溝通,客戶不行。

29
程式系統在交貨之前會不斷縮小。
先用元件定義取悅老闆。
再拿經費概算要部長妥協現實的方案。
在運用會議中,課長會嘗識減少自己責任範圍。
在細節會議中,負責人會把範圍縮到自己記得的部分。

30
SE需要持久力,程式設計師需要爆發力。

31
準時離開公司,工作會變多。

32
完美的程式需要完美的時間與金錢。
聽說揮霍著美國的國家預算的NASA,也覺得時間跟錢不夠。

33
詳細設計要在程式碼的註解裡做完。
註解是唯一的自衛手段,至少要讓自己看懂。

34
還有時間看程式碼的話就執行他。
CPU跑得比腦細胞快。至少這時候可以休息。

35
程式的異常該稱為「bug」還是「規格上的限制」是看期限還剩多久決定的。

36
所謂便服日,好像社會上把他叫做假日
(註) 日本有些公司會有所謂便服日(不用穿西裝的日子),通常是星期五,但...

37
地獄持續一段時間後,充滿殺氣的怒吼會變多。
再持續一段時間,說話會變少但牢騷會變多,壟罩在凝重的氣氛裡。
再持續下去,反而會海闊天空,四周洋溢充滿活力的聲音。
這種狀態稱為「Programmer's High」,也是倒下來的人開始出現的時候。

38
遠處的火災一定燒到這裡。

39
禱告,然後跑吧。

40
程式不是用腦記的,要用身體記住。

41
明天能放假的話死了也罷。

42
外面有下雨耶,昨天開始下的嗎?

43
若不能心靜不移,身體會掛。
若不讓自己殘忍,自己會被殺。

44
客戶會說謊,業務會作夢,SE會做白日夢。
程式設計師則惦惦。(愈來愈自言自語)

45
(日文文字遊戲,講這兩個職務之間的矛盾)
SE總是不講理地說「別強人所難」,
業務總是強人所難地說「別說辦不到」。

46
規格書就像航海圖,客戶則是洋流。洋流陰晴不定,航海圖就變垃圾。
程式設計師必須在沒有航海圖的海上憑自己的力量找到大陸。

47
再嘮嘮叨叨下去也是要付錢的。

48
多想個10秒鐘,你可以不說「嗯,這個做得到」。

49
人是無法從別人失敗記取教訓的動物。
砍成本、改規格、加需求、趕上線,從來沒有人從Mizuho的失敗中記取教訓。
(譯註:Mizuho是日本知名銀行,當初合併系統上線時發生整合錯誤系統掛掉)

50
老手用來提振精神的魔法格言:
「不過比起以前來說算是…」
新人用來提起幹勁的魔法格言:
「把這件工作做完的話…」他們還不知道工作是沒有終點的。

51
所謂交案期限,是指開發現場從公司換到客戶那裡的日子。

52
程式、SE、經理不是職種。是職責。

53
業務是最難搞的客戶。

54
能夠迅速想到解法的程式設計師太多了。
他們能用一分鐘想到方法,用一天去寫程式。
不需要花一小時想到解法,再用一小時去寫程式。
- Jon Bentley

55
漂亮的規格,可以從沒有bug出現看出來。
明明爛的就是設計,為什麼是這樣…

56
上線後的除錯才叫做bug。

57
追加需求確定後交貨期限就無法確定,
交貨期限確定後追加需求就無法確定。
這稱為「追加需求與交貨期限的測不準原理」。

58
除三個錯就會冒出一個錯。
這稱為bug的無窮迴圈。

59
不祥的預感總會實現。
不過程式設計師不會去煩惱不祥的預感,那是SE的工作。

60
要解決地獄的辦法,就是客戶把錢交出來。

61
不懂電腦的操作者是發現bug的天才。而且無法重現。

62
每次開會就更改規格的客戶,
他的操作手冊要等到操作寫好的程式後才能寫出來。

63
搞不懂的時候,Currency(長整數)比Interger(整數)好用。
Variant(字串、數字都能存的萬能變數)又比Currency(長整數)好用。
安全第一。
(VB程式設計師如是說)

64
啊,那是微軟的規格。

65
程式設計師所不滿的規格也一定會讓客戶不滿。
(這是說程式設計師覺得難寫的地方常常是SE溝通有落差)

66
程式設計師需要的技能,
包括交涉、時程管理、業務分析、提案、設計、程式語言、架構、維護、使用。
SE需要的技能則減掉程式語言、架構、維護與使用。
專案經理需要的能力則再減掉業務分析、提案與設計。
業務需要的能力再扣掉時程管理。

67
正因為健康,才能做不健康的事。

68
規、規格、是規格啦。不過有一點跟規格不太一樣啦。
(譯註:聽說這是純愛手札裡的名言改的)

69
那是你說的規格。

70
開發室沒有窗戶,那是因為以前…

71
即使爛了,規格還是規格。
(譯註:模仿自日文俗語「腐っても鯛」=瑕不掩玉)

72
SE: 真沒辦法。
PG: 也沒註解。
(碰到不知道是誰寫的程式,大家都束手無策的狀態)

73
為什麼你不能兩三下解決掉他啦。
因為之前兩三下搞定的東西也被你兩三下就否定了。

74
不會動的bug就只是普通的bug。(會動的bug則能視為規格)

75
今天好好清理bug,bug應該死光了吧。
咦?Windows也死了唷。

76
客戶不會去想最壞的情況。要他面對最壞的情況,他會認為是漫天開價。
SE則會顧慮最壞的情況,準備應付最壞的情況。
程式設計師比誰都早預料到最壞的情況,而無視最壞的情況。

77
唯一不產生bug的方法,就是不寫程式。
第二好的方法,就是在時程跟人員確定之後的每次改規格,都重新檢視過整個專案。

78
共同責任是程式設計師的責任。
管理職?那是啥?好吃嗎?我沒吃過耶。

79
如果可以改行的話,想找個準時下班不叫「逃跑」的工作。

80
對職業程式設計師來說,漂亮的程式是單純而自然的邏輯、簡單而基本的指令、豐富的註解,
也就是新手程式設計師也能馬上動手改的程式。
而要寫出這樣的程式,需要單純、簡單、美麗的規格。
但可惜客人總是喜歡搞很複雜。

81
設計者應該是不該要求製作者製作出超過設計以上內容的吧…

82
無論是做的比規格書裡的多,還是只照規格書裡的寫,SE都會找程式設計師的碴。
所以程式設計師只做規格書裡的寫的內容。

83
SE對程式設計師說的「常識」每三小時變一次。

84
自己看規格書。不能跑的是規格。

85
「沒辦法」是要看把一天當多少小時來算。
一天常常指的是3人日,一個月常常是指4.5人月喔。

86
工時要減掉一半的單體測試與一半的系統測試,
而交貨期則要另外加上上線後的兩個月。

87
能拿到錢的規格變更稱為「受理項目」,
拿不到錢的規格變更則稱為「SE的規格確認失誤」。
程式設計師是這麼看的。

88
累了。我想睡了。可以回家嗎。
(累了吧,我也累了。好累喔怎麼了。反正就是規格啦,管他的)

89
試圖降低成本的話,為了配合預算,品質會下降,不過漫天開價做出來的品質也不見得好到哪裡去。

90
REDO到底該怎麼唸一直搞不懂。是利斗嗎、李度嗎、R E D O嗎,難道是 red 零 嗎? 拜託加上注音吧。

91
有人在程式碼註解裡寫日記。
像「今天是雨天…」,「想回家…」之類的。
甚至還有「修改日: 2003/10/10 不能同意你更多」這種註解出現。
說到這個,好像也看過「吃大便」這樣的註解。

92
小學生時第一次看到電腦
國中時第一次學會怎麼用
高中與大學學會程式語言
出社會後才發現自己走錯路

93
「不要讓老闆當業務比較好」

94
說來說去,要去研究根本不知道為什麼會動的東西為什麼不會動了,找拿破崙來也沒搞頭。


------------------------

ex 1
就算程式裡沒bug,編譯器會有bug。
就算編譯器沒bug,OS會有bug。
就算一切都沒bug,客戶會決定什麼是bug。

ex 2
規格與規格書是不同的東西。

ex 3
比期限更重要的是靈感與睡眠。

ex 4
比知識與經驗重要的是手冊與時間。

ex 5
能動就好了,能動的話…

ex 6
過了三天就是別人寫的程式碼。

ex 7 (大搜查線系列)
規格變動不是在會議室裡發生的!是在現場發生的!

ex 8 (大搜查線系列)
異常不是在模擬測試時發生的!是上線後才會發生的!

ex 9
漂亮的設計三天或許就膩了
骯髒的設計三天就習慣了

ex 10
bug與規格是一體兩面

ex 11
電腦裡沒有bug,bug常在人心。

ex 12
無論怎麼檢查,不管怎麼確認,上線前一晚就是睡不著。(RFC968)

ex 13
估價需要1%的經驗與99%的直覺

ex 14
沒有什麼事情比直接讓找不到任何bug的程式直接上線還要可怕的了。

ex 15
・『程式設計師』=能將SE條理不通的說明翻譯成程式碼的高手
・『SE』=與客戶討論改寫規格書、與程式設計師討論後再改寫規格書,程式出貨後還要繼續改寫規格書的人
・『PM』=每天修改自己定下的行程表的人
・『業界老鳥』=臉色蒼白缺乏表情的人
・『外包』=幫不會寫程式的正職員工寫程式的人
・『coding』=複製貼上的工作
・『單體測試』=指開始寫程式
・『除錯』=把程式碼註解掉的工作
・『新同事』=在火燒屁股的專案火上加油的人
・『出貨日』=把只完成一半的系統上線的日子
・『末班電車』=業界平均的下班時間
・『颱風假』=一年一度可以準時下班的業界假日

ex 16
當誰寫的程式碼跑出bug時,那個人大概都不在了(墨菲定理?)

ex 17
最終手段
「重開機」
意外的常常都很有效

ex 18
最強藉口
以前「那是硬體的極限」
現在「那是Windows的規格」

ex 19
「程式碼的可信度,不會比寫的人還可信。」

There are two ways of constructing a software design

Quote of the day - C. A. R. Hoare
There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.

- C. A. R. Hoare

我對軟體設計的方式導出的結論,有兩種方式。
一是把軟體設計得單純到很明顯不會有缺陷,
不然就是把軟體設計得複雜到沒有明顯的缺陷。
- C.A.R.Hoare

十大免費Windows必備安全工具精選

十大免費Windows必備安全工具精選
網際網路從來都不是安全的地方,如同行走要眼觀四面、過馬路還要再耳聽八方,使用網路本來就像行走江湖,照子要放亮。更有甚者,普及如Windows之流,不論因為樹大招風,還是體質本身孱弱,自是吸引各方好手或好事之徒(尤以後者居多),除了想一探系統強弱,當然也正是試試自己功力的好機會。於是主客之間過招、拆招,敗了就回去再練…但如果擔心自己的Windows電腦不夠強,務必再挑選幾件寶甲利器強化Windows系統,諸如Computer World文章《10 essential (and free!) security downloads for Windows》,精選十件可以強化Windows使用者隱私及安全的免費工具。
Secunia Personal Software Inspector
這是資安公司Secunia提供的程式,Secunia會持續觀察各種軟體的漏洞及修補檔案並建成資料庫,而使用者裝了PSI之後,PSI會掃瞄使用者的系統並比對Secunia資料庫,再列出清單給使用者;若有需要,使用者即可直接透過清單下載修補檔案。

SendShield (beta)
Office文件裡有除了內容,還有許多可能涉及隱私或文件作者不想讓他人知道的資訊。SendSield能整合到Outlook,並在使用Outlook寄送Office文件時,自動檢查文件內是否有涉及敏感的資訊,並協助使用者刪除。
Avast! Antivirus
這是出自ALWIL軟體公司的免費防毒軟體,特點包括輕量幾乎不佔記憶體或系統資源、簡單易用、功能完備,可偵測網路連線、Web、電子郵件等途徑而來的威脅。獨立的防毒軟體測試網站AV-comparatives.org給予Avast!的評價是Advanced+。

HijackThis
雖然工具的名稱是Hijack This,但相反的是,這個工具是要從間諜軟體的手中就出被挾持的電腦。來自趨勢科技的HijackThis能掃瞄間諜軟體可能藏身處所,除了能刪除可疑的項目,也能讓你將掃瞄結果上傳到HijackThis網站做進一步檢查。
SpywareBlaster
與其事後檢查,不如第一時間就將間諜軟體擋於門外。SpywareBlaster能停止ActiveX類型的間諜軟體、瀏覽器挾持者及其他惡意軟體的安裝,並能阻擋間諜軟體的cookies。

F-Secure BlackLight Rootkit Eliminator
這件工具專門對付rootkit,它會掃瞄系統隱藏的行程、資料夾、檔案,並將結果回報給使用者。如果發現任何可疑份子,除了能提供進一步資訊,亦能讓使用者更改可疑份子的檔案名稱或刪除(但對系統不是很熟悉,最好不要亂刪,以免誤刪反而導致系統無法運作)。
NoScript
這支頗受好評的Firefox擴充套件,不只能阻擋網頁上的script、plug-in、及各種類型的程式碼,並且還能防護跨網站程式攻擊(cross-site scripting attacks,XSS)。

Comodo Firewall Pro
這款免費的防火牆軟體提供輸入、輸出雙向保護,不過第一次執行時,應該先執行Clean PC模式,這會掃瞄整個電腦的程式及登錄資料庫,避免Comodo Firewall Pro不斷詢問使用者該如何處理它所遇到的連線(文中亦推薦了另一個免費的防火牆:Online Armor)。
McAfee SiteAdvisor
一般人看不出網站是不是包藏禍心,但裝了McAfee SiteAdvisor之後就不一樣:除了每一筆Google或Yahoo!的搜尋結果會有小圖指示網站的好與壞(出現紅色叉叉的是壞網站),進入網站時也會在瀏覽器底部出現類似的小圖。

CCleaner
這件工具能移除瀏覽網站之後網站對電腦所留下的追蹤,包括網際網路暫存檔、瀏覽歷程、cookies等,此外也能檢查、清除不需要檔案(例如暫存檔、Windows記錄檔等等)、或登錄資料庫有問題的項目。
心訣與招式一樣重要;光有神兵利器但沒有正確的觀念,還是無法完全保護。因此請牢記心訣一:千萬別以為安裝了工具,就以為神功護體;心訣二:對手隨時都等著見縫插針。

現今員工需要具備的十大IT技能

現今員工需要具備的十大IT技能

產品來來去去,技術日新月異,IT人是不是後悔當初念了或進了這行?別嘆氣了,轉行未必更好,但留下來的挑戰肯定不會少,還是看看《Wanted: 10 IT skills employers need today》有沒有值得借鏡的參考。這篇報導訪問了許多IT業界人士,列出了十項現今員工需要具備的IT技能(但排名順序無關重要性)。

無線網路。現在已經不只是網路時代,而且已經邁入無線網路時代。可憐的員工必須在衝浪、曬太陽的同時,分出心思想著公事,當然需要無線網路處理事情。無線網路的範圍非常廣,但是802.11、WiMAX和寬頻都將持續在接下來的五年受到重視,尤其行動技術領域更是重要。

虛擬化。 虛擬化原本是系統管理員和開發人員建立測試環境的好工具,但是現今的虛擬化技術已經逐漸成為資料中心運作及災難復原的主要角色。在電腦運算能力越來越強、 儲存容量及頻寬越來越大之後,將原本實體、獨立的伺服器,虛擬化並植入強大電腦,的確是善用資源的好方法。虛擬化技術除了涵蓋了伺服器、網路、儲存等領域 的技術,也新增了桌面虛擬技術。

資訊安全。資訊安全永遠都是最重要的IT技能。資訊安全不只是網路安全、電腦安全,也包含軟體開發的安全考量,甚至該如何銷毀廢棄的報表或硬碟,也都是資訊安全的範圍。

網管技術。 雖然曾經面臨達康泡沫化,但是現在業界對網管技術人才的需求又再次出現,而且隨著網路越加成長與複雜,網管技術人力的需求也比以前更廣、更深。有能力規 劃、管理大型IP-based企業網路的人,將成為炙手可熱的目標。業界需要的是有實務經驗的廣域網路專家,實務經驗對業界尤其重要,不能只會紙上談兵, 必須有網路安裝經驗,包括纜線、光纖的連接,以及網路設備的安裝與設定。而諸如IPv6、VoIP等新興技術,則是新一代網管技術所必備。

應用程式遞送網路(Application delivery networks:ADN)。網路經常會隨著企業員工或伙伴的地理位置散佈各地而日益複雜,根據研究顧問機構顧能的定義,如果公司想要部署現代的 browser-based應用程式以及Web services應用程式,就需要應用程式遞送網路。AND的技術範圍包含了傳統的網路技術,並且再加上儲存、安全、程式開發技術,也就是將應用程式與網 路更緊密的融合,以節省開發和部署的成本。

Web 2.0。為了強化Web的互動性,Web 2.0相當著重人機介面以及Web前後端的溝通,因此也產生了多種實作技術。雖然每一家軟體廠商提出了不同的實作方式,但除了熟悉廠商所提供的工具,切莫忽略工具底層的基礎技術。

IT商務分析。對企業而言,所有技術投資和營運開銷的最終目的,都希望能回饋到企業的商業運作,因此IT主管也需要對此能有所協助,並且與企業裡的其他主管以相同的商業語言溝通無礙。如果IT人能多一點商業概念,就能對企業的IT規劃、應用、採購、部署多一些幫助。

資料庫管理。網路的流量越來越大,相對的資料庫的容量也越來越大,尤其是大型的資料庫,因而這方面的人力需求也增加得非常快。而當資料量越來越大,企業就需要更快速的從資料庫取出正確資料的方法,因此商業智慧/資料探勘也成為IT人的重要技能。

團隊合作。IT人應該以更全面的視野來規劃、整合、解決問題,並且要能與IT部門的成員團隊合作,而能與其他部門的人共同合作。在過去,許多系統之間有著明顯的界線,但現在的IT趨勢則是要求各個系統能夠整合、甚至結合,因此需要跨領域的知識,或跨團隊的合作。

很擔心自己被資訊的洪流淘汰嗎?雖然這篇文章列出了十項重要技能,但其實更重要的是基礎的本質學能和做事態度。不要忽略學校教的基礎課程,網路概論、網路管理學校都有教,資訊安全、資料庫管理也都在學校課程裡,先別本末倒置忽略這些重要基礎,才能一步一步堆積所學。

五件應該告訴老闆及五件別跟老闆說的事情

五件應該告訴老闆及五件別跟老闆說的事情
身為IT專業人員,除了技術專業之外,深知辦公室文化對工作將更有幫助,尤其應該要能分辨老闆想要知道什麼事情。Computerworld有兩篇文章:《Five things you should always tell your boss》和《Five things you should never tell your boss》,分別提供了哪些事情應該要向老闆報告、哪些事情不用讓老闆知道的原則。這兩篇文章的內容,是與獲得Computerworld 2008 Premier 100 IT Leaders的IT主管訪談而來(也就是說,這十件事都是老闆的觀點)。
以下五件是應該告訴老闆的事情。
1.實情。任何主管都不喜歡美化問題、隱瞞事實、光說不練的員工,主管需要全盤的訊息,尤其不喜歡自己最後才知道真相。而且應該不加主觀評論的向老闆回報實情。
2.構想。縱使你的構想無關IT,但只要能改善業務、解決問題的建議,都是主管樂於聽到了。
3.需求。誠實的將工作上的需求告訴老闆。好的老闆會讓員工願意辛勤工作,原因往往在於老闆能讓員工樂在工作,而這有助於提高員工的工作士氣和生產力,並且留住員工。
4.不。向老闆說「不」的確需要勇氣。在你說不的同時,最好還能提供各種替代建議給老闆,並且讓老闆知道各種建議的優缺點。
5.好消息。沒有人只想每天聽到專案出狀況、伺服器當機又不確定何時能恢復之類的壞消息,因此也別忘了向老闆報告好消息。
此外,以下五件事情就別跟老闆說囉。
1.所有與技術相關但與業務無關的事情。對IT主管來說,感興趣的是能協助組織業務推展並且讓企業員工事半功倍的IT技術。尤其,你務必在瞭解業務需求的情況下,再提出技術面的建議;別再不瞭解業務需求的情況下,就提出你的技術建議、甚至解決方案。
2.只有一種解決方案。IT人員有時候會有若干技術偏好,這無可厚非,但如果所有的狀況都只搬得出同一套解決方案,就不免遭人質疑你的技術廣度不夠。
3.其他同事的負面評價。最不該的尤其是所有的人都忙著要趕上落後的專案進度,但你卻在此時跟老闆說一些對工作無益的話,更容易讓老闆反感。這類的事情不是不能跟老闆說,但是物必要拿捏時機,最好是在老闆主動問你的時候再說。
4.不可能。或許真的不可能,但是在告訴老闆不可能之前,務必將你所面臨的挑戰告訴老闆,然後和老闆討論「如何克服這些挑戰」。如果能放棄心中的成見,就可能會對自己所能完成的深感訝異。因此,先別說不可能,而是先具體找出問題與挑戰,如果自己無法解決,試著讓你的老闆知道難題所在,而不是告訴老闆「不可能」。
5.意外驚喜。IT主管大多不喜歡驚喜,特別是煞風景或不愉快的意外。而且,最好別讓小問題變成大災難才讓老闆知道。
IT主管通常不會事事都想知道,但有些事情他又非得知道不可,因此你得「說該說的,不該說的就別說」。不過這並非簡單的事,除了需要敏銳的觀察力,也需要經驗,尤其你必須諳練自己所在的辦公室文化,才能做出恰當的判斷。
張貼者:賴榮樞 於 9/16/2008 11:52:00 下午

如何面對裁員

如何面對裁員
公司裁員通常無預警,尤其是外商。多數人面臨「非自願性離職」,第一時間的情緒反應多是負面:震驚、難過、憤怒。專欄作家Ron Nutter在今年2月遭到解雇,震驚之餘,Nutter還是得面對明天。而在歷經了76天、85個工作機會、16次面談之後,Nutter找到了新工作,並且將自己遭逢裁員及求職的經驗,濃縮化成InfoWorld的文章《Twenty ways to survive a layoff》。
記下所記得的一切
首先,如果裁員已成事實,那麼從那一刻起,有太多事情需要處理,因此必須保持理智的頭腦,Nutter特別在文中提到,一定記下你所記得的一切。任何人遇到裁員的第一時間反應通常是震驚,然後陷入情緒的低潮。但唯有保持理智並以紙筆記下,才能清楚自己的權利與義務,例如薪資(付到何時)、遣散費、休假等。
而且這些事情的處理,可能不會在離開公司之前就結束,例如要留意後續的薪資是否入帳,健保續保的問題等。尤其,務必留意自己是否符合領取就業保險失業給付的條件,如果可以,也有許多手續流程要跑(相關資訊可參考勞委會勞工保險局網頁:http://www.bli.gov.tw/sub.asp?a=0005058)。
放開心並尋求家人支持
遭到解雇對多數人都相當負面,在離開舊工作、尋找新工作之前,Nutter認為不妨給自己幾天散心假。接著,找時間更新自己的工作履歷,不是制式文件的那種,而是記錄了自己完成過哪些專案工作。
新工作或許不是一時半刻就找到,失去工作就等於失去收入,因此Nutter在文中提醒必須做好節流,任何支出都必須謹慎,帳單更要詳細看過。如果還與其他家人同住,也應該讓他們知道狀況;家人的支持(甚至支援)此時便顯得重要不已,如果大家能共體時艱,甚至互相支援,會更容易走出失業的低潮。
除了線上的職業媒合網站,也別忘了其他的求職管道,例如把正在找工作的消息放上自己的部落格或即時通訊軟體,或者透過同事、甚至舊雇主、客戶詢問工作機會。面試新工作之前,也務必做足功課,例如瞭解新公司的規模、領域,甚至過去的記錄,而且不論上網搜尋,或者找找熟識的朋友詢問,都是很好的方法。
面試前應做足功課
此外Nutter在文中也建議,備妥個人履歷,更是面試新工作之前,非常重要的事情。千萬別因為一時的疏忽,才在面試時想不起自己參與過哪些專案或某個專案的細節。如果被發現準備不及--不論是忘了書面資料或面談時答不出來,都非常不利於面試成績。
在國內若請領就業保險失業給付,需回報求職記錄,但其實就算不需回報,如果能在找工作的時候,詳實記錄求職資料,對求職亦有助益。Nutter自己的經驗是以表格記錄每一項應徵工作的來源、日期、公司、職稱、內容、聯絡人及聯絡方式,並且記錄每一項工作的求職過程狀態,例如「寄出履歷」、「某日面試」、「已面試待通知」等,甚至也可以將前述的新公司資料記錄於此。
永不放棄
找工作也可以更為積極主動,有時候與其苦苦等候電話響,Nutter在文中建議不妨更為積極的撥給員工招募負責人。更重要的是必須記住「永不放棄」,找工作、申請就業保險失業給付等或許沒有想像中的順利,家人不見得能諒解你遭解雇,你更可能不甘心非自願性離職,但遇到不順心可以暫停一下、調適心情,不過無論如何,Nutter鼓勵失業者都應該抱著永不放棄的精神,期待更好的明天。

Python vs. PHP

Python vs. PHP

Introduction

Every month or so someone posts to comp.lang.python asking how Python compares to PHP. Python's 'language comparisons' page doesn't have an entry for PHP so here's a first draft. This work-in-progress compares PHP and Python and evaluates their relative strengths for web development.

Please contribute! Once there's some flesh on this skeleton, I'll tidy it up and submit it to: http://python.org/doc/Comparisons.html

-- TavisRudd? - 23 Nov 2001 -- MikeOrr - 15 Dec 2001 -- DiogoResende - 21 Jun 2007 :) -- SamuelCochran - 6 Jan 2008

Common Ground

Both PHP and Python:

  • are interpreted, high level languages with dynamic typing
  • are OpenSource (except PHP's ZEND engine?)
  • are supported by large developer communities
  • are easy to learn (compared to Java, and even Perl)
  • are easy to extend in C, C++ and Java
  • are extremely portable. They run on almost all platforms in existence without recompilation.
  • support for variable number of function arguments.
  • have the ability to freeze live objects in a string representation (for storing arbitrary objects on disk, moving them over the network, etc); they can then be converted back to identical objects with data intact. PHP's serialize function; Python's pickle and marshal modules. Note that PHP, handling of serialized objects and classes is much weakier and error prone than Python's due to PHP's lack of modules. When an object is serialized, only its attributes are stored, not its methods. Thus, the object's class must be present (with the exact same name) in the script that unserializes it. In Python this is handled automatically via the module/import framework. (this COULD be handled with PHP 5's __autoload(), but is not done automatically)

Compared as Languages

What does PHP have that Python doesn't?

  • syntax from C and Perl, with lots curly braces and dollar signs
  • the 'switch' statement and 'do ... while' construct
  • increment and decrement and assignment operators (assignment is a statement only in Python)
  • the ternary operator/statement (... ? ... : ...) (Python 2.5 added x = value if test() else other_value)
  • schizophrenic tableau of function names. The builtin library has a wide variety of naming conventions. There are no namespaces, so functions often have prefixes to denote their source (but often not). Functions are often placed into classes to simulate namespaces.
  • a very casual language, where globals are often used to pass arguments, all variables are "set" (to NULL), and a somewhat weak type system (not to be confused with dynamic types) (global variables should not be used, that is language independent)
  • an expedient (commonly installed) environment
  • aliases ('$a =& $b' means that when $b changes, $a changes also) (should be "references", not "aliases", but are called aliases)
  • one array type that doubles as a list and a dictionary. Dictionary keys are iterated in their original order.
  • (An EXCELLENT on-line Manual)
  • (Class magic methods)
  • (A somewhat clean code. Where is the public/private/protected/final/.. atributes in python? Why do I have to always put "self" on class methods?)

What does Python have that PHP doesn't?

  • a general purpose programming language (not just for the web) (not true PHP has a CLI SAPI, and is embeddable) (PHP was created for the web but has branched into general purpose applications, however it's arguably not "good at/for it")
  • indentation is used to mark out block structure rather than curly braces
  • namespaces and modules
  • a small core
  • very clear, concise, and orthogonal syntax
  • it is self documenting with docstrings and pydoc (PHP 5 has reflection and doc strings)
  • keyword arguments to functions and methods, easy support for default arguments (PHP has easy support default arguments: http://uk2.php.net/manual/en/functions.arguments.php)
  • true object orientation and 'first class' classes and functions (OO has been completely revamped in PHP 5)
  • classes are used extensively in the standard library
  • a notion of private attributes (PHP 5 supports this)
  • multiple inheritance
  • object-oriented file handling
  • method chaining
  • excellent introspection (PHP 5 Reflection)
  • everything is a reference! (references are painful in PHP) (Not in PHP 5)
  • one 'del' statement for all data types. PHP has 'unset' for variables and something else for array members. (Array members can be unset())
  • consistent case sensitivity (PHP does for variables, but not functions) (Functions are case insensitive)
  • a simple array slicing syntax
  • lambdas and other builtin functional programming constructs (php.net/create_function - create_function is not a true lambda and pollutes the global namespace, particularly dangerous in any type of loop)
  • iterators (PHP 5)
  • structured exception handling (PHP 5)
  • operator overloading
  • SWIG? integration
  • threading
  • an excellent profiler, plus several debuggers and IDEs (PHP has had this for a long time)
  • lots of high-level data types (lists, tuples, dicts, mx.DateTimes, NumPy arrays, etc.)
  • differentiation between arrays (lists) and associative arrays (dictionaries) (that is not an advantage)
  • dates that aren't limited to UNIX timestamps (<1970,>2038)
  • cached byte-code compilation (available for $980 in PHP!) (pecl.php.net/apc -- FREE, but not standard amongst PHP hosts) (roadsend is now also open source)
  • a standardized database API (pecl.php.net/PDO -- PHP 5.1)
  • support for all major GUI frameworks
  • strong internationalization and UNICODE support (May be available in PHP 6, but only when enabled and requires an external package)
  • maturity, stability and upward-compatibility (PHP is stable, mature and up/backward-compatible - not cleanly?)
  • tends to lead to much more scalable applications -- importing modules is safer than textually including code as in PHP: global variables are not used to exchange information. (global variables should not be used, that is language independent)

Compared as Web Development Frameworks

Unlike PHP, which has web development features built directly into the core language, Python's web development capabilites are provided by add-on modules. Basic CGI capabilities are provided by the 'cgi' module which comes in Python's standard library. There's also a wide range of third-party modules available for Python; some are complementary, others compete. As a result, Python provides a more flexible base for web development.

There are some adverse side effects of this flexibility. First, the range of choices can be bewildering. Unless you are working experienced Python web developers, PHP is easier to get started with. Second, support for PHP is more common with shared-hosting companies than support for the various Python options.

Another difference is that PHP is embedded in the web server, whereas Python web applications can either be embedded in the web server like PHP or run in a separate process. Here's a simple classification of Python web development platforms:

  • emdedded in the web server process
    • Apache modules mod_python and mod_snake embed the Python interpreter in Apache and allow other Apache modules to be written with Python. This is the same idea as mod_perl.
    • PyWX is an extension to AOLServer that serves the same purpose as the Apache modules above.
    • MS ASP scripts can be written using Python via Active Scripting Host.
  • running in a separate process
    • non-persistent process (a new process is spawned for each request)
      • custom CGI scripts
    • persistent process (all requests are sent from the web server to one persistent process, sometimes via a CGI wrapper)
      • custom Fast-CGI scripts
      • custom SCGI scripts
      • custom WSGI? modules
      • 'Application Servers'
        • Zope -- comes with its own web server but can also communicate with Apache via the CGI or Fast-CGI protocols.
        • Webware? -- works with any web server via CGI. With Apache it can communicate via a custom Fast-CGI like protocol.
        • SkunkWeb? -- only works with Apache, communicates via a custom Fast-CGI like protocol.

(Note: PHP programs can be run standalone or as ordinary CGI scripts. However, when called indirectly from the web (e.g., from a Perl CGI script), it requires unsetting an undocumented number of web environment variables so that PHP doesn't think it's running from the web and look in the wrong place for the script. Likewise, it's _possible_ to write a long-running server in PHP, but there are precious few examples of it.)

The vast majority of Python web applications are run in a separate process. This has some important implications. ... to be continued ...

... please add your observations

Python Template Engines

...

Here's some interesting notes on security in PHP: (Not true. The tutorial assumes default conf values that are not default anymore or don't even exist) http://www.securereality.com.au/studyinscarlet.txt

Community Support

PHP

  • huge installed user base, but the figures are probably distorted by shared hosting (Not true. It has PEAR and PECL repository)
  • low signal-to-noise ratio -- because PHP is so expedient, many of the users are not invested in the technology (or even their own code) or the community (Not true. IBM and Oracle invested in PHP)

Python

  • sizable, but not huge, installed user base
  • Python Software Foundation
  • lots of specialized interest groups
  • very high signal-to-noise ratio

Documentation

Core Documentation

Although both PHP and Python have excellent core documentation, Python's is more extensive and generally higher quality. PHP has a large number of translations available. Python doesn't. For PHP see http://www.php.net/docs.php and for Python see http://python.org/doc/ Python allows documentation on modules, classes, and functions to be included in the program code. The documentation becomes an attribute of the module/class/function, accessible from inside of the language itself. (This is so untrue. Python docs are short and don't explain in detail how something can or should be used. PHP uses examples (L.B.E.). PHP has comments on every page so you can check for someone that tried to do the same thing you did. PHP can be documented just like many other languages like C for example; http://www.phpdoc.org/ )

Frequently Asked Questions

Q1

... what is the best way to build web-based database applications like accounting systems, on Python? i.e. what is the equivalent of ASP pages or PHP pages or JSP pages, for Python?? Shouldn't we be learning THAT instead of PHP???

A1

There is no simple answer to this question. There are many tools available for doing this in Python. So many that the choices can be bewildering. You're best to think of the tools as falling into two complementary categories: Application Servers (there's probably a better term to use here) and Template Engines.

Application Servers:

Templating Engines:

My personal preference is Apache/Webware/Cheetah. I'll write more about this later. -- TavisRudd? - 23 Nov 2001

General Discussion

(add your comments here, along with a signature and date)


I haven't used PHP with XML, and I've only used Python with XML a little, but I get the impression Python is much better suited -- specifically because it is strongly types, where PHP is rather weak in its typing (like C). But I can't say from experience

-- IanBicking - 26 Nov 2001


To clarify, PHP's types are more dynamic than Python's. All variables are automatically initialized to NULL. It automatically converts between strings, numbers and NULL when a different type is needed for the operation, or with a type case. It also "does something" to convert to/from array and object. '123' -> 123, 'non-numeric' -> 0, NULL -> '', etc. Sometimes all this is convenient, especially when a missing CGI param converts to NULL which converts to '' in the VALUE= attribute, but it also leads to wrong ouput rather than errors if you misspell a variable or key.

PHP does not have first-class functions. There are equivalents to Python's map, reduce, filter, and there's array_walk, but they all take the name of a function rather than the function itself.

Examples of PHP's schizophrenic function naming: (string functions) stripslashes vs strip_tags; (array functions) array_keys vs asort vs count and shuffle; (variable functions etc) isset vs is_array.

PHP has constants, which are initialized with a totally different syntax than variable assignment. The advantage of constants is that they can be defined only once, allowing you to define sensitive constants in a secure include file, then prevent untrusted code from overriding them. Constants are global: they bypass the scoping rules. One disadvantage is that a constant is a bare word: if you misspell it, you'll silently get a NULL value.

Syntax errors show the file and line number, but not the character position. Sometimes the error message is specific, sometimes just "parse error". This leads to staring at the code for a while until you realize you're missing '$' or ';', or you put something besides a semicolon on the END line matching <<

-- MikeOrr - 15 Dec 2001

Back up files that have been modified today, and tar (winrar, zip) them!


' This script would backup all folders (including their subfolders) and files
' that are under the path specified in the objStartFolder variable.
'
' Only those files that have been modified today would be backed up.
'
' Note: if you don't want the files in .zip (or .rar) to be full path as where
' the files were original stored (using relative path in .zip file), make sure you put this script in the same
' directory of the files you want to back up. Otherwise, you would need to
' modify this script to suit your need.
'
' You can run this script in more than three ways:
' Way 1: cmd > cscript.exe script_name.vbs
' Way 2: double click on the script_name.vbs
' Way 3: run the script in scheduled tasks.

Dim MyParentPath
Dim MySubFolderFilePath

MySubFolderFilePath = ""

Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\Documents and Settings\Danny\Desktop\tmp"

' Specify the full path where the .zip will be stored, including .zip file extension and .zip file name.
ZipFileExtension = ".rar" ' can be either .zip or .rar
ZipFileName = "C:\DB_Backup_" & dateFormatLeadingZero( date() ) & ZipFileExtension

Set objFolder = objFSO.GetFolder(objStartFolder)
MyParentPath = objFolder.Path

'Wscript.Echo MyParentPath & "___"

Set colFiles = objFolder.Files
For Each objFile in colFiles
' Wscript.Echo """" & objFolder.Path & objFile.Name & """"
' Wscript.Echo """" & objFolder.Name & "\" & objFile.Name & """"
MySubFolderFilePath = MySubFolderFilePath & """" & objFile.Name & """" & " "
Next

ShowSubfolders objFSO.GetFolder(objStartFolder)

Wscript.Echo MySubFolderFilePath

Set wshShell = WScript.CreateObject ("WSCript.shell")
wshshell.run """C:\Program Files\WinRAR\WinRAR.exe"" a " & ZipFileName & " " & MySubFolderFilePath,0,True
set wshshell = Nothing

Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
' Wscript.Echo Subfolder.Path
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
' Wscript.Echo """" & Subfolder.Path & objFile.Name & """"
' Wscript.Echo """" & objFile.ParentFolder & "\" & objFile.Name & """"
If objFile.DateLastModified >= Date() Then
MySubFolderFilePath = MySubFolderFilePath & """" & Mid( objFile.ParentFolder & "\" & objFile.Name, Len(MyParentPath) + 2 ) & """" & " "
End If
Next
ShowSubFolders Subfolder
Next
End Sub

' Display a date with leading zero.
Function dateFormatLeadingZero( theDate )
dateFormatLeadingZero = DatePart("yyyy",theDate) _
& Right("0" & DatePart("m",theDate), 2) _
& Right("0" & DatePart("d",theDate), 2)
End Function

Key Factors for a Sucessful Startup

Key Factors for a Sucessful Startup

據林富元表示,有十八訣:
有無良好完整的成熟經營團隊?
有無與眾不同而居於領先的知識能力?
對市場是否有踏實而足夠的認識? 所嚮往的市場是否處在初生期或成長期?
是否一窩蜂追逐時尚隨波逐流?
有無知識產權或產品的智慧財產?
企劃中的產品或服務是否擁有很高的進入門檻?
對檯面上隱藏中的競爭者有無充份的瞭解?
知道自己在市場上,依長處而取決的區隔定位嗎?
有無完整的三至五年計畫書及財務分析報表?
是否能籌募完整足夠的創業基金?
投資股東有附加價值嗎?
經營團隊與投資股東享有良好互補關係? 它將影響你股東未來與你一路跟進的支撐力?
主要領導者的人格品質與靈活堅忍性? 有無能力雄厚的 CEO 對企業的影響成敗至大。
公司的整體文化為何? 撇開教條與文宣,公司整體是否具有共體時艱的內在文化?
這個企業能吸引到足夠的夥伴與聯盟?
團隊有市場開發能力嗎?
公司的遠景與願景是永續經營或曇花一現?
最終的最偉大雋永的價值,你是否取得了內外大眾的信任?

QOTD: Paul Graham on Language

QOTD: Paul Graham on Language

摘自 Hackers & Painters

* 電腦程式只是文字。選用的語言則決定了你的語彙能力。程式語言是程式設計者思考的方式。

* 程式設計師傾向歸屬於所用語言的派別,甚至比他們所用的語言區隔更大。因此,談到某種語言優於其他,會被認為是壞習慣。但是連程式設計師自己都不相信這種虛偽的禮節。我對於程式語言的看法或許會惹怒很多人,不過我認為這是瞭解駭客最好的方法。

* 程式語言是用來思考程式,而不是用來展現你已經想出來的程式。它應該像是一支鉛筆,而不是一支鋼筆。如果大家寫程式的方法跟我大學所學相同,靜態型別應該 會是一個優秀概念,不過,我所認識的每一位駭客,都不用這種方式來撰寫程式。我需要一個可以隨意擦寫塗抹的程式語言,而不是讓語言要求我正襟危坐地捧著型 別,非常禮貌地與嚴謹過時的編譯器對話。

Python Handbook

Python Handbook

How to Think Like a Computer Scientist 這本書裡提到,電腦專家的養成過程中,學習化解問題 (Problem Solving) 是重要的能力之一,它包括下列的步驟:

1. 具體地描述問題
2. 發揮創意地尋找解決方法
3. 清楚明確地表達解決方法

學習程式語言正是練習化解問題的絕佳機會,程式語言也為更深層的電腦歷險打開了窗。

工欲善其事,必先利其器,想快速學好程式語言,當然也要選個好工具。
推薦學習 Python 程式語言,因為具備下列的優點:

- 易學易安裝
- 開放源碼免費在各式環境執行
- 原始碼易讀易管理

學 習 Python 該有哪些相關先備知識? 物件觀念,shell 環境的操作,以及檔案系統結構,都是重要的項目,另外,C 語言的基本觀念與技巧,也會有助於 Python 的學習,比如說,使用 「C tutorial」 為關鍵字詞到搜尋引擎找資料。這些簡單的先備知識,有助於學習其他多種程式語言,值得一併認識。

程式語言的學習方法,其原則與日常語言極其相似。
「應用於日常生活」及「依樣畫葫蘆」,是兩條值得採用的好原則。
在生活裡尋找程式語言的應用機會,能讓語言學習增添動機與樂趣,模仿前人的程式範例,可省茫然摸索的時間浪費,日久自然能有舉一反三之效。

Python 語言的延革

* 1991 年由 Guido van Rossum 在荷蘭阿姆斯特丹 CWI 研究中心工作時所創作及發展。
* 1995 年到 2000 年之間,作者 Guido 先後在美國 CNRI 研究中心及 BeOpen.com 工作,並發展 Python 1.5 及 1.6 版本。
* 經由 Zope 公司的主要協助,2001 年之後 Python Software Foundation 成立,軟體開發的領導人仍為 Guido。
* 早期 Python 以 C 語言為基底撰寫而成,目前則有以 Java 語言為基底的 Jython 及架構在 .NET 的 IronPython 版本。
* Guido van Rossum 在 2005 年底成為 Google 公司僱員,該公司將 Python 程式語言列為程式員的三大官方語言之一。

Python 語言的特色

* 易學易用 (Easy Learning)
* 語法結構清晰 (Clear Syntax and Structure)
* 物件導向式 (Object Oriented)
* 直譯式、交談式 (Interpreted, Interactive)
* 跨平台 (Cross Platform)
* 延伸與內嵌 (Extended and Embedded)
* 開放源碼 (Open Source)

其優點有

* 適於入門學習。語法簡易而直覺,接近自然語言,入門後又可輕鬆地接續 C、Java 等語言的學習。
* 完整的函式庫及模組支援。常見的程式設計需求,利用內建資料型別及函式庫就能有效滿足,還可援用網路上豐富的模組與應用程式。
* 適於大型專案開發。從設計哲學及語法結構開始,就要求程式員撰寫清晰可讀的原始碼,大幅提昇其維護性。
* 資料處理能力佳。已內建 Regular Expression 及 Unicode 支援。
* 容易結合其他語言及工具。例如 C、Java、.Net 等語言及環境,還有 Eclipse、wxPython、SPE IDE 等工具。
* 生產力及執行效率能有最好平衡。採用 bytecode 格式及 virtual machine 運作機制,另外可用 C 語言等系統語言,將效率瓶頸的程式區段改寫。

應用實例有

* 教學環境: MIT 新生程式入門及 OLPC 計畫選用 Python 為預設語言。
* 入口網站服務: Google, YouTube, Yahoo! 網站的關鍵服務以 Python 語言開發。
* 動畫軟體: Maya, Blender 語言擴充介面支援 Python 語言。
* 圖形介面及動畫遊戲: wxPython, PyGame 是協助創作的好工具。
* 郵遞論壇: mailman 程式以 Python 語言寫成。
* 網頁應用伺服與開發框架: Zope, Django, TurboGears 是主要的範例。
* 安裝程式: Red Hat Linux 開機安裝程式及 Gentoo 套件管理。
* 檔案點對點分享工具: BitTorrent 工具程式以 Python 語言開發。

直譯器提供一個交談式環境,使用者可以輸入指令,直譯器則會在螢幕上顯示執行結果,包括錯誤時的訊息,讓使用者即時體驗 Python 的運作方式,就像面對一位有問必答的老師。

從 Python 的下載網址 http://www.python.org/download/ 可以找到所有版本的檔案,包括各式平台的執行檔及原始碼檔案。

在 Windows 環境中,選取執行 IDLE (Python GUI) 或 Python (command line) 可進入 Python 交談式操作介面。「>>>」是提示符號,代表 Python 已經就緒,使用者可以輸入指令。

Executing an EXE inside a VBScript file that has spaces in the path.

Executing an EXE inside a VBScript file that has spaces in the path.

I've done quite a bit of scripting but ran across something that baffles me. Trying to execute a file in a directory with a spaces in the path would bomb. I googled and found a thing that has me put [] inside to fix it but it didn't work. Here is what i was trying to do, if there is no spaces in the path to the EXE including any directories, the script works fine. Here is an example to a path for an EXE c:\winnt\system32\Ica PassThrough\pn.exe. Here is the script code

Set wshShell = WScript.CreateObject ("WSCript.shell")
wshshell.run "c:\winnt\system32\Ica PassThrough\pn.exe", 6, True
set wshshell = nothing

Of course, this code would BOMB! The script would return an error complaining it couldn't find the file. Thanks to quick posting in the news://msnews.microsoft.public.windows.server.scripting newsgroup.

Al Dunbar, world famous fellow MVP posted the answer to my prayers!

Your .run command is trying to run something called "C:\winnt\system32\ica" and pass it a parameter called "PassThrough\pn.exe". This is the same thing you would get if you typed the following at a command prompt:

c:\winnt\system32\Ica PassThrough\pn.exe

If the name of the file to run is actually "c:\winnt\system32\Ica PassThrough\pn.exe", you would enter it at the command prompt as:

"c:\winnt\system32\Ica PassThrough\pn.exe"

The double quotes in your code do not form part of the filename string being passed to the .run method, they are required to indicate a literal string.
You can prove this is the case by changing your script to look like this:

> Set wshShell = WScript.CreateObject ("WSCript.shell")
> wshshell.run c:\winnt\system32\Ica PassThrough\pn.exe, 6, True
> set wshshell = nothing


Which will throw a syntax error (for rather obvious reasons). You need to pass a string that actually contains the quoted filename, which can be done this way:

> wshshell.run """c:\winnt\system32\Ica PassThrough\pn.exe""", 6, True

Within a literal string, a single double-quote character is represented by two double-quote characters. Notice the Three double quotes around the string, This worked! Thought I'd pass this tip along.

Tuesday, October 28, 2008

vbscript run external command software executable file .exe


Set wshShell = WScript.CreateObject ("WSCript.shell")
wshshell.run "c:\windows\system32\cmd.exe" ,8,true
set wshshell = Nothing

' First: try ",0,True" instead of ",10,True" at the end of your run method.
' That wshshell.run value indicates intWindowStyle Which can be one of the following:
'
' 0 Hides the window and activates another window.
' 1 Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
' 2 Activates the window and displays it as a minimized window.
' 3 Activates the window and displays it as a maximized window.
' 4 Displays a window in its most recent size and position. The active window remains active.
' 5 Activates the window and displays it in its current size and position.
' 6 Minimizes the specified window and activates the next top-level window in the Z order.
' 7 Displays the window as a minimized window. The active window remains active.
' 8 Displays the window in its current state. The active window remains active.
' 9 Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.
' 10 Sets the show-state based on the state of the program that started the application.

Back up files that have been changed or modified today


@echo off
:: Default to tokens 1 to 3.
SET UnivDateTokens=1-3

:: Determine the first token.
FOR /F "tokens=1 delims=.:/-, " %%A IN ('DATE /T') DO SET UnivDatePart1=%%A

:: If the first token is a letter then use tokens 2 to 4 instead.
IF "%UnivDatePart1:~0,1%" GTR "9" SET UnivDateTokens=2-4

:: Extract the current date and put it into the yy, mm, dd variables depending upon the system date format.
FOR /F "tokens=%UnivDateTokens% delims=.:/-, " %%A in ('DATE /T') DO (
FOR /F "skip=1 tokens=2-4 delims=/-,()." %%D IN ('ECHO.^|DATE') DO (
SET %%D=%%A
SET %%E=%%B
SET %%F=%%C
SET UnivDatePart1=
SET UnivDateTokens=
)
)

:: Create a shortcut to the current date/time in CCYYMMDD format.
SET TodaysDateTime=%MM%-%DD%-%YY%

:: variables
set drive=C:\BackTmp
set backupcmd=xcopy /s /c /d:%TodaysDateTime% /e /h /i /r /y

:: echo ### Backing up My Documents...
:: %backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents"

:: echo ### Backing up Favorites...
:: %backupcmd% "%USERPROFILE%\Favorites" "%drive%\Favorites"

:: echo ### Backing up email and address book (Outlook Express)...
:: %backupcmd% "%USERPROFILE%\Application Data\Microsoft\Address Book" "%drive%\Address Book"
:: %backupcmd% "%USERPROFILE%\Local Settings\Application Data\Identities" "%drive%\Outlook Express"

:: echo ### Backing up email and contacts (MS Outlook)...
:: %backupcmd% "%USERPROFILE%\Local Settings\Application Data\Microsoft\Outlook" "%drive%\Outlook"

:: echo ### Backing up the Registry...
:: if not exist "%drive%\Registry" mkdir "%drive%\Registry"
:: if exist "%drive%\Registry\regbackup.reg" del "%drive%\Registry\regbackup.reg"
:: regedit /e "%drive%\Registry\regbackup.reg"

:: use below syntax to backup other directories...
:: %backupcmd% "...source directory..." "%drive%\...destination dir..."

%backupcmd% "%USERPROFILE%\Desktop\test_replace" "%drive%\test"

echo Backup Complete!
@pause

Batch .bat scripting, output current date todayb


@ECHO OFF
REM Default to tokens 1 to 3.
SET UnivDateTokens=1-3

REM Determine the first token.
FOR /F "tokens=1 delims=.:/-, " %%A IN ('DATE /T') DO SET UnivDatePart1=%%A

REM If the first token is a letter then use tokens 2 to 4 instead.
IF "%UnivDatePart1:~0,1%" GTR "9" SET UnivDateTokens=2-4

REM Extract the current date and put it into the yy, mm, dd variables depending upon the system date format.
FOR /F "tokens=%UnivDateTokens% delims=.:/-, " %%A in ('DATE /T') DO (
FOR /F "skip=1 tokens=2-4 delims=/-,()." %%D IN ('ECHO.^|DATE') DO (
SET %%D=%%A
SET %%E=%%B
SET %%F=%%C
SET UnivDatePart1=
SET UnivDateTokens=
)
)

REM Create a shortcut to the current date/time in CCYYMMDD format.
SET TodaysDateTime=%YY%-%MM%-%DD%

echo %TodaysDateTime%

@PAUSE

How to Backup using Batch Files

How to Backup using Batch Files
2004.12.10 13:03 EST by Philip


Sometimes it is useful, or even necessary to simply copy existing directories to another hard disk or network drive, rather than using more complicated backup methods. Multiple directories can be backed up comparatively easy with a simple click, by creating and running a batch file. That file can be executed manually from your desktop, can be added to startup or scheduled for periodic execution as needed.

Batch files have comparatively easy syntax and can have many uses, so this method could also be a good learning experience by example. You can simply copy the text below, and paste it into Notepad. Create a new file with either .bat or .cmd extension, rather than txt.

Here is a working example of a backup script you can modify for your needs:

@echo off
:: variables
set drive=G:\Backup
set backupcmd=xcopy /s /c /d /e /h /i /r /y

echo ### Backing up My Documents...
%backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents"

echo ### Backing up Favorites...
%backupcmd% "%USERPROFILE%\Favorites" "%drive%\Favorites"

echo ### Backing up email and address book (Outlook Express)...
%backupcmd% "%USERPROFILE%\Application Data\Microsoft\Address Book" "%drive%\Address Book"
%backupcmd% "%USERPROFILE%\Local Settings\Application Data\Identities" "%drive%\Outlook Express"

echo ### Backing up email and contacts (MS Outlook)...
%backupcmd% "%USERPROFILE%\Local Settings\Application Data\Microsoft\Outlook" "%drive%\Outlook"

echo ### Backing up the Registry...
if not exist "%drive%\Registry" mkdir "%drive%\Registry"
if exist "%drive%\Registry\regbackup.reg" del "%drive%\Registry\regbackup.reg"
regedit /e "%drive%\Registry\regbackup.reg"

:: use below syntax to backup other directories...
:: %backupcmd% "...source directory..." "%drive%\...destination dir..."

echo Backup Complete!
@pause

The above example backs up "My Documents", Favorites, Outlook Express email/address book, (all for the current user) and the Windows Registry. It copies the files to the directory defined in the %drive% variable, or "g:\Backup". If the script is ran multiple times, it will only rewrite if the source files are newer. It will create subdirectories as necessary, and it will retain file attributes. It can copy system and hidden files.

In the above file, all lines that begin with "::" are comments. The "set drive=" and "set backupcmd=" near the top define two variables (referenced by %drive% and %backupcmd%), used a number of times throughout the file; the first being the location of the top directory where we want to backup, and the second the actual copy command with all necessary switches. All the "echo " lines in the file simpy output the line of text to the screen, and the lines beginning with %backupcmd% are the actual commands to execute.

Note that most of the folders in the above backup example are subdirectories of the %USERPROFILE%... It is possible to simply backup the entire user profile with My Documents, Favorites, Outlook Express, Outlook, etc. by backing up this one folder. Here is an example (it assumes the above "drive" and "backupcmd" variables are set):

%backupcmd% "%USERPROFILE%" "%drive%\%UserName% - profile"

Backing up Other Directories and networked PCs

You can backup other directories by simply creating more alike lines:

%backupcmd% "...source dir..." "%drive%\...destination dir..."

For example, if you'd like to backup "C:\Program Files\Microsoft Office" to our destination "G:\Backup\MS Office" (and retain the directory structure) you'd need to add the following line to the batch file:

%backupcmd% "C:\Program Files\Microsoft Office" "%drive%\MS Office"

Here is another example, backing up the Administrator Profile on a machine on the LAN with computer name "Lianli":

%backupcmd% "\\Lianli\c\Documents and Settings\Administrator" "%drive%\Lianli - admin profile"

Remember, you have to save the batch file with either .bat or .cmd extension, then just double-click to execute it.

Using the Current Date

Sometimes it is useful to create folders with the date incorporated in the folder name. Here is how to set the variable folder to the current date (assuming US system date format):

set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%
%backupcmd% "...source dir..." "%drive%\%folder%\...destination dir..."

It is also possible to use the current time in the folder name. The following example with incorporate both the current date and time to the minute, separated by underscores. There is an extra step that cleans up possible spaces in single-digit hours in the system time:

set hour=%time:~0,2%
if "%hour:~0,1%"==" " set hour=0%time:~1,1%
set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%_%hour%_%time:~3,2%
%backupcmd% "...source dir..." "%drive%\%folder%\...destination dir..."

Example - dated directories

In the example below, we first set 3 variables: drive, folder, and backupcmd. The "drive" variable defines the root directory of our backups. The "folder" takes the 2 digit day value from the current date (US date format, taking 2 digits from the date command output, starting at the 7th character), which we will use as a subdirectory. The third variable, "backupcmd" defines our backup command with the appropriate command line switches we want to use.

@echo off
:: variables
set drive=D:\Backup
set folder=%date:~7,2%
set backupcmd=xcopy /s /c /d /e /h /i /r /k /y

echo ### Backing up directory...
%backupcmd% "C:\Program Files\somedirectory" "%drive%\%folder%"

echo Backup Complete!
@pause

This example will backup the "C:\Program Files\somedirectory" folder to "D:\Backup\[dd]" where [dd] is the current day of the month. After a month, we will have 30ish daily copies of the backup... And, because of the xcopy command line switches chosen, following backups will only overwrite files that are newer, speeding up subsequent backups. Alternatively you can add a line to delete the %folder% directory prior to executing the %backupcmd% if you prefer to start clean (and take longer).

Cleaning up

It is usually a good idea to clean up temporary files, cookies, and history from the destination backup, as applicable. It is especially useful if you're backing up full, multiple user profiles and overwriting them periodically. Since temporary files and cookies change, your backed up directories will keep increasing with unnecessary files. To remedy this, the following code can be added to the backup script, or to a separate batch file. It will automatically search all subdirectories for "cookies", "temp" and "history", and then remove those directories:

:: change to the destination drive first
G:
:: your parent backup directory
drive=G:\Backup

echo ### Searching for files to clean up...
cd %drive%
dir /s/b/ad \cookies > %drive%\cleanup.txt
dir /s/b/ad \temp > %drive%\cleanup.txt
dir /s/b/ad \history > %drive%\cleanup.txt

echo ### Deleting cookies, temp files and history from backup dir
for /f "delims=" %%J in (%drive%\cleanup.txt) do rd "%%J" /Q/S

echo Cleanup complete
@pause

Note that you need to change to the destination drive, and the main backup directory before searching for files to delete. Any sub-folders that contain "cookies", "temp", or "history" will be deleted automatically. You can test to see what will be deleted by commenting out the "for /f ....." line (just add :: to the beginning of the line, or delete it from the batch file and add it again later). If that line is not present, the file will only list all files to be deleted in the cleaup.txt file, located in the destination directory (G:\Backup\cleanup.txt in the above example). If you add the cleanup portion to the end of your backup batch file, you may want to remove the "@pause" line at the end of the backup portion, so everything can execute without user interacion.

Alternatively, there is a simpler one-line method of deleting specific subdirectories after backing up. The disadvantage of using this method is that you'd need another line for each separate directory to be removed... In other words, it doesn't work well when removing a large number of directories by similar names. Still, here is an example:

rmdir /s /q "%drive%\%UserName%\Local Settings\Temporary Internet Files"

Notes:

  • Any batch file can be interupted with CTRL+C or CTRL+Break if needed. They can also be paused with the Pause/Break key.
  • Instead of backing up My Documents, Favorites, Outlook and Outlook Express files separately, you can combine it all into one line for the current user: %backupcmd% "%USERPROFILE%" "%drive%\%UserName% - profile" . The only disadvantage being that it would save temporary IE files as well (however the default location of those can be changed, or you can automate cleanup after backing up, as described above).
  • The Registry backup in the above examples works well only for partial registry restores, it does not save the complete system state. Read this FAQ for more info