Monthly Archives: February 2012

JDRF Ride to Cure Diabetes

Friends, I’m bicycling the 105-mile Ride to Cure Diabetes in Death Valley this October. It’s a fundraiser for JDRF to support diabetes research, therapies, and patient advocacy. Won’t you please help me meet my fund-raising goal?


Here I am testing my blood sugar on the bike. Help make this a thing of the past—the testing, not the cycling. :^)

Posted in Cycling, Diabetes | Leave a comment


Coworker: So, what are you doing? [Eying my copy of Steve's Digital Image Processing Using MATLAB book.]

Me: I thought it was about time for me to learn how filtering works.

Coworker: Everybody has to walk through that convolution and correlation forest at some point and come out the other side as a man.

Posted in Computing, Fodder for Techno-weenies, General, Life Lessons | Leave a comment

Opera, E-mail, and Documentary Shorts

I have three questions for y’all today, dear readers.

Opera Recommendations — Yesterday (before the Academy Awards love-fest) I watched the PBS “Great Performances” recording of the Met’s staging of Donizetti’s “Anna Bolena.” Wow, that was great!

Watch GP at the Met: Anna Bolena on PBS. See more from Great Performances.

(The New York Times has a a better excerpt. You know, one with music.)

My exposure to opera is (um) rather limited. I’ve listened to all of “La Traviata” and selections from some Mozart and Wagner operas, but that’s pretty much it. What I’ve heard, I like—and I’ve always meant to listen to more of it—but I’ve always been super-overwhelmed by the magnitude of the selection at the library.

Do you have any favorites that you might suggest?

E-mail to Actions — I won’t hide my skepticism about e-mail. Of course it has its good parts, but I struggle with converting the actions that are contained (hiding?) in all of those messages into items on my To Do list. How do you take all of the important parts of e-mail and turn them into easy-to-remember, actionable things?

Documentary Shorts — Lisa and I watched a few hours of Oscar-nominated short films Saturday night. There were a lot of good films there in both the animated and live-action categories. And you can find collections of both of them on iTunes. Yay! (See the previous links.)

But where can I find the documentary shorts? Anyone know?

Posted in General, Life Lessons | 1 Comment

Writing a File Reader in MATLAB

A colleague recently asked me to help him read a file in MATLAB, which supports reading a whole bunch of image and scientific data formats right out-of-the-box but not NRRD. This format stores 3D volumes of radiology data and (like FITS) contains a text header containing key-value pairs followed by a binary payload. Having written file parsers full-time for the better part of ten years, it didn’t take too long for me to create a .nrrd file reader for MATLAB.

I’m kind of proud of this little feature for its simplicity, and it shows a lot of the power of MATLAB. In fewer than 200 lines of well-structured code, I was able to implement a robust file reader. Here are a few features it uses that anyone creating their own file reader in MATLAB might also try to take advantage of:

assert — Stop writing if blocks that only exist to check whether everything is okay and error if it isn’t.

fid = fopen(filename, 'rb');
assert(fid > 0, 'Could not open file.');

And . . .

assert(isfield(meta, 'sizes') && ...
       isfield(meta, 'dimension') && ...
       isfield(meta, 'encoding') && ...
       isfield(meta, 'endian'), ...
       'Missing required metadata fields.')

onCleanup — Why worry about trying to remember to clean up resources? Let the onCleanup class take care of it for you. Construct one of these objects by giving it an anonymous function that closes your file handle when the object goes out of scope—whether from an error or at the end of the function.

cleaner = onCleanup(@() fclose(fid));

regexp — Use MATLAB’s regular expression engine to handle complicated text parsing for you.

theLine = fgetl(fid);

% "fieldname:= value" or "fieldname: value" or "fieldname:value"
parsedLine = regexp(theLine, ':=?\s*', 'split', 'once');

Dynamic structure field indexing — If you have a string that’s a legal MATLAB identifier, there’s no need to write complicated logic just to use it as a field name in a structure. Simply use the .(string) construct.

field = lower(parsedLine{1});
value = parsedLine{2};

field(isspace(field)) = '';  % Remove embedded spaces.
meta(1).(field) = value;

Using temporary files to decompress data — The NRRD format supports storing the image data as raw bytes, human readable text, or GZIP-compressed byte streams. When a file contains compressed or encapsulated data and MATLAB has a file reader capable of handling that, it’s easiest just to write the data to a temporary file and use the supported reader. Consider the readData() subfunction that recursively handles three different kinds of encoding:

function data = readData(fidIn, meta, datatype)

switch (meta.encoding)
 case {'raw'}

  data = fread(fidIn, inf, [datatype '=>' datatype]);

 case {'gzip', 'gz'}

  tmpBase = tempname();
  tmpFile = [tmpBase '.gz'];
  fidTmp = fopen(tmpFile, 'wb');
  assert(fidTmp > 3, 'Could not open temporary file for GZIP decompression')

  tmp = fread(fidIn, inf, 'uint8=>uint8');
  fwrite(fidTmp, tmp, 'uint8');


  fidTmp = fopen(tmpBase, 'rb');
  cleaner = onCleanup(@() fclose(fidTmp));

  meta.encoding = 'raw';
  data = readData(fidTmp, meta, datatype);

 case {'txt', 'text', 'ascii'}

  data = fscanf(fidIn, '%f');
  data = cast(data, datatype);

  assert(false, 'Unsupported encoding')

swapbytes — Like many formats, NRRD supports little-endian and big-endian byte ordering. The swapbytes function makes it dead simple to change endianness, and the computer function helps you determine whether swapping is necessary. Here’s the pattern, which uses the “endian” metadata value read from the .nrrd file:

function data = adjustEndian(data, meta)

[~,~,endian] = computer();

needToSwap = (isequal(endian, 'B') && ...
               isequal(lower(meta.endian), 'little')) || ...
             (isequal(endian, 'L') && ...
               isequal(lower(meta.endian), 'big'));

if (needToSwap)
    data = swapbytes(data);

Happy coding!

Posted in Computing, Fodder for Techno-weenies, MATLAB | 2 Comments

Catching Up

I — I finished off the bottle of sugar-free Robitussin DM yesterday. That must mean I’m well now, right?

II — Yesterday morning, I went for a long run around Milford, Hopkinton, and Holliston. The 12.5 miles were a bit slower than they might have been if I hadn’t been sick and/or injured for the better part of the last two months, but I don’t care. I’m looking forward to running Around the Bay in just under five weeks. I have goals for the race, but mostly I’m excited about just doing it.

III — Victoria invited me to join her on a JDRF Ride to Cure Diabetes. More details about the 100+ mile Death Valley bike ride in October and how you can help are on the way . . .

IV — The consensus at the bike store this afternoon is that twelve years is “a very full life” for an indoor trainer. I was surprised myself to realize that we’d had it that long, but I remember riding on it while watching the summer olympics in 2000. A couple weeks ago, forty-five minutes into a nice ride to nowhere, the riding got very difficult very quickly, and I could hear a horrible grinding sound. Fortunately, my awesome new bike was not the source of the sound. Unfortunately, the bearings in the trainer seem to have seized. Sadness. The upside is that now I have a new, very quiet trainer for the basement.

V — Lisa and I have been watching lots of films recently. I like “good” movies, so we made our way through eight of the nine Oscar-nominees for “Best Picture.” (You can’t make me watch “Incredibly Loud and Extremely Close” or whatever it’s called.) I’ve also watched a number of foreign films, popcorn movies, and documentaries. By the way, my three favorite nominated films of the year were “The Artist,” “The Descendants,” and “Midnight in Paris.” Lisa and I also both liked Miyazaki’s new Studio Ghibli film “The Secret World of Arrietty.”

VI — Saturday evening we went to the Providence cheese shop beloved by our friends. We bought a lovely Napfkäse, which is a delicious Swiss cheese somewhere in the neighborhood of Comté (my favorite cheese) and Gruyère, with grainy hints of Parmigiano-Reggiano. If you can get your hands on some, give it a try.

VII — It’s been almost a decade since I decided to stay in software engineering and not go to grad school, but I still miss history. Turns out, I can be a software engineer by day and read history at night. My current choice is Fred Anderson’s Crucible of War: The Seven Years’ War and the Face of Empire in British North America, 1754-1766. This book has been on my reading list forever, and I wish I had gotten around to it earlier. If all goes well, I’ll share details with you about this long war that destroyed France’s North American empire, seemed to bind American colonials more closely to the British empire and each other, and then ultimately set in place many of the precursors to the American Revolution. I’m having such a good time reading it.

VIII — I also signed up for one of the history listservs that were so popular a decade ago (academically speaking). It’s like a little bit of early American history enlivening my inbox everyday.

IX — I’ve been doing strength training at the office gym a couple times a week. While I don’t particularly enjoy it, I believe it will make me a better athlete. Strength training reminds me of this ad:

And this Oatmeal comic makes me laugh.

Posted in Cycling, General, History, Running, Video | Leave a comment

Real People Sick

The ironic thing about me having diabetes is that I’m really bad at being sick.

I come about it honestly. My father is a bit of a hypochondriac, so I’ve always been a bit skeptical of illness. My mother is usually way too busy to ever be sick, seeming to save it all up until—from time to time—something big knocked her out. As a paramedic, my stepfather was around illness and injury all day long, and in those pre-HIPPA days it was okay to talk about the things that happened in the emergency rooms and on the accident-prone highways of Wyoming.

As a result, I have a rather high bar for being sick. “Do I have hemorrhagic fever?” No. “Do I need surgery?” No. “Did I bring the rattlesnake that bit me into the E.R. in a pillowcase . . . after finishing digging all of the new post holes?” No. “Then I must not be too sick.” Don’t get me wrong; I don’t believe in going to work and exposing my coworkers to whatever contagious thing I have, but it takes a lot to keep me home. Fever mainly. Or the inability to stay awake. Or pain. Or not being able to keep things that belong on the inside on the inside. Or hemorrhagic fever . . . which might combine all of those together—though I’ve never had it. (*touch wood*)

I do what I can to stay healthy. I get a flu shot annually. I avoid people who are sick. I wash my hands. I avoid the finger-food that randomly shows up around the office printer. I tell myself that I feel well, even if I’m a bit marginal. And, for the most part, I stay very healthy.

Except that every year around this time, I get a respiratory infection that slows me down. I blame winter—and children—for the sniffle and headache that eventually turns into a sore throat, cough, and malaise as it moves its way from my sinuses to my chest.

It’s going around, and I don’t really feel bad at all. Except, yesterday when I got home it hit me. In the span of five minutes my mind switched from “It’s beautiful; I should run outside” to “I still feel a bit wimpy; I should run on the treadmill” to “I think I could vom; I’m should lie here on the coach under a blanket.”

I guess I looked pathetic when Lisa came home from work an hour later. By that time, I didn’t feel quite so bad, just worn out.

Which brings me back to my initial observation: I am not a good sickie. I do what I should to help me get well as quickly as possible—I take it easy and follow the widely held “Don’t exercise if you’re sick from the throat down or have a fever” philosophy—but it makes me unhappy in a way that the actual illness usually doesn’t. When I miss a workout—much less actual work—for things that don’t even remotely resemble hemorrhagic fever, I feel like a slacker, a loafer, a shirker.

I missed a few workouts last week before I started feeling better over the weekend, just to relapse over the last few days. Monday, when I thought I was feeling well, I went for a surprisingly slow swim in the morning and a short but surprisingly slow run in the afternoon. Then Tuesday I went to the gym to pick things up and put them down, which was surprisingly difficult. And that was the last time I worked out this week. Tuesday afternoon workout? Nope. Wednesday morning swim? Nope. Wednesday afternoon run? Nope. Thursday morning weight training? Nope. And since I’ve been coughing and downing sugar-free Robitussin DM all day, it’s likely that I’ll take this afternoon off, too.

And this, my friends is the difference between having diabetes and being Real People Sick™: When I just have diabetes, I can do whatever I want. Actually being sick sucks.

Posted in Diabetes, Running | 2 Comments


From a pre-lunchtime conversation . . .

Coworker: You can sign up to be a zombie or a normal person. If you’re a normal person, you wear a flag-football belt, and if the zombies chasing you grab two of the flags, you’re done.

Me: And if you hit one of the zombies in the head with a bat?

Coworker: You get charged with assault.

Posted in General, Running | 1 Comment


Lisa makes the best T-shirts! This Christmas gift might just be perfect.

Bad-Ass Diabetic Motherfucker

Posted in Diabetes, General, I am Rembrandt | 3 Comments

An Experiment with SSE

Updated: 6 February 2012.

Techie people, the good stuff—code, results, more info—is below the fold.

Friends, I’ve been in my head a bit recently. That’s not necessarily bad—it’s a nice neighborhood, really—but one of the dark alleys I’ve had to walk past a lot lately involves way too many imposter-type feelings. As I previously mentioned, we’re hiring, and we’re looking for someone to do many of the same job tasks that I do. Being mostly self-taught at software engineering and computer science, I have to remind myself that I have more than a dozen years of experience; whereas, for most of the people whose résumés cross my desk, they do not.

It’s sometimes hard to silence those voices that say “everyone else is more accomplished than you.” Even though it’s not true, I’ve been meaning to pick up some more skills so that I can (a) try to feel like less of an imposter and (b) write more awesome code to make our product more awesome and help us fend off our competitors and make more loot.

So yesterday afternoon, rather than coming up with (yet another) daunting list of all of the places where I feel like I should learn more, I just picked one that I already knew about: Streaming SIMD Extensions, a.k.a. SSE. For me, the best way to learn is to write a program that does something (theoretically) useful, run into real-life obstacles, and workaround the pitfalls I encountered. Practice, practice, practice.

My dear readers who don’t program, you can now safely navigate away for another day without guilt. The rest of the post is rather technical and describes how I took an example I found online, made it work with gcc, and got a 4x speedup by using SSE. A speedup and happier outlook. Not bad for a few hours on a Saturday!

Continue reading

Posted in Computing, Fodder for Techno-weenies, General | 1 Comment

Criticizing Brainstorming

Friends, I think I might have something interesting say in the next couple of days. Until then, here are some more excerpts, this time from Cliff Kuang’s Fast Company article “The Brainstorming Process Is B.S. But Can We Rework It?”. And, yes, it also has that contrarian, all-those-ideas-from-the-forties-through-the-seventies-were-pretty-much-wrong flavor (with at least a hint of maybe-it-was-partly-right-but-we-know-better-now).

The business practice of brainstorming has been around with us so long that it seems like unadorned common sense: If you want a rash of new ideas, you get a group of people in a room, have them shout things out, and make sure not to criticize, because that sort of self-censoring is sure to kill the flow of new thoughts. . . .

[Alex Osborn, the 1940s ad man and inventor of brainstorming] thought, quite reasonably, that creativity was both brittle and fickle: In the presence of criticism, it simply couldn’t wring itself free from our own minds. We could only call our muses if judgments didn’t drag us down. Osborn claimed that this very brainstorming process was the secret to BBDO’s durable creativity, allowing his ad guys to produce as many as 87 ideas in 90 minutes—a veritable avalanche. “The brainstorm had turned his employees into imagination machines,” writes Jonah Lehrer in a long, excellent article in The New Yorker. But as Lehrer argues, the only problem with all this is that brainstorming is total bullshit. . . .

  • You’re More Creative Working Alone: “Putting people into big groups doesn’t actually increase the flow of ideas. Group dynamics themselves—rather than overt criticism—work to stifle each person’s potential.”
  • Criticism Improves the Brainstorming Process: “Usually, inventions often begin when an inventor spots a problem. Good ideas usually don’t hang by themselves, unattached. They come about as solutions. Thus, allowing criticism into a room full of people trying to brainstorm allows them to refine and redefine a problem.”
  • Creativity Is About Happenstance, Not Planning: “Too much familiarity bred groupthink. Too little meant that they didn’t have enough chemistry to challenge each other. The most productive groups were those with a baseline of familiarity but just enough fresh blood to make things interesting. . . . Studies have shown that the most successful groups of scientists also work in extremely close physical proximity. Just being around another creative person is vital to the process . . .”
Posted in General, Life Lessons, This is who we are | Leave a comment