Category Archives: Work

calca

Calca: the notepad calculator

For years, I’ve been search­ing for a good free-form sym­bolic cal­cu­la­tor pro­gram that works across mul­ti­ple desk­top oper­at­ing sys­tems. I think I’ve finally found one worth men­tion­ing. My goals:

  • Be able to enter expres­sions sim­i­lar to what I could do on a TI-85, back in the day, for exam­ple: 2^2+(2*10)
  • Be able to eas­ily edit and copy previously-entered expres­sions.
  • Input/output hex. I work in hex a lot. This includes expres­sions (0x48+0x16) as well as base con­ver­sion (0xC3 as decimal or 0b110101 as decimal) and bit­wise math (0xFC AND 0x7F).
  • Lightweight. Quick to load, quick to cal­cu­late. Get in, get out. Or leave it run­ning in the back­ground with­out eat­ing a ton of resources. I don’t need or want Mathematica or Maxima.
  • It needs to min­i­mally run on Windows and Mac. Ideally a Linux ver­sion would be avail­able, too. I write code on Linux (work) and Mac (home), but my office Windows box ends up being my doc­u­men­ta­tion ref­er­ence, scratch­pad, cal­cu­la­tor, and every­thing else non-coding because I typ­i­cally run my Linux IDE full-screen (bridged with Synergy, nat­u­rally).

I’d pre­vi­ously got­ten hooked on Soulver. It’s great on the Mac, but there are not Windows or Linux ports. There is an iOS port, but I can’t stand the data entry. SpeedCrunch is avail­able for all plat­forms, but like many Open Source pro­grams, the oper­a­tion and user inter­face is clunky.

A few months back, I found Calca, “the text edi­tor that loves math,” for Windows and Mac. It lit­er­ally is a text edi­tor. The trick is that it looks for “=” and inter­prets these as def­i­n­i­tion state­ments and it looks for “=>”, and treats these lines as prob­lems to solve. Everything from “=>” to the end of the line is rewrit­ten to become a read-only answer. For exam­ple:

calca

I don’t come close to using all the fea­tures in Calca: func­tions, unit/currency con­ver­sion, matrix math, deriv­a­tives, and so on. My needs are small, but with the pieces I do use, it per­forms extremely well.

A few things I don’t like about Calca:

  • There are no bit­wise shifts or inver­sions. I some­times run into cases where a 32-bit inte­ger is com­posed of sev­eral unaligned bit fields. For instance, bits 5..7 might be one field. It would be great to say: 0x1234 >> 5 & 0b111
  • I fre­quently get con­fused with base con­ver­sion syn­tax. Is it “as dec” or “in dec”? I fre­quently pick the wrong one.
  • Having to type “=>” at the end of each line is typo­graph­i­cally awk­ward. I appre­ci­ate Soulver hav­ing a sec­ond col­umn that auto-updates as you type.
  • It would be nice to have a “pre­vi­ous answer” sym­bol. The TI cal­cu­la­tors auto­mat­i­cally insert an “Ans” vari­able (a place­holder for the pre­vi­ous line’s answer) if you start a new line with an oper­a­tor instead of an operand.

For me, it was worth buy­ing both a Windows and Mac license. I use it all the time.

Posted in: Software Work

someone_is_doing_something_nasty

ssh for Programmers

Overview

Way back when, just after the dot-com-bomb, I found myself work­ing for a media com­pany named Metapa. We made mp3s and 30 sec­ond pre­view clips from boxes of CDs that tech-clueless record com­pa­nies snail-mailed us. Metapa was staffed with a ton of Unix-heads and I received a great school­ing in the ways of the Secure Shell, ssh. You could not get to a server with­out ssh­ing into it. Our “VPN” was a server run­ning ssh, con­fig­ured to only accept key-based login. There was no way to log in with just a pass­word. You would con­nect and use ssh’s built-in port for­ward­ing to route more fancy con­nec­tions, as required. I got to know ssh incred­i­bly well.

At more recent jobs, peo­ple have used ssh to man­u­ally con­nect to boxes and to man­u­ally issue com­mands, but they never did any­thing more advanced. I never under­stood exactly why. I’m sure some of this is that these have been mixed Windows/Linux envi­ron­ments with heav­ier reliance on Windows, so the “cul­ture” of using ssh for every­thing just isn’t present. Part of it may also be lack of expe­ri­ence with ssh.

