pigfoot’s weblog

We should forget about small efficiencies — Donald Knuth

Archive for the ‘Develop’ Category

Although mordem md5sum(1) of coreutils in Linux can acknowledge the md5sum of FreeBSD format, I still want to convert FreeBSD format to Linux one via python. Here is original file:

md5sum generated by md5(1) of FreeBSD

MD5 (Thunderbird-1.5.0.4.exe) = 3b862cd35571ecec3de5e34112bf3f15
MD5 (Thunderbird-1.5.0.5.exe) = 3b93bd5529e2a81054514f57dc4b3916

And I want to convert to:

md5sum generated by md5sum(1) of Linux

3b862cd35571ecec3de5e34112bf3f15  Thunderbird-1.5.0.4.exe
3b93bd5529e2a81054514f57dc4b3916  Thunderbird-1.5.0.5.exe

The sample code is quite simple:

# Open file named md5sum.txt
hFile = open ("md5sum.txt", "rU")

# Read whole content into a List file handle
aListLines = [szLine for szLine in hFile]

# Loading completed, then close file handle
hFile.close()

# Reset output list
aListOutputLines = []

# Process each line one by one
for szLine in aListLines:
....# split 'szFile = szHash' by three charactes of ' = '
....szFile, szHash = szLine.split(' = ')
....# Strip what we don't need and add two characters of space
....aListOutputLines.append(szHash.rstrip('\n') \
........+ ' ' * 2 \
........+ szFile.lstrip('MD5 (').rstrip(')'))

# Now aListOutputLines is final result, hence we open file to write next
hFile = open("md5sum.txt.new", "w")

# Process each line one by one
for szLine in aListOutputLines:
....hFile.write("%s\n" %  szLine)

# Closing a handle is a good habit, it's unnecessary though
hFile.close()

It’s all ;-)

By the way, the meaning of open (“md5sum.txt”, “rU”) is called open file with Universal Newline.

Popularity: 9% [?]

  • 2 Comments
  • Filed under: Develop, Python
  • Key Porting Differences from LinuxThreads to NPTL, from OSNews.

    The LinuxThreads project originally brought multithreading to Linux, but didn’t conform to POSIX threading standards.

    The introduction of Native POSIX Thread Library (NPTL) however, overcame many of these disadvantages.

    This article describes some of the differences between these two Linux threading models for developers who may need to port their applications or who simply want to understand where the differences lie.

    Popularity: 4% [?]

  • 0 Comments
  • Filed under: Develop
  • Meld : Diff and merge tool

    在 Windows 上, 就 Diff 和 Merge 的 Tool 來說, Araxis Merge 算是一絕, 那在 Linux 上就沒有這麼好用的 Tool 了. 不過今天才發現在 sourceforce.net 上有個 Meld 的 project, 可能也是 Gnome2 上 diff and merge 的殺手級 tool.

    這個是比對檔案的 screenshot:

    file diff screenshot

    這個是比對目錄的 screenshot:

    directory diff screenshot

    安裝的方法如果是 Fedora, 可以參考我寫的這篇 [RedHat] How to Fetch RPM? #1 – Fetch Manually. 它在 Fedora Extras 裡.

    Popularity: 12% [?]

  • 0 Comments
  • Filed under: Develop, IT, Linux, Unix
  • [MFC] CString Management

    CString Management, from CodeProject.

    CStrings are a useful data type. They greatly simplify a lot of operations in MFC, making it much more convenient to do string manipulation. However, there are some special techniques to using CStrings, particularly hard for people coming from a pure-C background to learn. This essay discusses some of these techniques.

    Much of what you need to do is pretty straightforward. This is not a complete tutorial on CStrings, but captures the most common basic questions

    From this article, we can learn how to effectively use CStrings.

    Popularity: 22% [?]

  • 0 Comments
  • Filed under: Develop, Windows
  • 用 C 語言窺探記憶體, from 中央大學數學系單維彰的網站.
    Introduction to Endianness.

    最後我們講一則有趣的故事. 為什麼字元的排序設計, 要叫做大頭或小頭呢? 雖然從前面的解釋, 我們看得出意義, 但是這背後其實有一個故事.

    Big-Endian 和 Little-Endian 並不是計算機工程師定的名稱, 而是英文作家 Jonathan Swift 在將近 300 年前創造的名詞!這個名詞出現於 Swift 創作的著名小說 “Gulliver’s Travels“, 中文通常翻譯作《格利佛遊記》或者《大小人國歷險記》或者《小人國歷險記》之類的, 許多讀者大概在童年時期讀過這本書的童話版節譯本.

    這部故事書裡, 有一個虛構的『小人國』, 稱為 Lilliput. 格利佛意外抵達 Lilliput 的時候, 該國正在內戰. 內戰分成兩大派系 (沒有派系就沒有內戰): Big-Endian 和 Little-Endian. Big-Endian 和 Little-Endian 為了一件很可笑的小事而分成派系: Big-Endian (保守派) 堅持要從雞蛋比較大的那一頭敲開蛋殼 (大頭開蛋), 而 Little-Endian (改革派) 堅持要從雞蛋比較小的那一頭敲開蛋殼 (小頭開蛋). 雞蛋比較大的那一頭叫做 big-end, 因此支持大頭開蛋者就叫做 big-endian; 同理, 另一派就叫做 little-endian 了.

    作者其實可能要藉用這個情節, 來諷刺當時在英國的政治與宗教時事. 後來, 計算機科學家也在爭吵關於 byte order 的問題: 究竟是把高位的字元放在前面比較好, 還是放在後面比較好? 一位當時在美國南加大的計算機科學家 Danny Cohen 在 1980 年 4 月 1 日,發表了標題為 “On Holy Wars and a Plea for Peace” 的文章 (後來在 1981 年刊登於 IEEE 的 Computer 期刊), 把這場計算機科學家的論戰比喻成格利佛在小人國遇見的 Big-Endian 和 Little-Endian 兩派之內戰. 這是非常有趣的譬喻, 一直流傳至今, 成為這兩種硬體設計理念的正式代名詞. 可見, 如果童話書讀得透徹, 長大後可以應用在偉大的論證上.

    真奇妙, 現在我才知道 Big-Endian 和 Little-Endian 的由來. ^^

    Popularity: 14% [?]

  • 0 Comments
  • Filed under: C/C++, Develop
  • Microsoft to launch code-sharing site

    Microsoft to launch code-sharing site called CodePlex, from ZDNet.

    Microsoft on Tuesday is expected to officially launch a community-building Web site where it will share code with developers.

    The CodePlex site will be a venue for Microsoft to provide programmers with tools available under its Shared Source licenses. These licenses allow people to view the source code of products, the software giant said.

    Popularity: 8% [?]

  • 0 Comments
  • Filed under: Develop, IT, Microsoft
  • VC Add-ins: WTL Helper

    WTL Helper, from CodeProject.

    Add-in for MS VC++.NET 2003 that helps to insert message handlers for WTL.

    Popularity: 24% [?]

  • 0 Comments
  • Filed under: Develop, Windows