The power of Mercurial Queues extension

When I work in a Mercurial local workspace, to fix one bug or add a new feature, I'd like to track my modifications in versioning way, so I did local check-ins on every milestone. While when I push the changes to parent workspace, all the changesets (even some trivial changes, e.g., fixing typo:$) will be saved to parent workspace.

I once used the most stupid way, having two local copies, one is for development, another one is for pushing to parent. Then I found one tip to concatenate multiple changesets into one changeset, but it still needs an extra clone. Finally, I met the MQ extension.

Refer to the tutorial, you would find it's really close to what you want.

Here I list the most important tips:

  • To initialize the patch versioned repository:
  • hg qinit -c

  • To convert all applied MQ patches into permanent changesets: (Note, after the conversion, you may not rollback the last changeset)
  • hg qdelete -r qbase:qtip

  • Synchronizing with upstream (which is much simpler than the steps in MqMerge, and does not introduce extra "merge marker" changeset)
  • hg qpop -a
    hg pull -u
    hg qpush -a

    python-rbtree和内建dict的性能比较


    python
    内建的dict(字典)类使用的是hash算法,因此它的key不是有序的。而C++中的std::map或std::set使用的是平衡二叉树(通常为红黑树),其key是有序的。在网上搜了搜,找到了一个用C和pyrex混合实现的红黑树模块,python-rbtree

    我编写了一个极简单的测试程序,在Solaris x86 + python 2.4.4平台上运行,分别使用dict和rbtree,插入两百万个记录(key是3个整型,value是1个整型,你大概猜到我在干什么了吧 :) )。且在dict插入完之后,调用dict.keys().sort()对其key进行排序(也就是快排)。比较的结果是,两种方法使用的内存相当(大概在200M左右)。但是hash算法的速度要快一倍以上。当记录个数增加到五百万个时,结果还是差不多──即内存使用相当,hash算法快一倍。

    至少在这个数量级上,内建的dict性能更佳。我还尝试了另一个纯Python的红黑树实现--RBTree.py,结果令人失望,在记录个数比较多的情况下,似乎根本无法得到正确的结果。

    结论,python中的dict是可信赖的!

    对Jserv的访问两篇

    Jserv(黃敬群)是名满两岸的自由软件开发者,是我崇拜的青年才俊、技术偶像之一。我虽然痴长了几岁,但是在Linux和自由软件开发方面却是后学晚辈。下面是台湾的同业者对Jserv的访问,读后直觉得自己光阴虚度了 :$。

    自由軟體開發者 Jserv 訪問 (上)
    自由軟體開發者 Jserv 訪問 (下)

    记得我最初了解到Jserv,是2002或03年,读到他的一篇关于Qt/Embedded本地化的文章。后来逐步看到他在浏览器、嵌入式系统、图形库、Java虚拟机、输入法、Linux内核、实时系统等各个方面的成绩,对他的技术能力真是钦佩不已。而且Jserv还是一位兼具诗人气质、十分感性的青年,从他许多的blog中,可以看到他对人生许多富有哲理性的思考。

    后来虽然在网络上有一些联络,但对他个人却了解不多。这两篇访问,正好满足了我的好奇... ...

    希望他将Lab的事业拓展到大陆来。

    Google released Android SDK preview


    Google released Android SDK preview today, have a look at the feature overview video. From the application development demonstration, and technical presentations (video 1, 2, and 3), you can see that Java (as a programming language) is almost everywhere, but on a different virtual machine--Dalvik Virtual Machine, a register-based (typically JVM is stack-based) virtual machine that optimized for mobile devices. Another interesting thing is, it supports OpenGL ES 1.0 specification, and the "Surface Manager" could seamlessly composite 2D and 3D graphic layers from multiple applications.

    Here is the architecture of Android platform (click to enlarge):

    You may download the SDK here.

    《货币战争》你读了么?

    经朋友的推荐,我去买了一本早已畅销多时的书──《货币战争》。一口气读完了,真是心惊肉跳。

    原来英格兰银行是私有银行啊,连美联储也不例外(也有很多人对此进行了反驳),而这两国的政府居然无权发行货币,需要将国家的赋税作为抵押从银行借贷,再由银行来发行。书中还描写了这些国际银行家是如何操纵国际金融市场(甚至环保都不放过),来牟取巨额利润的。

    然后去豆瓣上看了看大家的书评,有推崇备至的,也有不屑一顾的。不过对我这种金融门外汉来说,读过一遍还是很有收获的。

    人类获得自由和解放的路途还很遥远啊!

    本书作者的blog:http://currencywar.blog.hexun.com

    A simple stript to extract the contents from Sogou corpus

    I wrote a simple python script to extract the contents from Sogou corpus.

    #!/usr/bin/python
    import codecs
    import sys
    usage = """
    Usage:
        sogou_corpus_conv.py corpus_in_xml > contents_in_txt
    """
    try:
        file = codecs.open(sys.argv[1], "r", "GB18030" )
    except:
        print usage
        exit(1)
    for line in file:
        if line.startswith(""):
            start, end = len(""), -len("")-1
            line = line[start:end].replace(u'\ue525', '')
            print line.encode("UTF-8")
    

    With the extracted contents, you could continue to build the SunPinyin SLM.

    First impression about Indiana -- OpenSolaris Developer Preview

    Today, I installed indiana preview release (get it here) on an existing solaris partition. And the installation time is a little longer than I expected. The only one issue I met is, after the installation, grub was not installed properly. So, we have to use
    installgrub(1) to reinstall it on MBR. The root password on livecd is "opensolaris".

    Currently the software package repository is still small (have a look at http://pkg.opensolaris.org.) Anyway, it's the first step (also an important step), and I believe it will lead opensolaris to bigger success.

    BTW, you may try to install Glassfish packages via IPS, refer to http://wiki.updatecenter.java.net/Wiki.jsp?page=MultiPlatformIPSPrototype.