This arti­cle attempts to touch on the slightly more advanced meth­ods of work­ing with ssh. I am not going to get into port for­ward­ing, since that requires a much more advanced men­tal model and a good grasp of how to con­fig­ure the local and remote soft­ware. I also will not get into rsync, which is a com­mon tool that pig­gy­backs atop ssh to syn­chro­nize fold­ers. What I will dis­cus is a few of the more com­mon advanced uses:

  • copy­ing files
  • log­ging in with­out keys
  • aliases for server names
  • dif­fer­ing user­names
  • log­ging in to the cloud (com­bi­na­tion aliases, user­names, and alter­nate keys)
  • a quick fix for changed host iden­ti­ties

Copying Files

ssh has a com­pan­ion app named scp, or Secure Copy. It works exactly like the reg­u­lar Unix cp com­mand except the source and des­ti­na­tion can take ssh file paths in the form of username@machine:path/to/file.txt.

For instance, if I wanted to push my “.vimrc” file to a remote sys­tem named frodo, I could run any one of the fol­low­ing com­mands:

# a technically correct, but wordy way to do it
scp .vimrc briane@frodo:.vimrc

# destination file is the same name, so no need to specify
scp .vimrc briane@frodo:

# assumes my username is the same on frodo, so no need to specify
scp .vimrc frodo:

Note that when scp con­nects, it is in your home direc­tory. These des­ti­na­tions use rel­a­tive paths (because the paths do not start with a slash) so they are rel­a­tive to your home folder. If you wanted to copy a log file, you might use an absolute path such as:

# copy the Apache error log to the current folder
scp briane@frodo:/var/log/apache/error.log .

Logging in Without Keys

By default ssh (as well as scp) uses your Unix pass­word to access the remote sys­tem. This is all well and good, but it also offers another way to iden­tify your­self that allows for a bit more con­ve­nience and a lot more secu­rity. This method is dual-key cryp­tog­ra­phy. Put sim­ply, this is a whole bunch of math shared between two files, a “pub­lic” key and a “pri­vate” key. The pri­vate key is, effec­tively, a ludi­crously large num­ber — like a pass­word — that you share with nobody. The pub­lic key is math­e­mat­i­cally derived from the pri­vate key and can be used to check the authen­tic­ity of the pri­vate key. You can share the pub­lic key far and wide. When using keys with ssh, you store a copy of your pub­lic key on the remote server. Every time you log in to it, your machine and the remote machine do a lit­tle dance involv­ing the pub­lic and pri­vate keys, and you’re instantly logged in — no pass­word required. It effec­tively shifts the authen­ti­ca­tion mech­a­nism from “what you know” (a pass­word) to “what you have” (a data file with that long num­ber).

In con­cept, this is all well and good, but it is some­times a lit­tle painful and tedious to set up by hand. You have to ensure the cor­rect file is in the cor­rect place. The per­mis­sions have to be per­fect or the ssh server will refuse your login. After all, if your pub­lic key is writable by other peo­ple, then some­one with access to the sys­tem can over­write it with their pub­lic key and log in as you, with your full per­mis­sions and cre­den­tials. Fortunately, if there is one thing that com­put­ers are good at automat­ing, it is sim­ple, annoy­ing, some­times painful tasks.

First, you will need to cre­ate a key (if you have not done so already). It’s a sim­ple com­mand:

ssh-keygen

Just keep hit­ting Return to answer all the ques­tions with their defaults, includ­ing an empty pass­word. Next, you can use a script like the fol­low­ing, named colonize.sh, that will send your key to a remote machine over a reg­u­lar ssh-with-password con­nec­tion and set up the per­mis­sions.

#!/bin/bash
if [ -z "$1" ]; then
    echo "Function: copies ssh public keys to remote machines for passwordless login"
    echo "Usage: colonize.sh <username>@<servername or ip address>"
    exit 1
fi
KEY=id_rsa.pub
STORE=authorized_keys
CONTENT=`cat ~/.ssh/$KEY`
echo "Attaching key to authorized_keys file"
ssh $1 "mkdir -p .ssh && chmod 700 .ssh && touch .ssh/$STORE \
    && chmod 644 .ssh/$STORE \
    && echo '$CONTENT' >> .ssh/$STORE"
