Friday, February 5, 2010

My digital home

  • Connecting people
  • Sharing information

Thursday, January 28, 2010

Submitted another bug to Eclipse

It's unavoidable to have ambiguous types in single Java file. The way to solve the problem is very easy, using fully qualified class name. Unfortunately, the Content Assist of Eclipse 3.6M4 is not that smart to generate correct code.

I submitted this bug to Eclipse today and let's see what will happen.

Friday, January 15, 2010

Floating point arithmetic in Python 3 is much more accurate

There is always limited precision in floating point arithmetic due to conversion between decimal and binary. But I found Python 3 becomes much more accurate.

 zhao@nettop:~$ python  
 Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15)   
 [GCC 4.4.1] on linux2  
 Type "help", "copyright", "credits" or "license" for more information.  
 >>> 12.6 / 2  
 6.2999999999999998  
 >>> 12.6 + 0.01
 12.609999999999999
 >>> float('3.2')
 3.2000000000000002  

 zhao@nettop:~$ python3  
 Python 3.1.1+ (r311:74480, Nov 2 2009, 14:49:22)   
 [GCC 4.4.1] on linux2  
 Type "help", "copyright", "credits" or "license" for more information.  
 >>> 12.6 / 2  
 6.3  
 >>> 12.6 + 0.01  
 12.61  
 >>> float('3.2')  
 3.2  
Who has any idea about this?

Wednesday, January 13, 2010

Go Google

Don't get me wrong. It is Go Google, not Google Go.

Today is a big day. A day that proves the failure of "being evil". A day that reveals (who is afraid of) the power of information and technology. A day that witnesses the pain of making no money by being fucked by someone with totally different values.

Visit the following 2 links and experience the history.

Official Google Blog: A new approach to China

Official Gmail Blog: Default https access for Gmail




Saturday, January 9, 2010

Let scim and ibus support Skype

By default, I cannot input Chinese in Linux version of Skype. This issue doesn't get solved when Karmic Koala decided to introduce a new input framework, ibus, to replace scim.

To solve this problem, add these 3 lines into your .bashrc file and reboot:
 export GTK_IM_MODULE=ibus  
 export XMODIFIERS=@im=ibus  
 export QT_IM_MODULE=ibus  

If you prefer scim, maybe these lines will help (not tested):
 export XMODIFIERS=@im=SCIM  
 export GTK_IM_MODULE=scim  
 export QT_IM_MODULE=scim  

Skype is better now under Ubuntu.

Sunday, January 3, 2010

Schema of iTunes podcast feed

In 2006, in order to aggregate my favourite podcasts and share them with other iPod owners, I did a podcast aggregation service named MyTunes.

I chose JAXB to map XML documents to Java objects and vice versa, so I need a schema or DTD file of iTunes podcast feed. Unfortunately I couldn't find one. I had to generate one myself.

I got an example feed from Apple. I removed a few elements that I think of no use at the moment and generated its schema.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" elementFormDefault="qualified">
    <xs:complexType name="channelType">
        <xs:sequence>
            <xs:element ref="title"/>
            <xs:element ref="link"/>
            <xs:element ref="language"/>
            <xs:element ref="description"/>
            <xs:element ref="pubDate"/>
            <xs:element name="image" type="imageType"/>
            <xs:element ref="copyright"/>
            <xs:element ref="subtitle"/>
            <xs:element ref="summary"/>
            <xs:element name="item" type="itemType" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:element name="copyright">
        <xs:simpleType>
            <xs:restriction base="xs:string">
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
        <xs:element name="subtitle">
        <xs:simpleType>
            <xs:restriction base="xs:string">
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
        <xs:element name="summary">
        <xs:simpleType>
            <xs:restriction base="xs:string">
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
    <xs:element name="description">
        <xs:simpleType>
            <xs:restriction base="xs:string">
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
    <xs:complexType name="enclosureType">
        <xs:attribute name="url" use="required">
            <xs:simpleType>
                <xs:restriction base="xs:anyURI">
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
        <xs:attribute name="length" use="required">
            <xs:simpleType>
                <xs:restriction base="xs:int">
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
        <xs:attribute name="type" use="required">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
    </xs:complexType>
    <xs:element name="guid">
        <xs:simpleType>
            <xs:restriction base="xs:anyURI">
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
    <xs:complexType name="imageType">
        <xs:sequence>
            <xs:element ref="url"/>
            <xs:element ref="title"/>
            <xs:element ref="link"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="itemType">
        <xs:sequence>
            <xs:element ref="title"/>
            <xs:element ref="link"/>
            <xs:element ref="description"/>
            <xs:element ref="subtitle"/>
            <xs:element ref="summary"/>
            <xs:element name="enclosure" type="enclosureType"/>
            <xs:element ref="guid"/>
            <xs:element ref="pubDate"/>
            <xs:element ref="duration"/>
        </xs:sequence>
    </xs:complexType>
    <xs:element name="language">
        <xs:simpleType>
            <xs:restriction base="xs:string">
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
    <xs:element name="link">
        <xs:simpleType>
            <xs:restriction base="xs:anyURI">
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
    <xs:element name="pubDate">
        <xs:simpleType>
            <xs:restriction base="xs:string">
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
    <xs:element name="duration">
        <xs:simpleType>
            <xs:restriction base="xs:string">
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
    <xs:element name="rss">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="channel" type="channelType"/>
            </xs:sequence>
            <xs:attribute name="version" use="required">
                <xs:simpleType>
                    <xs:restriction base="xs:decimal">
                        <xs:enumeration value="2.0"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
        </xs:complexType>
    </xs:element>
    <xs:element name="title">
        <xs:simpleType>
            <xs:restriction base="xs:string">
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
    <xs:element name="url">
        <xs:simpleType>
            <xs:restriction base="xs:anyURI">
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
</xs:schema>

Then I created Java classes (ObjectFactory.java, Rss.java, ChannelType.java, ImageType.java, ItemType.java and EnclosureType.java) using xjc. Now we're ready to output iTunes compatible podcast feed.

I had closed MyTunes before I moved to Melbourne in 2008. In less than 2 years, MyTunes collected several hundreds of user agent (it only collects user agent, nothing else). I think it'll be a good idea to publish them one day.

Monday, November 16, 2009

Message Digest algorithms in Java Cryptography Architecture

This is the 2nd part of Message Digest algorithms test. I tested MD5, SHA-1, SHA-256, SHA-384 and SHA-512 in Java Cryptography Architecture (JCA) of Java SE6 against the same file as in 1st part.


Alg. Name
Real Time
User Time
System Time
MD5
0m15.004s
0m9.109s
0m1.344s
SHA-1
0m38.654s
0m35.318s
0m2.036s
SHA-256
0m59.053s
0m56.032s
0m1.784s
SHA-384
1m56.362s
1m53.663s
0m1.364s
SHA-512
1m58.385s
1m53.727s
0m1.484s

The results are quite interesting if compared with the results of md5sum, sha1sum, sha224sum, sha256sum, sha384sum and sha512sum in Ubuntu in 1st part. Basically
  • MD5 is comparable in terms of time but with a higher percentage of CPU usage (2X);
  • SHA-1 and SHA-256 are much slower (2X);
  • SHA-384 and SHA-512 are a bit faster than native implementations.