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 29, 2010
Saturday, January 16, 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?
Update on 27/12/2020, Python 2.7 fixed it as well.
$ python
Python 2.7.18rc1 (default, Apr 7 2020, 12:05:55)
[GCC 9.3.0] 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
Saturday, January 09, 2010
Let scim and ibus support Skype
Update 28/4/2012 - If you're using Ubuntu 12.04 Precise Pangolin, install ibus-qt4 first.
sudo apt-get install ibus-qt4
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:
If you prefer scim, maybe these lines will help (not tested):
Skype is better now under Ubuntu.
sudo apt-get install ibus-qt4
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.
Monday, January 04, 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.
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.
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.
Subscribe to:
Posts (Atom)