echo "Complete!  You should be able to log in without a password now!"

Now if you want to col­o­nize a remote machine with your ssh keys, you’d just do some­thing like:

colonize.sh briane@bilbo

Enter your pass­word (for the last time ever!) and next time you ssh or scp with that machine, it will use your keys instead of your pass­word.

Server Aliases

There is a con­fig file in your dot-ssh folder named sim­ply .ssh/config. This holds a wealth of options for cus­tom per-server set­tings. Long ago, I had a vir­tual pri­vate server with Dreamhost (I’ve since moved to Linode for reli­a­bil­ity rea­sons; if you’d like to try it out, feel free to use my refer­ral URL). This server had the ugly and dif­fi­cult to remem­ber name of “ps24493.dreamhost.com”. I ssh and scp all the time, but had dif­fi­culty remem­ber­ing that exact server num­ber. Fortunately, there is a bet­ter way.

Your .ssh/config file lets you define a Host (what you type to con­nect) to a HostName (the actual server name). For exam­ple, my con­fig had the fol­low­ing two lines:

Host dreamhost
HostName ps24493.dreamhost.com

This means that “dreamhost” ends up as short­hand for the more annoy­ing “ps24493.dreamhost.com”. If I want to log in, I’d just “ssh dreamhost”. If I wanted to copy a file, I could “scp index.html dreamhost:/var/www/my_website”. It made it much eas­ier to access the server.

Differing Usernames

I actu­ally had one more line in that part of con­fig file. The account name I use on most of my local machines is sim­ply “brian”. On that vir­tual pri­vate server, it was the much more ver­bose but globally-unique “brianenigma”. So tech­ni­cally, I could not con­nect with a sim­ple “ssh dreamhost” but “ssh brianenigma@dreamhost”. But there is another line that can be added to the .ssh/config to allow the for­mer vari­ant with­out a user­name.

You can define a default user­name for a spe­cific sys­tem by putting a “User” entry in the “Host” sec­tion. For instance:

Host dreamhost
HostName ps24493.dreamhost.com
User brianenigma

This, then, allows me to type in “ssh dreamhost” instead of the much more wordy “ssh brianenigma@ps24493.dreamhost.com”.

Logging in to the Cloud

Amazon’s Web Services is an inter­est­ing beast. You get a machine up in the cloud that you can log into. It typ­i­cally has an ugly name (which can be nick­named — see two sec­tions back) and may have a dif­fer­ent user­name than the one you use on your local machine (which can also be rede­fined — see the pre­vi­ous sec­tion). It throws in yet another wrin­kle. Password-based login is for­bid­den and it assigns you a pub­lic and pri­vate key pair. Because it assigns you a key, it is obvi­ously going to be dif­fer­ent than any key you have pre­vi­ously gen­er­ated for all your other con­nec­tions.

There is an ugly way to spec­ify the key­store you down­loaded from Amazon on the com­mand line, but a far more sim­ply way is to define it in your .ssh/config, such as this entry that com­bines all of the above and adds the key­store:

Host cloud
HostName ec2-256-301-297-271.us-west-2.compute.amazonaws.com
User administrator
IdentityFile ~/.ssh/my_amazon_key.pem

Now you can log in to your AWS account by just typ­ing “ssh cloud”. ssh will expand that out to the very ugly equiv­a­lent:

ssh -i ~/.ssh/my_amazon_key.pem administrator@ec2-256-301-297-271.us-west-2.compute.amazonaws.com

Remote Host Identification has Changed

I work in a lab envi­ron­ment with lots of servers that are fre­quently refor­mat­ted. This means that the servers retain their name and IP address, but the ssh fin­ger­prints that uniquely iden­tify them (to help thwart third par­ties from pos­ing as the server and steal­ing your pass­words) get wiped out. In this case, if I attempt to log in, I get a big scary mes­sage like the fol­low­ing:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
f0:d1:77:17:9a:55:de:ad:be:ef:00:00:08:67:53:09.
Please contact your system administrator.
Add correct host key in /home/briane/.ssh/known_hosts to get rid of this message.
Offending key in /home/briane/.ssh/known_hosts: 6
Permission denied (publickey,password).

