Tuesday, July 27, 2010

Plotting complex polynomials with octave and octaviz (vtk)

I got to wondering what happens when you feed complex numbers into polynomials, so I poked around and found the awesome vtk library binding for the octave language, called octaviz.  (octave is a free implementation of the MATLAB language).

When we plot z = f(x), where x and z are complex numbers, we get 4 dimensions to plot, so I shifted each point in the surface plot N units + or - in the Y direction, where N is the imaginary part of the output.  The color also indicates how far each point was stretched in the + or - Y direction. 


global a = 1
global b = 0
global c = 0

function z = polynomial (i,j)
  global a
  global b
  global c
  x = i + (j * 1j);
  z = a*x*x + b*x + c;

[I,J] = meshgrid(-1:0.2:1);
REAL = arrayfun(@real, arrayfun(@polynomial, I, J));
IMAG = arrayfun(@imag, arrayfun(@polynomial, I, J));
vtk_surf(I,J+IMAG,REAL, IMAG);

input ("Orient it the way you want it before I save.");
vtk_print('polynomial.jpg', '-djpeg');
input ("Done!");

Wednesday, July 21, 2010


The stoics teach that we should not complain of life--the door of the prison is open.
-august 25, 1983

Thursday, July 15, 2010

Things I hate: externalized costs in programming

Bob adds a feature to handle a situation that someday might arise. Alice then discovers a production failure caused by that feature. Good luck removing the feature: doing that might cause a production failure someday!

python-tk: tkinter photo doesn't work inside a function

Wow, python-tk sucks. When I create the photo inside a function, it gets garbage-collected because it's not smart enough to know that the label is using it. So I have to manually keep it from being deallocated (in this case, by making it global). Also, I'd really like to use after_idle instead of after, but it never gets around to actually updating the display.


import Tkinter
import ImageTk,Image

root = Tkinter.Tk()

old_label = None
label = None
photo = None
def display_image(root, image):
global old_label
global label
global photo

root.geometry('%dx%d' % (image.size[0], image.size[1]))

photo = ImageTk.PhotoImage(image)

label = Tkinter.Label(root, image=photo)

if old_label is not None:

old_label = label

def image_loop():
global root
print '.'
image = get_image()
display_image(root, image)



python plumbing: PIL Image from data string

Today I wanted to use netcat (nc) to send a JPEG image file over a network to a python script so that I can manipulate it with PIL, the python imaging library.

PIL has fromstring and frombuffer methods, but I couldn't get them to work. But I found the ImageFile module, which let me feed the data in as it came off the socket.

To serve up the images, I did this from the shell:

while true ; do nc -q 0 -l -p 12345 < foo.jpg ; done

Then this python script received and displayed an image:


import socket
from PIL import ImageFile

tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcp.connect(('', 12345))
tcp.send("1000 4")

file = open("bar.jpg", "w")
parser = ImageFile.Parser()

while 1:
jpgdata = tcp.recv(65536)
if not jpgdata:


image = parser.close()

Saturday, July 10, 2010

Xorg window redraw: workaround by forcing update

When using Sketchup in wine on my ubuntu linux machine, I find that it doesn't update the screen properly. For instance, if I hit control-A to select everything, I don't see the selection until I do something else. That is, the screen seems to be one update behind.

Here's a workaround that works with Sketchup: in a separate terminal, I run:

$ watch -n 0.3 xrefresh -geometry 1x1+500+500

That uses xrefresh to create a 1x1 pixel x11 window at 500,500 on the screen every 0.3 seconds. That's enough to get sketchup to redraw itself.

If that's not enough, you can run xrefresh without the -geometry option to have it draw a window the size of the entire screen. But that's a lot more distracting.

Thursday, July 08, 2010

libgphoto2 / gphoto2 build from svn and install locally

Today I wanted to make a patch against gphoto2 (the command-line interface to libgphoto2) without overwriting the version installed by ubuntu.

So I needed to download libgphoto2 and gphoto2 from subversion and then install it to a local directory.

$ sudo apt-get install automake autoconf libtool gettext pkg-config subversion build-essential
$ mkdir gphoto-svn
$ cd gphoto-svn
$ svn checkout https://gphoto.svn.sourceforge.net/svnroot/gphoto/trunk/libgphoto2
$ cd libgphoto2
$ autoreconf -is
$ mkdir -p /tmp/gphoto2/local
$ ./configure --prefix=/tmp/gphoto2/local
$ make
$ make install
$ # neat, libgphoto2 installed to /tmp/gphoto2/local
$ cd ..
$ svn checkout https://gphoto.svn.sourceforge.net/svnroot/gphoto/trunk/gphoto2
$ cd gphoto2
$ autoreconf -is
$ ./configure --prefix=/tmp/gphoto2/local --with-libgphoto2=/tmp/gphoto2/local
$ make
$ # make install is optional; I just ran ./gphoto2/gphoto2 directly
$ # edited files, then "make" to rebuild

Earth Source / pals4wood sucks

American business is doomed. I needed to buy several thousand dollars worth of plywood. My friend recommended "PALS", a local distributor. Great, let's go to their website.

Hm, no price list online. That sucks. I guess I'll email them a list of what I need. Hm, the email bounced: mailbox full. Let's try one of the other sales reps, and mention the bounce so they can fix it. Nope, that one also bounces. Okaaayyy, well at least one of them has a @yahoo.com address listed. That's pretty sketchy, but maybe they just can't seem to get their mail service right.

Weeks go by, no answer. Thanks, guys. Something that I was ready to take care of weeks ago, credit card in hand, has been on my mind ever since, while I wait to see if you'll ever get around to answering.

