Trivial ThoughtsThoughts and discussion on programming projects using the Python language.Rule for Refactoring Code- May 16, 2004 Rule for Refactoring Code These are the rules I've developed over the years that I follow when refactoring code. They're rules in the sense that I always regret it if I fail to follow them for any reason. Unit Testing: Don't Even Start Without It. You won't know your refactoring didn't break the code unless you have unit test coverage of the affected code. If you don't have that coverage already, add new tests. Keep Each Refactoring Narrowly-Focused. Don't combine..http://radio.weblogs.com/0124960/2004/05/16.html#a29 Sun-Relative Time Events Using Python- May 13, 2004 Sun-Relative Time Events Using Python For my current X10 home automation project, I want the ability to schedule events to occur at sun-relative times like 'sunrise' and 'sunset'. Now, you can do that by using an X10 light sensor and watching for the 'on' and 'off' commands it will send. But will the sensor be triggered by stray light, like from a passing car's headlights I don't know. Perhaps with careful placement of the sensor, you could avoid accidental...http://radio.weblogs.com/0124960/2004/05/13.html#a28 Python and X10 Home Automation, Part 1.1- May 10, 2004 Python and X10 Home Automation, Part 1.1 I wrote previously about Project WiSH, which gives you access to X10 computer interface controllers via device drivers. I also wrote about uprading my home system to Mandrake 10. Mandrake 10 has the new 2.6 kernel. Sadly, WiSH does not (yet) work with that kernel. So, I had to find an alternative. From googling around, and comments from readers, I found the 'bottlerocket' software, for accessing the CM-17a 'Firecracker' X10...http://radio.weblogs.com/0124960/2004/05/10.html#a27 Upgrading to Mandrake 10- May 8, 2004 Upgrading to Mandrake 10 Last night I decided to upgrade my home Linux box, which was running Mandrake 9.2, to the newly-released Mandrake 10. I run Mandrake at home, and until recently, on my work machine, too. Now at work I run Red Hat 9, but only because we use ClearCase (don't get me started) as our version control software, and it patches into the kernel, and only supports Red Hat. So I was forced (kicking and screaming) to switch to Red Hat at work. Now, this is just my...http://radio.weblogs.com/0124960/2004/05/08.html#a26 Handling CSV Strings, Redux- May 6, 2004 Handling CSV Strings, Redux I've written several times about the Python csv module and its limited API. I presented an adaptor class for use when you want to parse a CSV string, without being locked into reading sequentially from a file. Here's another way of doing it, using Python's standard 'I have a string, but I need a file-like object' adapter, the StringIO module.import StringIO Or use cStringIO, it's fasterimport csv First, create the StringIO object,..http://radio.weblogs.com/0124960/2004/05/05.html#a25 Python and X10 Home Automation, Part 1- May 5, 2004 Python and X10 Home Automation, Part 1 I recently saw an ad from x10.com for a free (you pay shipping) X10 starter kit, including a 'Firecracker' computer interface. That was a deal I couldn't pass up, so I ordered it through their web site, and 3 days later, the kit arrived. The kit consists of the CM-17a 'Firecracker' serial computer interface, which transmits via radio, a transceiver module which receives the radio commands from the Firecracker and retransmits them via the X10 protocol.http://radio.weblogs.com/0124960/2004/05/05.html#a24 |