The fix here is to open up .ssh/known_hosts and delete line 6. Technically, delet­ing the entire file also works (and I have seen plenty of peo­ple do that as a “fix”), but that has the side-effect of forc­ing you to con­firm, all over again, every remote host you con­nect to as a new host. So: “delete line 6” is sim­ple enough to do, but also annoy­ing. We can auto­mate that. The fol­low­ing script, called fixssh.sh, will retain the past nine back­ups of your known_hosts file and delete the offend­ing line. In this case, you’d run it with “fixssh.sh 6”.

#!/bin/bash

if [ -z "$1" ]; then
    echo "Put line number of your ~/.ssh/known_hosts file for deletion on the"
    echo "command line."
    exit 1
fi

cd ~/.ssh/
rm -rf known_hosts.9
for NUM in 8 7 6 5 4 3 2 1 ; do 
    ((NUMPLUS=$NUM + 1))
    if [ -d known_hosts.$NUM ]; then 
        mv known_hosts.$NUM known_hosts.$NUMPLUS 
    fi 
done
mv known_hosts known_hosts.1
cat known_hosts.1 | sed "$1 d" > known_hosts
chmod 644 known_hosts

Conclusion

I hope these tips help you become more pro­fi­cient at ssh usage. Once you have these down, you might search on your own for the more advanced top­ics like how to use rsync, to keep mas­sive amounts of files in sync, or using ssh port for­ward­ing.

Posted in: Code Software Work

creepy_horse_head_street_view

Why, yes, I *am* that creepy horse in Google’s PDX street view

Google sent Thomas Hayden in to do the “inte­rior street view” pho­tog­ra­phy of Elemental Technologies last week.  Fortunately, I had a lit­tle bit of notice (unlike with the car-based street view pho­tog­ra­phy) and was able to bring in the creepy horse head mask I got a cou­ple of hal­loweens ago.

He came by and took pho­tos dur­ing lunch.  That’s me in the red shirt.  You can’t see it, but I had chop­sticks in hand, over a bowl of ramen.

Find the link here: http://nja.me/horse

If you look around the office, you can spot my desk.  It’s the one with the tea tins and rub­ber horse head mask.  He took that photo ear­lier, while I was at the food carts and nobody was wear­ing the mask.  Unfortunately, the angle and res­o­lu­tion isn’t quite right to see my laser-cut light-up name­plate.

Other things to spot (you’ll have to use the “1” and “2” but­tons to tra­verse between floors)...

  • bas­ket­ball signed by Muggsy Bogues
  • rub­ber chicken
  • Mini Me
  • the reflec­tion of the pho­tog­ra­pher
  • a TableTop beer stein
  • an arcade game cab­i­net
  • a fly­ing toaster and octo­pus
  • the Puzzled Pint logo
  • a pirate flag
  • Hello Kitty rid­ing a pega­sus
  • a NewTek TriCaster
  • Waldo (just kid­ding, there’s no Waldo)

The answers are in the com­ments.

Posted in: Dear Diary Pictures Portland Work

Windows Natural Scrolling and Synergy

Windows Natural Scrolling and Synergy

A lit­tle over a year ago, I wrote about set­ting up “nat­ural scolling” on Windows. I tried it for a week or so and never quite got used to it. One of the biggest set­backs was the soft­ware I use to con­nect my Windows and Linux boxes together as one large desk­top: Synergy. My mouse and key­board are hooked up to a Windows box. When the mouse scrolls off the left side of the screen, Synergy takes over and passes the mouse move­ments and key­board sequences to the Linux box’s desk­top. I get what feels like a large, sweep­ing, cross-OS desk­top. It turns out that the AutoHotkey map­pings to reverse the scroll wheel did not get trans­mit­ted across to Synergy. They only worked on one half of my desk­top. This is not just annoy­ing, but really messes with your mus­cle mem­ory of which way to scroll.

I recently heard John Siracusa men­tion in a recent episode of Hypercritical that he is right-handed, but uses the mouse with his left hand. He switched mouse-handedness long ago because he started to feel the begin­nings of ten­dini­tis and/or carpal-tunnel syn­drome in his right arm and didn’t want to see it worsen. Because I’ve been feel­ing ten­dini­tis come and go, despite breaks and exer­cises, I thought I would try some­thing sim­i­lar. I feel that the major­ity of my dis­com­fort comes from scrolling so I thought I would try using my left hand for the major­ity of scrolling and sim­ple move­ments. I hap­pen to have a spare Apple Magic Trackpad, which I brought into work and hooked up. I set it up to the left of my key­board, but am keep­ing the mouse to the right. The track­pad is okay for point­ing, scrolling, and click­ing. Dragging and right-clicking are much more dif­fi­cult (at least with the Windows dri­vers). For me, those are much more rare oper­a­tions than scrolling and select­ing — I mainly nav­i­gate spec­i­fi­ca­tion doc­u­ments and code trees — so the mouse is still avail­able on the right.

