Monday, August 25, 2008

Melodies On The Street

Last weekend I visited my home town Pilsen. I was terribly tired but I felt lucky to spend some time with my friends. I arranged meeting with my school mates. There were too many events and so little time, therefore I have met just some of them. Even though I spent a nice time.

One of my friends decided to be programmer and to reach really big salary. If he is allready decided then I don't want to argue to him about that idea. I will help him on his way.

Thursday, August 21, 2008

Python Unicode exception

While using Python I encounter one common exception:

Traceback (most recent call last):

File "./", line 564, in ?
File "./", line 553, in main
print "Value: %s" % unicodeString
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 87: ordinal not in range(128)

The reason is that we want to print Unicode object but it cannot be converted to appropriate characters automaticaly. Solution is easy, we have to convert the object before printing it:

print ("Value: %s" % unicodeString).encode('utf-8')

# visible char
print ("Value: %s" % unicodeString).encode('ascii', 'replace')
# zero char
print ("Value: %s" % unicodeString).encode('ascii', 'ignore')
# exception (default)
print ("Value: %s" % unicodeString).encode('ascii', 'strict')

Additional reading: source

Note: We have to convert the whole object after joining ascii with unicode. Otherwise Python would join the ascii part and utf8 part and convert the result to Unicode and the error appears again.

You can use unicodedata to normalize string:
import unicodedata
unicodedata.normalize('NFKD', 'p\xc5\x99\xc3\xadli\xc5\xa1 \xc5\xbelu\xc5\xa5ou\xc4\x8dk\xc3\xbd k\xc5\xaf\xc5\x88'.decode('utf-8')).encode('utf-8')

Source: Python doc

Tuesday, August 19, 2008

Non-traditional English lesson

Well, today I spent nice English lesson. Some students go with their teacher to the nature or sit in a caffee or pub. Today was nice weather so we got into nice restaurant and started talking.

For me was absolutely unusual leaving the work before the 4pm so I was looking around enjoying the city rush and sun. We returned aproximately at noon and decided to repeat the meeting again in another restaurant. Additionaly we combined our lesson with lunch so I saved almost one whole hour just by attending my favourite English lesson.

Friday, August 15, 2008

Bits and pieces

Great Greek dances...

I am looking forward for this weekend. I will attend lesson of Greek dances with my friend. We tried this kind of dance just once before and we liked it.

Yesterday I had talk with one of the Czech Square dance choreographers (yes, caller) about our further teaching lessons of another dance level - C3A. Just a few people in Czech republic know this level, we even do not have whole square group and we meet irregularly. His idea was to teach other dancers this level to enforce our dancers base.

Attended Greek dances
...It was fine. In the village nearby Prague, along the Vltava bank. The weekend was raining so it was good time for dance.

Mixed notes

Python lacks good XML support in standard distribution. I found a list of Python XML libraries comparison:

It is possible to convert DOM to dictionary records with following functions:

or use module xml2dict:

Sometimes I do ssh to some development machine which I am not quite familiar with. I usualy want to detect Linux distribution and version. The following description is very helpful:

Czech trafic navigator:

Python date and time manipulation:

Thursday, August 14, 2008

Dancing in Samba rhythm

Sometimes I want to use Samba as fast as possible. Unfortunately there may occur unexpected problems during user authentication. Following sequence of commands solves many of them:

smbpasswd user_name
pdbedit -a user_name

In other words, adding user and setting up password may not have been enough, we need to add him/her to user database.

sudo mount -t cifs //netbiosname/sharename /media/sharename

-o \
username=winusername, \
password=winpassword, \
iocharset=utf8, \
file_mode=0777, \
dir_mode=0777 \

guest, \

Monday, August 11, 2008

Debian X Fonts

How to install nice X fonts in Debian quick and easily?

In the root console exec command:
apt-get install msttcorefonts

If the following error occur:
E: Couldn't find package msttcorefonts

you should add "contrib" section to your /etc/apt/sources.list:
deb etch main contrib non-free

and then execute - as usually:
apt-get update

and do again:
apt-get install msttcorefonts

Then select these fonts as default.

If you use KDE open Control Center then select:
Appearance & Themes then Fonts. In the right dialog select default fonts for each font type.

Appropriate font names are: Times, Arial, Courier, Courier New, Courier 10 Pitch, Lucida Typewriter

Done. Note that font settings take effect after restart of each application. You also have to select fonts for specific applications such as Firefox, Thunderbird, Kwrite, etc.

Wednesday, August 06, 2008

Sailing on Vltava river

Yesterday was nice weather and sun was shining like other days. But instead of other days I did not have to stay in my office all the time. I just finished one important project and I was allowed to leave for a while so I enjoyed the day even more.

I went with my friend on the Vltava bank where we rent pedal-powered ship. Then we sailed around the Strelecky island. We enjoyed very nice view of Prague Castle and Vysehrad church which we saw from our ship.