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.
Monday, August 25, 2008
Thursday, August 21, 2008
Python Unicode exception
While using Python I encounter one common exception:
Traceback (most recent call last):
File "./unicode-test.py", line 564, in ?
main()
File "./unicode-test.py", 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')
optionaly:
# 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:
Source: Python doc
Traceback (most recent call last):
File "./unicode-test.py", line 564, in ?
main()
File "./unicode-test.py", 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')
optionaly:
# 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.
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.
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:
http://www.somebits.com/weblog/tech/python/xpath.html
It is possible to convert DOM to dictionary records with following functions:
http://code.activestate.com/recipes/116539/
or use module xml2dict:
http://code.google.com/p/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:
http://www.novell.com/coolsolutions/feature/11251.html
Czech trafic navigator:
http://www.dopravniinfo.cz/default.aspx
Python date and time manipulation:
http://seehuhn.de/pages/pdate
http://www.somebits.com/weblog/tech/python/xpath.html
It is possible to convert DOM to dictionary records with following functions:
http://code.activestate.com/recipes/116539/
or use module xml2dict:
http://code.google.com/p/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:
http://www.novell.com/coolsolutions/feature/11251.html
Czech trafic navigator:
http://www.dopravniinfo.cz/default.aspx
Python date and time manipulation:
http://seehuhn.de/pages/pdate
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.
Mount:
sudo mount -t cifs //netbiosname/sharename /media/sharename
Options:
-o \
username=winusername, \
password=winpassword, \
iocharset=utf8, \
file_mode=0777, \
dir_mode=0777 \
Or:
guest, \
rw
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.
Mount:
sudo mount -t cifs //netbiosname/sharename /media/sharename
Options:
-o \
username=winusername, \
password=winpassword, \
iocharset=utf8, \
file_mode=0777, \
dir_mode=0777 \
Or:
guest, \
rw
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 http://ftp.us.debian.org/debian 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.
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 http://ftp.us.debian.org/debian 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.
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.
Subscribe to:
Posts (Atom)