I ini­tially tried this for a day and it mostly worked, except for scrolling. I’m so used to touch-scrolling on my Mac that the reg­u­lar (non-natural? unnat­ural?) track­pad scrolling kept throw­ing me for a loop. AutoHotkey still did not work across Synergy. A lit­tle more research was required.

The key to get­ting this work­ing and usable was dis­cov­er­ing how to reverse scrolling down at the OS level, rather than up in the appli­ca­tion layer (as AutoHotkey does). There are actu­ally just some reg­istry keys to tog­gle in HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Enum/HID that will reverse scroll-direction at a layer deeper than AutoHotkey and deeper than Synergy. I ran across this blog post that explains how to find the “FlipFlopWheel” keys within the above-mentioned HID path and tog­gle them. This isn’t the solu­tion for every­one — regedit can be a scary and dan­ger­ous tool in the hands of the unini­ti­ated — but it worked for me.

I now have a left-handed track­pad set up with nat­ural scrolling for day-to-day nav­i­ga­tion and a right-handed mouse set up for more tricky oper­a­tions. So far, things are good.

Posted in: Code Dear Diary Software Work

bike_commute_challenge-calendar

Bike Commute Challenge: Final Score

Last month, I did the Portland Bike Commute Challenge.  You may remem­ber the post.  I did not end up with the score-card I hoped for, but it was decent enough, con­sid­er­ing this was the first “real” bik­ing I have done since, per­haps, junior high school.  In recent years, my bicy­cling has been con­fined to small trips to the pub and back.

I loved going to work (coast­ing down Clinton street).  I was less happy with the return trips home (ped­al­ing all the way back up Clinton).  I could not do Wednesdays, due to sched­ul­ing (yoga) and things sort of petered out toward the end of the month when the weather turned for the worse (my wardrobe is a lit­tle light on the water­proof activewear front).  Overall, though, I think I did well.  Go me!

Posted in: Dear Diary Portland Work

generating2

Rock, Scissors, Fire

It seems like all engi­neers like to name things in clever ways along a com­mon theme.  Most often, this man­i­fests itself in the names of com­put­ers.  All of the servers in a given server room or indi­vid­ual rack might get named after Simpsons char­ac­ters, the seven dwarves, the seven deadly sins, the nine greek muses, the nine eight plan­ets, and so on.

I work at a com­pany that has con­fer­ence rooms named after the four orig­i­nal ele­ments: earth, air, water, and fire.  Due to some remod­el­ing and growth, we will get to add a new con­fer­ence room.  One of the first ques­tions is what to name it.  We could start a new nam­ing theme, but we sort of painted our­selves into a cor­ner with the four ele­ments.  Or did we?

Actually, the Wikipedia Page on the clas­si­cal ele­ments shows quintessence/quint/æther/ether as a fifth ele­ment (not to men­tion alter­na­tives like Leeloo Dallas, Captain Planet’s “heart”, and a vari­ety of fic­tional ele­ments like unob­ta­nium), so there is a bit more room to grow there.

The actual rea­son for this post is to point out some­thing fun I saw in look­ing over the clas­si­cal ele­ments.  In China, they do not use earth, air, water, and fire but instead have wood, fire, earth, metal, and water.  Not only that, but they have a great lit­tle rock/paper/scissors/lizard/Spock thing going on in the way one ele­ment spawns or negates another.  (Of course, to be a true rock/paper/scissors/lizard/Spock, there would have to be arrows across the diag­o­nals, not just around the out­side — I leave it as an exer­cise for the reader to invent those.)

To bet­ter illus­trate, I would like to present the cycles in Mario Brothers bitmaps:

Yes, this is what hap­pens when you spend too much time get­ting sucked into Wikipedia.

Posted in: Dear Diary Work

Push_button_cable_box

My last cable box had pushbuttons