I give up and order from their competitor. They don't have prices online either, so I get to go back and forth with their sales guy about what I want and what they have over the course of a week or so. And I finally give up on PALS, call in to the competitor, wait for him to pull up the email, give him my credit card info, and place the order.

Now, out of some perverse sense of business ethics, I decide to try one last time to reach PALS and let them know how broken their website is.

Searching again for "pals plywood", the first result is for "earth source forest products", whose website makes no mention of PALS. Maybe everything's fixed now?

I send them an email to info@pals4wood, the email address listed on the new website. That message bounces back (mailbox full) too, but also sends me an autoresponse... telling me to call them. Seriously, guys?

Okay, sure, why not? I'm already in it this far. I call the toll-free number listed in the email. Rings forever. Whee! Let's try the Oakland branch. Ah ha, somebody answers! Oops, wrong number.

That's right, the company with two websites, both of which list numerous email addresses, all broken, lists the wrong phone number to call when you email their info address. FML.

Wednesday, July 07, 2010


The Secret Miracle

The date was set for March 29, at 9:00 A.M. That delay ... was caused by the administrative desire to work impersonally and deliberately, as vegetables do, or planets.


The Aleph

I do, however, recall these lines from a satire in which he lashed out vehemently against bad poets:

This one fits the poem with a coat of mail
Of erudition; that one, with gala pomps and circumstance.
Both flail their absurd pennons to no avail,
Neglecting, poor wretches, the factor sublime -- its LOVELINESS!

It was only out of concern that he might create an army of implacable and powerful enemies, he told me, that he did not fearlessly publish the poem.


The Aleph (1949)

"I picture him," he said with an animation that was rather unaccountable, "in his study, as though in the watchtower of a great city, surrounded by telephones, telegraphs, phonographs, the latest in radio-telephone and motion-picture and magic-lantern equipment, and glossaries and calendars and timetables and bulletins..."

He observed that for a man so equipped, the act of traveling was supererogatory; this twentieth century of ours had upended the fable Muhammad and the mountain -- mountains nowadays did in fact come to the modern Muhammad.

Saturday, July 03, 2010

ubuntu hardy firefox 3.6.6 freezes

After today's apt-get dist-upgrade on my hardy (ubuntu 8.04) machine, firefox would freeze almost immediately and had to be killed.

Turns out there are two copies of libflashplayer.so that can get installed, one by the flashplugin-nonfree package, and one by the adobe-flashplayer .deb package that adobe distributes.

sudo apt-get remove flashplugin-nonfree and then a reinstall of the install_flash_player_10_linux.deb from adobe fixes the freeze, and also upgraded me from flash9 to flash10.

Friday, July 02, 2010

conservation of responsibility

Job descriptions usually specify that they want people with good teamwork skills. That can be good, but often it means sending out lots of emails asking other people for opinions.

In my last blog post I claimed that capacity for responsibility is a scarce resource.

So lately I've been trying to reduce the number of interrupts and decisions required for decisions that come along.


me: I'm in town. Want to have lunch?
Robert: sure!
me: [checks calendar] How about Thursday or Friday?
Robert: [checks calendar] Great, let's do Friday.
me: [checks calendar] 1pm sound okay?
Robert: sure
me: [adds it to our calendars]

Totals: 7 messages, 5 decisions, 4 uses of calendar. And that's just to *schedule* it. Without even talking about where to meet. Both of us still have to check our calendars on Friday and meet at the right time.

That could have been reduced to:
me: [adds lunch to our calendars with "hey, I'm in town" to the description]

Each time someone contacts us, we get a little anticipatory shot of stress as we get ready to read it and find out whether it's good, bad or boring. Reducing that can free up a lot of responsibility for more important tasks.

code.google.com bugs

Trying to report a bug in code.google.com project hosting, I couldn't find anything by searching for "code.google.com bugs", "google code bugs", "code.google.com issues", etc. Turns out the bug tracker is under the "support" project. (Link goes to the issues page).

Maybe this will make it more findable.

Responsibility as a bottleneck

I'm lucky enough to work at a company that tries give me all the resources I need to get my job done. Yet I've felt overwhelmed a lot lately, even, no especially when I find myself goofing off a lot. And it's because I've exceeded my capacity for responsibility.

I got the idea from hyperbole and a half, and it explains a lot of phenomena in our society.

Let's say I decide to take a for-fun class a the local college. And it's time to go to class now.

Oh wait, the car is parked at another building. And it's low on gas; should I fill up before I go? And my books are at home. Do without them?

You now have 4 things to do or decisions to make, all before class starts. Classes have about 16 - 48 class sessions. If going to class each time involves 4 little tasks, that's up to 200 little obstacles you'll have to handle, just to get to all the classes. Then there's registration, books, tests, and assignments. No wonder people don't take more classes on their own.

Calendars help, but how do you schedule keeping the gas tank full? Or remembering where you parked?

Here's the point: there's a limit to the number of things I can keep track of, and the number of decisions I can make in a day. And that holds me back more than my capacity to do the "actual" labor required to execute those decisions.

I don't surf the internet like a zombie for hours because the internet is so interesting or addicting. It's because it's stateless. I don't have to remember what I see, or take action on it in three days' time, or have it cascade into dozens of other pressing tasks.

Thursday, July 01, 2010

"Unknown end tag for </a>" error on code.google.com wiki page

See http://code.google.com/p/support/issues/detail?id=4171. I was trying to link to an image, and it apparently wants a closing <img> before it can handle the </a>