Tim\'s picture      Blogging Ottinger (tim)

2008-April-18

Building Lists the Hard Way in Python

Filed under: Programming, Life

Just for the record, these are dumb:

#  Example A: reading
file = open(somefile)
contents = []
for line in file:
   contents.append(line)
	
# Example B: writing
file = open(somefile, \"w\")
for line in contents:
     file.writeline(line)
	
# Example C: filtering
result = []
for line in contents:
     if not line.find(\"boo\"):
        result.append(line)
	
Python is easy. That means you should just about always be able to get the same results with a lot less effort. Python is not Java.

# Example A: reading
contents = open(somefile).readlines()
	
# Example B: writing
open(somefile,\"w\").writelines(contents)
	
# Example C: filtering
result  = [ line for line in contents if not line.find(\"boo\") ]
	
# Example D: In case you miss confusing, obfuscated, ugly code since you started using python
open(somefile,\"w\").writelines( [ line for line in open(otherfile) if not line.find(\"boo\") ])

By the way, example D is also stupid. Nobody should write code like that. Python is not Perl.

The Year of Living Biblically

Filed under: Reading

I’ve started on A.J. Jacobs’ masterpiece The Year of Living Biblically today. I already raced through the introduction and part of September (his first month of transition) over some hamburger concoction at Red Robin (and no refills on fries; though I had two refills of iced tea).

The basic idea is that he has decided to immerse completely in the laws of the old and new testament. He wears the fringes on his clothes, grows a beard, tithes, eliminates wool/flax blends from his wardrobe, eats a Levitical diet, vows to stop coveting other people’s belongings, and more. He seeks guidance from the Bible (a great many translations) and from various guides including ministers, rabbis, and most recently an Amish man named Amos. He is contemplating how to apply biblical guidance to raising his son. This is great stuff.

I’m already hooked. If this is the tone at the start, I can’t wait until things start getting a little odd and crazy. I appreciate Jacobs’ wit and humanity. He is a fine writer and strikes a chord easily. He is journeying from unbelief and agnosticism and ignorance into… well, it’s hard to say what when I’m only 1/24th of the way through his journey. But wherever he’s going, I’m riding along.

2008-April-17

English and the Letter E

Filed under: Angst

Reddit let me to a strange web site for some cracking/hacking/naughtiness (I think. I wasn’t interested enough to read it). What I did see is a sentence on one page that said:

Does the underground still breath?

My, how the letter E changes things. Does the author ask if the underground is still alive(”does the underground still breathe?”) or if it will kill you (does the underground still breath)? Should those who don’t want their breathing stilled stay away?

After that, I just wandered off disinterested. The site doesn’t fit in with my life program of cultivating innocence.

2008-April-15

Today’s Top Ten Command Line Tools

Filed under: Linux, Programming

This is all the rage lately, so I’m doing it too:

[0]tottinge@clicky:~$ history|awk '{a[$2]++} END{for(i in a){printf \"%5d\t%s\n\",a[i],i}}'|sort -rn|head
  119   sudo
   53   ls
   34   hpodder
   30   cd
   19   vi
   18   ping
   16   exit
   13   df
   12   apt-cache
   10   ./savepower.sh

Sudo is almost always for “sudo ifdown ath0; sudo ifup ath0=ath0-whatever”. I am mobile, and often switching wireless networks between home, airports, panera bread, church, taco john, goldentree at hotels, and other people’s offices.

savepower.sh is a script I made to put my laptop in low-power mode. I mostly took the advice from my copy of powertop. It seems to extend my laptop battery quite a bit, and it looks something like this:

#!/bin/bash  -x
SERVERS_TO_STOP=\"cupsys mysql bluetooth apache2 bittorrent mono-xsp tomcat5\"
for server in ${SERVERS_TO_STOP}
do
    sudo invoke-rc.d ${server} stop
done
sudo bash -c \"echo 5 > /proc/sys/vm/laptop_mode\"
sudo bash -c \"echo 1 > /sys/module/snd_ac97_codec/parameters/power_save\"
sudo bash -c \"echo 1500 > /proc/sys/vm/dirty_writeback_centisecs\"
sudo bash -c \"echo disabled >  /proc/acpi/ibm/bluetooth\"

Starting In Python

Filed under: Programming

Some of my friends and relatives are getting a start in python. Some are just curious about programming in general, some are interested especially in testing with Twill or the like. I have a few recommendations for the beginner.

The first is to go to the python home page. This is really Python Central. You will want to download the appropriate version for your machine (see the download button in the left navigation bar?) and then dig into the documentation section.

There is a guide for beginners. It is certainly worth traversing. It includes sections for programmers and for non-programmers. This might be the python noob’s best friend.

The tutorial is actually very good, but may not be for everybody. It can sometimes dive a little deep for a page or two, then be too simple on the next. You may have to skip over some sections and come back to them later. For instance, there is mention of unicode magic early in section 2, and you don’t really need it until later. I think that this tutorial has been receiving updates as enhancements are added, and they’re not always carefully merged into the learning stream. It is still rewarding to the patient.

For python game programming, I’m told that pygame is the thing to use.

If you are interested in web programming, right now the hotness is called Django though there are other web frameworks available, many of which are quite popular.

Remember to find and read python code, since deciphering code is a good way to learn how to write it. Just remember that not all programmers place the same value on simplicity. Once you are wrapped up trying to read code that’s confusing and ugly, don’t feel bad if you need to put it down and seek another example.

Finally, consider the great number of “how to” articles at The Python Cookbook which is part of a book by the same name. You’ll find it handy though the solutions may require you to dig a bit now and then.

Enjoy your new pet python.

2008-April-8

Weinermobile Sighting

Filed under: Fun

You see the strangest things in hotel parking lots. Here is a bit of Americana oddity:
Oscar Meyer Wienermobile
Today there were two of them. I took the picture with my phone, which is a poor camera, but there it is.

By the way, George Sparks sent me a spelling correction and a link to the wienermobile’s Wikipedia entry.

2008-April-4

Agile AD2800 P90-Equipped Beauty

Filed under: Guitars

The Agile AD-2800 in Black Cherry with P90 pickups:

Agile AD2800 Black Cherry with P90 pickups
detail of AD-2800 Guitar from Rondo

Image Details
As usual, the picture of the whole guitar (on the left) is also a link.

This is the prettiest low-cost P90 guitar I’ve seen, and I’ve only seen the pictures. I may have to make this my next Christmas present (planning ahead). I’m pretty much sold on the idea that I want the raunchy sound of a P90, and I want it to be affordable-yet-attractive. Ron’s done me well before.

Is this a gorgeous guitar or what? The PRS-like double-cut is practical as well as stylish, and there is a bevel to help you get up to the really high notes. I also think I might like the LP-style switch on the upper bout. I don’t know, though. It’s further out of reach of my hands. The headstock is a bit more stylish too. I like the black hardware and that it has separate tone and volume for each pickup (I’ll never buy two-knob guitars again).

I like the white/cream binding in particular. Before I got my GG5 CUS (black hollowbody) I never realized how much visual impact comes from the binding. Stepping out with either of these makes a good first impression (which I then have to maintain… maybe I should stick with ugly guitars?).

Black pickup covers are definitely my preference. I hate the white covers I keep seeing, like the ones on the Les Paul Gold Top guitars. The black blends in and lets the styling of the body and hardware stand out better. It doesn’t clash.



2008-April-3

Twill Testing

Filed under: Programming

I had a very simple first brush with twill, in which I drove Google around a little bit. I was successful, and even delighted. It’s a nice language and an even better python library. As a next step, I got some friends around to play with testing a real application.

For some reason, when we try to do a submit(), we get an exception due to POST encoding.

I was totally baffled, and hence this post. I’m looking for any input as to what is wrong, and will pursue it. If I find the answer it will definitely be appended to the text of this post.

It’s really a shame, because the framework is so simple and clean already.


– Problem resolved. Can you spot the noob in in this picture?tim
> On Thu, Apr 03, 2008 at 01:26:03PM -0500, Tim Ottinger wrote:
> -> I just started playing with Twill, and I think it’s pretty cool.
> ->[…] got a baffling
> -> exception on ’submit()’ . The exception is:
> -> ValueError: unknown POST form encoding type ‘’
Titus Brown wrote:
> Huh, never seen that one. What’s the enctype on the form?

Ummm….
* blushes deeply*
* files bug report on site owner’s website *
tks

Crazy Week

Filed under: Life

It’s a crazy week. I flew out Sunday, after some flight delays due to weather.

I had a minor delay getting a rental car, and then an interruption getting into my room at the hotel. Normally I wouldn’t have minded, but somewhere near the end of the flight I started getting ill. But when I checked into my room around midnight I had what appears to be a case of food poisoning. I needed a place of private suffering, so every small delay was stressing me out. I know that by 2:00am I was so sick I didn’t know which way to turn. I pitied my neighbors for their poor nights sleep. Monday was spent not working. I made peace with drinking water by noon, was eating a sandwich by 6:00p, and managed to sleep Monday night.

Tuesday work was really was great. I am visiting a really great team and learning as much as I’m teaching. There is much good afoot here. On the other hand, my sleep cycle is shot. I got maybe three and a half hours sleep.

Now I find that I’ve picked up some kind of sinus thing. The more athletic parts of Sunday night have left my sternum in a pretty painful and tender state. Sneezing and coughing aren’t fun with the sternum thing, but I feel so tremendously better than I did Monday, it’s almost heaven. I’ll have the sleep thing squared away and all will be normal or better. I’m happy these are all little things, and short-lived.

Last week’s spring break with my kids and wife was great, even though I joked about it with my Des Moines sign photo. It was so nice being all together, spending time and having fun. I even got some swimming in … or at least I got to wrestle and play in the water. I am really happy that I didn’t come down with any of this earlier. I am really grateful for the timing. I’d rather be sore and tired this week than last.

Short form, though: I’m fine, how are you?

Get free blog up and running in minutes with Blogsome | Theme designs available here