Today a cou­ple of dif­fer­ent peo­ple at work com­mented on the screen­saver I cur­rently use. It is xanalogtv from the xscreen­saver pack­age. It sim­u­lates switch­ing chan­nels on an old boxy rotary-channel-selector tele­vi­sion, com­plete with snow, image ghost­ing, wig­gly ver­ti­cal sync, and all of that. The author of this screen­saver put in an impres­sive amount of work to get a crisp mod­ern dig­i­tal mon­i­tor to emu­late a grainy old tele­vi­sion.

It then occurred to me that kids that are just now turn­ing old enough to start remem­ber­ing their child­hood will really have no expe­ri­ence with the sorts of fuzzy ana­log that this screen­saver is try­ing to emu­late. Glitchy CDs and DVDs usu­ally result in stut­ter­ing. Glitchy video files result in square, blocky, mul­ti­col­ored graph­ics. With tele­vi­sion all dig­i­tal now, small glitches in the video sig­nal results in the video stut­ter­ing a bit and large glitches cause the TV to drop out to a solid blue screen. There’s no fuzzi­ness, no rolling pic­ture, no ghost­ing. For bet­ter or for worse, it’s his­tory.

This then got me think­ing about the last time I remem­ber expe­ri­enc­ing fuzzy rolling video. That was also the last time I had cable. That cable box had a “remote con­trol” — a boxy thing on a 20′ wire with twelve but­tons and a four-way selec­tor switch. Three posi­tions on that selec­tor switch chose three dif­fer­ent sets of chan­nels and the low­est posi­tion was “off” (the TV plugged into the cable box, so it could turn the TV off; tele­vi­sions were dumb and had no mem­ory or other state that could be lost if unplugged). It looked a lit­tle some­thing like this, wood grain and all (via Wikipedia):

The dial on the right was to fine-tune the selected sta­tion. Just about every kid in the neigh­bor­hood knew that if you clicked down two or more chan­nel but­tons, then played with the dial a bit, you could kinda-sorta-maybe tune into the porn chan­nels. The audio was usu­ally pretty good. The pic­ture always had ana­log glitches. Sometimes the col­ors were inverted. Sometimes, the pic­ture was cov­ered in wavy sta­tic. Sometimes you just got sound — no usable pic­ture. Those were the days of ana­log.

These days, the “cable” shows that I watch are per­fectly crystal-clear (well, aside from the occa­sional mpeg arti­fact­ing, but my eyes are now trained to look for that sort of thing, oth­er­wise I doubt I’d notice much of that). They come off of the inter­net, be it iTunes, Netflix, Hulu, or oth­er­wise. Bits and bytes are ones and zeros. They work or they don’t. It’s not like in the old-school days where you needed thick gold-plated cables for the ulti­mate qual­ity (no mat­ter what Monster tries to tell you about their spendy “magic” HDMI cables). With no degre­da­tion in qual­ity, the bits come from the inter­net, through the com­puter, and out to the tele­vi­sion. No more snow, no more ghosted images, no more sync issues.

And you either get the porn chan­nel or you don’t — no fuzzy mis­tuned ana­log chan­nel. Kids these days won’t get that. Of course, when I last had cable, there was barely an inter­net. There was no cyber-nanny. Daddy’s porn stash was a box in the back of the closet, not a hid­den folder on the hard drive. I think kids these days are prob­a­bly okay on, if not over­flow­ing in, porn. And it’s crisp and clear and dig­i­tal.

Posted in: Dear Diary Television Work

Have you tried switching it off, then on again?

I wrote briefly about it before, but many years ago I used to work as a low-level tech at a vir­tual real­ity com­pany. When I wasn’t oper­at­ing or hack­ing the sys­tem, I was repair­ing it. These repairs were some­times a lit­tle com­plex, but 99% of the time, they boiled down to two things. Reboot. If that does not work, turn off the machine, open up the access panel, slide out one of the gar­gan­tuan proces­sor boards from the back­plane and push on each and every chip. Yep, that’s right. Use my thumb to apply pres­sure to the chips, ensur­ing they sit cor­rectly in their sock­ets. I guess that was a thing. Temperature vari­a­tions caused the chips and their sock­ets to expand and con­tract, even­tu­ally work­ing them­selves loose. The prob­lems that arose were almost entirely hard­ware.

