Posts

Python: Unicode

Python has very good support for unicode, but half the time it's gets in the way. Java, by default, uses the Latin1 encoding (aka ISO-8859-1) which makes programming in languages like Portuguese very easy. Python's default, unfortunately, is 7 bit ASCII. If you use any accents you have to properly decode it for it to work without an error. A quick work around is to create a file called sitecustomize.py in your python lib directory and put in the following: import sys sys.setdefaultencoding('latin1') This definitely makes coding with European accents a lot easier. Here's a good article on unicode and python. I've read that some people have had problems with sitecustomize and third party modules, but I believe that's only if you set it to utf8. The other thing you need to do is put: # -*- coding: latin1 -*- near the top of your python program. Neil Hodgson recomends testing your libraries with the -U switch for Python and by trying sys.setdefaultenco...

Tools: Matplotlib for Python

Image
When it comes to doing graphs, Matplotlib is the one to use. It's an open source library that does a wonderful job of creating graphs. As you can see above it also does a good job with anti-aliasing the lines (this is zoomed in from a black and white graph I did for my wife). The site has a lot more samples which show the features of the library. I was able to create a figure with six graphs in about 10 minutes, without ever having used the library before (just copied from the examples). To get all the little text elements and adjustments took a bit longer, but it is still impressive how quickly you can get going. In a few lines you can output the graph to the screen using either Tkinker, wxPython, or GTK and have it interactive as well (zoomin, etc.). You can also output to PNG, JPG, SVG, PS and other output formats. The anti-aliasing is done so well because Matplotlib uses the Anti-Grain Geometry library which can do sub-pixel anti-aliasing of lines ( check it out ). Mat...

UI: iRiver

I've finally seen the iPod. The UI is very nice on the iPod, the thumb wheel is brilliant. The buttons on my iRiver H340 are quaint, in retrospect. I wish that iRiver put PageUp, PageDown buttons on their interface, when scrolling through hundreds of directories the +/- buttons are too slow. The Dot and A-B buttons on the right could be overloaded to be PageUp and PageDown, since they aren't used in that mode. Another complaint I have is that when you press the dot button goes between the different playing modes which have names like "D", "A", "SFL DA". Why don't the put near the bottom a long description of the playing mode, for a second or two? So that SFL DA becomes, "Shuffle, Directory All". Which brings me to another complaint, I don't see any difference between "SFL DA", and "SFL D". I was hoping that one would shuffle between all the files in the current directory and below , yeash.

Tools: Frink calculator

I highly recommend using Frink instead of, say, windows Calc. It's a free, but not open source, Java program. It's command line driven but very powerful. I especially like the built in conversion capabilities and translation features. Here's the feature list: Tracks units of measure (feet, meters, tons, dollars, watts, etc.) through all calculations and allows you to add, subtract, multiply, and divide them effortlessly, and makes sure the answer comes out correct, even if you mix units like gallons and liters. Arbitrary-precision math , including huge integers and floating-point numbers, rational numbers (that is, fractions like 1/3 are kept without loss of precision,) and complex numbers. Advanced mathematical functions including trigonometric functions (even for complex numbers,) factoring and primality testing , and base conversions . Unit Conversion between thousands of unit types with a huge built-in data file . Date/time math (add off...

iRiver: First Thoughts

So I got for Christmas the iRiver 340 music jukebox (40 gig version). I chose it over the iPod because: It's cheaper - US$386.00 instead of $500.00. I can make Podcasts on it (i.e. I can record things at high quality) The battery is better than the iPod. It supports Ogg Vorbis audio compression. Has a radio (but I don't see myself using it very much). You don't need to use iTunes to copy your files. It mounts as a drive on Windows, and thus you can copy pretty much anything to it. My guess is that the iPod has a nicer interface, but I wouldn't know, since I've never used one. I've been using my favorite synchronizing program, Unison , to update my iRiver. I'm using about 20 gig of disk space so far. What I didn't like is that the US version of the iRiver: doesn't come with a cradle (a $25.00 addon), the carrying case completely covers the buttons and the display (a proper carrying case is a $30.00 addon), so anyt...

Security: Off-the-Record Messaging

These guys created a method of sending IM messages which provides a method of chatting in such a way that you know who you are talking to is who you think it is (authentication), but soon after the message has been sent it can't be read anymore - the key expires and isn't saved. An interesting point in the paper is that even when you use an cryptographic system, if the FBI takes you machine there's a good chance that they can get your messages and prove that you sent that message. If you did something incriminating this is the opposite of what you want. As far as I understand the system, the messages are ephemeral and are unreadable after a short time (even by you). Yet at the same time there are some guarantees that the person you are chatting with is who you think it is rather than an imposter trying to get information from you. I suppose the downside of the protocol is that you don't have a history of your messages which can be handy. via slashdot .

Python: Static vs. Dynamic

Ian Bickin's article discussed some other articles : [...] one way to decrease bugs is testing, but another way is to decrease the amount of code. Code deleted is code debugged. Static typing can decrease the number of bugs, but decreasing the amount of code is a much, much more effective way to decrease bugs. ... Static type defenders complain about the combinatorial type interactions in dynamically typed languages -- how can you test all the code paths, given all the possible types? But their languages lead to combinatorial code , which is far worse: for many classes of hard problems, they can't solve them once, they have to solve them everytime they are encountered. Ouch. Python is both dynamically typed (like VBasic and strongly typed (like Java) , the best of both worlds.