I no longer work at that com­pany — it went bust years ago — but I do find myself work­ing again in com­puter graph­ics. These days, the prob­lems tend to be a bit more com­plex than “turn it off, then back on again” or “push on the chips.” Fortunately, it’s not as bad as my last gig, where we devel­oped both hard­ware and soft­ware. When some­thing broke there, it took time to deter­mine if the fault is in the code or the cir­cuit design. With my cur­rent work, prob­lems are gen­er­ally in the code we’ve writ­ten or in hard­ware dri­vers (code some­one else has writ­ten, that our code talks to).

Sometimes oper­at­ing sys­tem updates pull in new dri­vers. When this hap­pens, usu­ally things are okay, maybe requir­ing a lit­tle bit of “jig­gling the han­dle” sorts of oper­a­tions to make things right (rebuild­ing from clean code and such).

An OS update came down the wire a few days ago. It included a new Linux ker­nel, which wasn’t a big deal. A dri­ver rein­stall and a recom­pile of my code should have been more than enough. Unfortunately, it wasn’t. Nothing was work­ing and I kept get­ting the same cryp­tic error mes­sage. This was late in the day. The next day, after a few more hours of trou­bleshoot­ing, I decided it was time to just wipe my sys­tem and return to a known-good state with the orig­i­nal boot disk. Thirty min­utes later, I was star­ing at a freshly installed oper­at­ing sys­tem, but the prob­lems per­sisted.

On a whim, I tried some­thing. I unplugged power, pulled off the side panel, and then wig­gled and pushed on the graph­ics card. Buttoning things up, I hit the power but­ton and tried again. Everything worked fine.

I never thought I’d be back at that job again. That reboot and push on the chips job. Over the years, I honed my skills and thought I rose above it, but in this high tech world, some­times the low-tech solu­tions are exactly what is required.

Posted in: Dear Diary Work

Boost C++ & Operator Overloading

As you may or may not know already, I recently started a new job.  The new com­pany makes a lot more heavy-duty use of C++ than the pre­vi­ous one did.  Among the C++ code is the 3rd party Boost C++ library.  I had periph­er­ally heard of Boost before, but had never looked too deeply at it.  It is a set of stan­dard cross-platform C++ classes that per­form a vari­ety of use­ful oper­a­tions.  You can think of it like an addi­tion to the Standard Template Library (STL).  In fact, they are try­ing to get some of their code accepted as future C++ stan­dards.

There are two classes in Boost that are used fre­quently in our code: for­mat and path.  I like them and find them use­ful, but a small detail of their imple­men­ta­tion just rubs me the wrong way.  Before I get into that detail, let me first dis­cuss their util­ity.  Programmers often have to for­mat strings.  In C, the way to do this is sim­i­lar to:

sprintf(buffer, "The answer to %s is %d", "your question", 42);

You had bet­ter hope that “buffer” is big enough to hold the answer, though.  You could dynam­i­cally allo­cate the buffer (and remem­ber to free it later).  You can use snprintf() and worry about the null-terminator if the buffer is too small.  But any way you do it, it’s going to take a few lines of code, might not be mem­ory effi­cient, and prob­a­bly isn’t as clean as it should be.

The reg­u­lar C++ way of per­form­ing this oper­a­tion uses a class to worry about the details of buffer size, string length, and releas­ing the buffer.  For exam­ple:

std::ostringstream buffer << "The answer to " << "your question" << " is " << 42;

This sort of works, but gets ugly if you have lots of vari­ables inter­spersed with sta­tic text.  It also kills any efforts at inter­na­tion­al­iza­tion.

The Boost way of doing this is more like the C way, but with­out the buffer size wor­ries:

std::string buffer = str(format("The answer to %s is %d") % "your question" % 42);

It is even less crash-prone than the C sprintf().  If you were to feed it only one argu­ment, but have two or more place­hold­ers in your for­mat string, Boost would be fine, but sprintf() may choke, include garbage, or crash.  With Boost, you can even get more fancy (with bet­ter i18n com­pli­ance) by using posi­tional argu­ments:

std::string buffer = str(format("The answer to %2% is %1%") % 42 % "your question");

The per­cents act sort of like the Python for­mat­ting oper­a­tor:

buffer = “The answer to %s is %d” % {“your ques­tion”, 42};

The Boost object for work­ing with paths uses a sim­i­lar trick, only instead of the per­cent oper­a­tor, it’s the slash oper­a­tor.  You can do some­thing like this:

path myPath = "/home/brian";
myPath = myPath / "Pictures";
myPath /= "photo.jpg";
myPath.replace_extension("png");

And in the end myPath.string() holds the text “/home/brian/pictures/photo.png”.  It gets the slashes and back­slashes cor­rect for Unix ver­sus Windows and has all sorts OS-agnostic helper func­tions for cre­at­ing paths, delet­ing files, and what­not.

As much as I like these classes and enjoy their ease of use, there is one minor thing that rubs me the wrong way, as I men­tioned above.  Specifically: the “clever” way they’ve over­loaded the per­cent and slash oper­a­tors.  I was taught long, long ago that although you can over­load stan­dard oper­a­tors in C++ it’s a bad, bad thing to be too clever in chang­ing their seman­tic mean­ing.  The oper­a­tor+() func­tion should always per­form some sort of addi­tion (be it sum­ma­tion or con­cate­na­tion).  Similarly, operator/() should divide or do some­thing akin to divi­sion.  Operator%() should be mod­u­lus (the remain­der after divid­ing).  You can over­load them to do some­thing spe­cial for your class related to the orig­i­nal mean­ing (adding com­plex num­bers, cross-multiplying matri­ces), but you shouldn’t go too out-of-bounds with their mean­ing.

I could have sworn that I read this in the Bjarne Stroustrup C++ book or one of the other top-rated C++ books, but skim­ming my dig­i­tal copies to find a spe­cific ref­er­ence quo­ta­tion to cite turned up noth­ing.

Do I find the for­mat and path classes incred­i­bly use­ful?  Yes!  Do I find their oper­a­tor over­load­ing a minor annoy­ance?  Yes!  Is it annoy­ing enough to pre­vent me from using those classes?  No!  I find the Boost imple­men­ta­tion of the slash and per­cent a lit­tle too out­side the box from what I’m used to, but I’ll go ahead and keep using them and will prob­a­bly get used to it in time.

Posted in: Code Work

Money vs. Culture

There is a great guy named Merlin Mann whose work I have been appre­ci­at­ing for years.  He is pretty much a time and pro­duc­tiv­ity guru, although I am not sure you’d be able to catch him using the word “guru” to describe him­self in any way.  He invented the Hipster PDA and Inbox Zero.  Earlier in the year he gave a talk at Rutgers about time and atten­tion and I got to lis­ten to the pod­cast of that talk.  A lot of the ses­sion revolved around the car­toon ani­mals of the Richard Scarry books.  I used to love those books as a kid!  Back in the day, it was pretty easy to illus­trate jobs in a book for chil­dren.  Give a dog a red hat or a pig a big knife and you instantly knew they were a fire­man or a (iron­i­cally or oth­er­wise) butcher.  Information work­ers these days are less easy to make into car­i­ca­tures.  A cat sit­ting at a desk with a com­puter under a flo­res­cent light could be a sec­re­tary or a web designer or an author or an illus­tra­tor or an embed­ded sys­tems engi­neer or some dude spend­ing all day run­ning a pre­tend farm on Facebook.  I don’t know that I could explain my job to an 8 year old.

Although most of the talk was about jobs and main­tain­ing atten­tion and san­ity with regard to email over­load and too many meet­ings, a cer­tain bit about 10 min­utes in really res­onated with me more than any other part of the talk.  That part is as fol­lows (empha­sis mine):

If I’m going to spend ten hours a day here, I need to like you guys a lot, and we’re going to need a cul­ture here that works.  Money is the rea­son peo­ple say they leave a job, but cul­ture is the rea­son that money became an issue. If some­body loves their job intensely and feels very keyed into the cul­ture of their work, they’ll find ways to make the money work a lot of the time, or at least longer than you’d think.”

I have kept this quote with me since first hear­ing it many, many months ago.  It is a very sim­ple state­ment, but there are some enor­mous truths lurk­ing behind it.  If you are an infor­ma­tion worker, I highly rec­om­mend lis­ten­ing to or watch­ing Merlin’s Rutgers talk or his Inbox Zero talk at Google.  Or heck — buy his book when it’s avail­able.

Posted in: Dear Diary Quotes Work