Thursday, April 2, 2015

Rational superstition

A couple days ago, I was ready to upload spanking new code to its web server, to find that the FTP server wasn't accepting my password.  Just in case I was imagining things, I ran through every single password this hosting account has had during its history.  No joy.

I won't mention the name of the web hosting provider, but let's just say that they're middle of the road.  By which I mean not the kind of outfit that will ride out Global Thermonuclear Armageddon with five nines, but not bottom-feeders catering to spammers either.

So I logged into my account and went to the control panel interface to reset the FTP password.  Or tried to.  Instead of being automatically passed through from the main account page, I was again challenged for a password, and again every possible option failed.  Now I haven't changed the password, so the "Who's been eating my porridge" alarm bells went off.  Mercifully, I still had sufficient access to my account to be able to submit a support ticket.

This is where my experience as the resident SysAdmin comes in handy--not so much that I have all the tools I need to debug the problem, but that I can speak the dialect of those who do.  Which includes having a good idea of what they might need from me, and trying to supply it before they even ask.  The preliminary diagnosis was a blacklisted IP address.  Because I'm in Canada talking to a U.S. provider, I guess that wouldn't entirely surprise me.  (Nothing crosses the border easily these days, don'cha'know?)

But upon further review, my IP address was found to be above suspicion, and seeing no other flags, the support tech simply rebooted the firewall and the problem disappeared as quickly as it had appeared.  Rather like one reboots a PC/laptop to "fix" an intermittent, unexplainable problem.  Or we reboot the router when we know darned well that Rogers (our ISP) needs to replace the gerbil powering their DNS servers.  Or how I deal with a repeatedly crashing text app. on my Android phone by restarting it.  Or back up email before installing system updates.

Bottom line is, even if were able to run any gremlin to ground, we still might not be able to chivvy it out of its lair to finish it off.  At least not without a lot of collateral damage.  Simpler just to reboot, as though the process is some ritualised purification ceremony that exorcises the demons.

Sigh.  As much as I'd like to believe that we I/T folks are ruthlessly logical and relentless in pursuit of root causes, we don't often live up to the standard.  Granted, we're nowhere near as superstitious as some breeds--notably actors--but I can rationalise it as efficient laziness, yes?

Monday, March 30, 2015

"Back to the Future": The coding version

So there's this.  Tongue firmly lodged in cheek, I call it "The Mark I" (code name "Sylvester.")


See, over the past 10 years, we've tried training Mister Kitty to stay off the counter.  With the result that he's merely become progressively stealthier about it.  Which basically makes it an arms race.  Opening a new front in the war, the "Mark I" compensates for our less-than-preternatural hoomin hearing.

The thing hanging off a mini-USB cable at the top right is a programmable microcontroller (an Adafruit Trinket).  The green rectangle with all the pin-holes is a mini-size solderless breadboard, used to connect all the pieces.  The white square inside the green rectangle is a passive infrared (PIR) sensor.  The black button under the yellow and blue wires is a Piezo element (for making sounds).  And a pushbutton is trying to hide under the second blue wire.

The microcontroller is programmed to listen to the PIR sensor for the signal that it's detected movement of a warm body within its radius of operation.  Finding movement, the microcontroller has the Piezo element play a few bars of Tweety Bird's song ("I tawt I taw a puddy-tat...").  The pushbutton arms and disarms the device.

Crude?  Sure.  Ugly?  Yep.  But it scored its first success this morning when I busted His Doodness.  One yell and he was downstairs, not to be seen for a couple of hours thereafter.  The hope is that eventually he'll realise the futility of his schemes and keep his filthy litter-clogs off the counter.  And then I can re-use all the parts in other projects. 

As a programmer, this sort of project is something of a departure from the norm.  For one thing, software takes second place to hardware.  As the builder, you're responsible for making sure all the circuitry works and you don't fry components, blow fuses, or burn down the house.  That's not something that I normally have to worry about, even when, say, adding more memory to my PC.

But even the software side takes some getting used to.  It's not the language (which is a variant of C++, something I learned back in Programmer School) that's the issue.  It's the confines of the platform.  The Trinket's hardware isn't too far ahead of what went into 80s arcade games.  So you're not going to be writing the War and Peace of computer programs, right?

More significantly, there is no operating system--the processor merely runs the same program over and over until power is interrupted or new code is uploaded.  Now, if you've never written code for a web browser or a smartphone, the only thing you need to understand is that both these environments are set up to be able to do several things at once.

For instance, when you type a search into Google, each time you type a letter, the web browser goes out to a Google web server and lets it know what's currently in the search-box.  The web server responds by sending back its best matches.  That's how the results can change even as you type.  The major point is that the browser can listen for your key-strokes, fire off its information, and present the results as three loosely-connected processes.  In a word:  Multi-tasking.  Just like we easily-distracted hoomins can do.

The Trinket, by contrast, can only do one thing at a time.  In the case of the "Mark I," for instance, it can't listen for the reset button while a note is playing.  So I have to sneak in a check on the button's state in between notes.  But even then I have to be precise about the timing because the button needs time to "debounce" (don't worry about the definition of that--it's not important) and I have to make sure that doesn't add too much of a pause before the next note.

It took more error-and-trial than I should probably admit to, just to make something relatively simple like that work.  I suspect that the browser/smartphone mindset I've lived in for over a decade has a lot to do with that.  Unlearning is always harder than relearning.

Trust me, I'm absolutely not whining.  Back when the Trinket's processing power would have been considered cutting-edge, I would have had to program it in Assembler.  Which is the coding equivalent of building the Taj Mahal one Lego at a time.  Maybe that's what hipster programmers do; I dunno.

But I will say that having this little thing basically kick my butt is actually pretty fun in a "retro" sort of way.  Building like it's 1982...partying like it's 1999.

Friday, March 27, 2015

Frivolous Friday, 2015.03.27: Geeks and Bees

The winters of 2013-2014 and 2014-2015 have been a double-whammy for bees.  At least in our backyard.  Damp autumns, soggy plus dangerously late springs.  I'm not holding out much hope for the handful of hives barely visible in the backyard.  And I'm not at all happy about paying a ridiculous price to basically start from scratch in less than a week.

See, the problem is that the go-to source for imported honeybees, a.k.a. the United States, is pretty much off-limits (some Queens excepted) because of parasite/disease issue (and no doubt the usual tribal stupidities besides...glad we passed NAFTA and all...).  The most logical Canadian sources (Vancouver Island, southwestern British Colombia, and southern Nova Scotia) don't seem much interested in filling the gap.  Or, for all I know, they're just overwhelmed.  So obscene amounts of fossil fuels are expended to import honeybee "packages" (basically starter colonies) from--I kid you not--New Zealand.

From what I can see, the importers (at least the ones we're working with) are almost gratuitously conscientious about it all--even escorting the bees on their journey and making sure they're fed and all.  I'm not knocking them...however much I might envy their trip to New Zealand this time of year.

Okay, so I'm willing to meet Mother Nature more than halfway by tilting at the windmill of keeping honeybees alive into the next spring by dint of making sure they're healthy and well fed (to the extent that such contrary beasties will allow me to intervene).   I'm certainly not above hacking besides.  (Mind you, with electronics--i.e. logging temperature & humidity readings--you're fighting the triple-whammy of unreliable power supplies, the even less reliable elements, and the bees' propensity to shellac everything that's not comb with a substance known as propolis.   Making it all affordable for beekeepers working on precarious margins is another subject altogether.)

Those are the challenges.  But I would take it kindly if the governments of Canada and the United States would, in tandem, extract their craniums from their backsides and figure out how allow healthy, cold-tolerant bees to cross the border in volume.  Even back in Wisconsin, I found the reliance on southern (by which I mean less cold-hardy) bees silly.  Particularly when some of the most notable pollinator research in the U.S. is being done by the University of Minnesota.  I would argue that, all other things being equal, regional boundaries count for much more than national ones.

Given that one out of three bites we take has to be pollinated, my left brain fails to grok how this sort of thing is not a priority for any government.  Particularly for a government so obsessed about national security that it has time to care about who wears what during a citizenship ceremony or is willing to bomb people on sketchy second-hand rationales or wants to classify anything threatening the economy of Canada as "terrorism. "

Thursday, March 26, 2015

Trinity

Triads such as those that show up in medieval poetry were, as I understand, a memory device.  And, of course, three is a magic number in a lot of places--literature, religion, what-have-you.

The trinity upon which I sort of bumbled now--prompted by a passage from the somewhat fluffy and unconvincing first novel of The Dresden Files--has to do with one's life as a craftsperson.  Even in a mostly intangible craft like mine.

Student - We have to start somewhere.  But we need to step into other levels as quickly as possible, or it's all just academic.  Worse, we never gain any meaningful confidence.  That only comes from stepping beyond the pre-fabricated exercises, failing, figuring out why, and (hopefully) fixing.  And while it is a dangerous thing to expect to be in this mode indefinitely, it is more dangerous still to think that everything is still ahead and that you have nothing to share with anyone behind you in the journey.

Practitioner - Now we've learned to do something...probably many related somethings.  If we don't know exactly how just yet, we can look it up...or piece it together from StackOverflow, tutorials, YouTube, whatever applies.  Often, we can get by on understanding the "how" more so than the "why."  It is a dangerous thing now to think that we are forever past the Student phase.  It makes us afraid of mistakes which makes us afraid of experimenting, and too attached to what we already know.

Teacher - Stepping into this role should be profoundly humbling.  Humbling by dint of sheer panic and frantic research when we realise that our understanding is not nearly so fleshed-out as we imagined.  Because teaching is ultimately an exercise in creating context in which knowledge can be transferred from experience to inexperience.  This forces us to verify things that we took for granted as Practitioner--taking us full circle back to Student and probably Practitioner besides.  Or should, anyway.  Because if it doesn't, that's the most dangerous state to remain for any extended length of time.

And so the healthiest head-space for any craftsperson to live at any given time is all three. Learn. Do. Teach. Repeat.


Monday, March 23, 2015

Whimsical chagrin

A reminder from Dennis reading aloud to me while I was washing dishes after he made dinner tonight:
"From a drop of water," said the writer, "a logician could infer the possibility of an Atlantic or a Niagara without having seen or heard of one or the other.  So all life is a great chain, the nature of which is known whenever we are shown a single link of it.  Like all other arts, the Science of Deduction and Analysis is one which can be acquired by long and patient study, nor is life long enough to allow any mortal to attain the highest possible perfection in it.  Before turning to those moral and mental aspects of the matter which present the greatest difficulties, let the enquirer begin by mastering more elementary problems."
- Sir Arthur Conan Doyle, A Study in Scarlet

Welcome to computer debugging, Mr. Sherlock Holmes.  Only in place of that drop of water substitute "It doesn't work!" and you'd be perfectly at home in the 21st century.

Wednesday, March 18, 2015

Vicious cycles, Part II

Back in 2009, when "Views from the Bridge" were but a wee lass, I poked fun at a weakness I share in common (solidarity?) with other crafters--namely, the infamous Designated Tote Bag Syndrome(TM).  As it turns out, I was being too narrow in my satire. Because, apparently, it's not just a crafter thing.

Alas, the Moncton area's options for dealers in off-the-shelf electronic components is pretty thin right now.  Also, the loonie-greenback exchange rate being what it is(n't), it's becoming more expensive to mail order certain kinds of stuff.  And, as always, the wanna-be mad inventor can also expect to pay through the nose on shipping.  That confluence of costs makes bulk-purchasing more attractive.  Even for a tight-wad such as your faithful blogger. 

So, pitting my frugal Upper Midwestern upbringing against itself (i.e. saving money by dint of spending money), I ended up with eight programmable micro-controllers (a.k.a. "Trinkets"), because at that quantity they were under 10 loonies a pop (ignoring tax and shipping, as our consumer-geared brains are wont to do).   Those micro-controllers, however, aren't much use to me without a mechanism to plug them into something--in my case, a breadboard. 

But the good folks at CE3 pointed me to BJW Electronics, who were happy to solder headers onto them.  (For the record, I'm not deep enough into this hobby to justify a soldering iron plus accessories.  That, and my Mom still has the toolbox I tried soldering for her in middle school Industrial Arts, and it's frankly embarrassing--like Nidavellir collectively sneezed on cheap sheet metal.  But that's just how Moms roll, so...#whaddyadoamirite?)

That all--again minus HST and whatever shipping costs are associated with me picking them up myself--added about five loons a pop.  But it's still better than the $30-40 CDN you'd pay for a full-blown Arduino, yes?

I already have two--okay, probably three--projects earmarked specifically for the Trinkets, and I assured myself that the other six or five will come in handy.  Sometime.

But then I thought of Halloween.   

And how I can certainly figure out how to make red, white, and yellow LEDs imitate candles in lieu of waiting for the Grande Digue winds to (inevitably) blow out the usual tea lights inside the Jack-o-lanterns.   

And there's no reason (apart, of course, from rain) why the LEDs couldn't be triggered by a passive infrared sensor.   

And as long as I have to pay postage for a PIR sensor anyway, I might as well get a handful.   

And at that point, it might make sense to have another PIR sensor trigger a servo-motor to loose a gravity-propelled "ghost" on a guy-wire strung between the pine trees and our front door.

Aaaaaaannnddd....

My Gentle Reader sees where this is heading, right?

The problem is, now I definitely don't have enough Trinkets to make this happen.  And the irony of it all is that we average two sets of trick-or-treaters per annum. 

But that's just the problem.  With some people, the means infers the motive...and then the motive infers the means...which then again infers the motive...and so on.

Culturally, I suppose, it's a good problem to have.  Except for when the credit card bill arrives.

The unresearched project is not worth doing*

I've been hoping that Clay Shirky's low profile on his blog means that he's flogging away at the keyboard on another book.  Frankly, I'm jonesing...to the point of re-reading Cognitive Surplus for, like, the fourth time.

Chapter 1 reminded me of the McDonald's milkshake research project.  (And, unsurprisingly, the engineer's urban myth about General Motors's vanilla ice cream problem**.)

But what do fast food and cars have to do with software development?  In a word, problem-solving.  (Okay, maybe that's two words...except when I cheat by hyphenating.  So there.)  Anyhoo, problem number one is making sure you're solving the right problem in the first place.

In the case of McDonald's, their problem was lacklustre milkshake sales.  The obvious attack vector on the problem is of course, experimenting with the formula and taste-testing it.  That gives a number of variables:
  • Sweetness
  • Flavour profile
  • Consistency
  • Mouth-feel
  • Temperature
The problem is, McDonald's could spend millions of dollars in the lab tweaking the formula along multiple axes.  But what if the formula is not the issue? 

As it turned out, 40% of milkshake sales were purchased not as a dessert or treat, but as a commuter-friendly breakfast***.  The milkshake could be consumed one-handed, didn't leave crumbs (or stickier things) on the car (or commuter), and had more staying power than a doughnut.  Moreover, milkshakes, because they take longer to consume, had the added value of providing frequent (momentary) distractions during heavy traffic:  
  1. See the car ahead start to roll forward...
  2. Accelerate...
  3. See the brake lights of the car ahead come on...
  4. Step on the brake...
  5. Pause...
  6. Reach for the milkshake...
  7. Sip...
  8. Put down milkshake...  
  9. Aaaaaaaannnnd repeat until the commute or milkshake run out.
Not surprisingly, the researcher who identified the important commuter demographic (Gerald Berstell), didn't do that from inside the lab.  He sat in a McDonald's for 18 hours for that epiphany (among others).  And then came back to quiz customers--not about how they thought the milkshake tasted, but what kind of problem it was solving for them.

And while I'm sure that Mr. Berstell's time and observational skills don't come cheap, they're infinitesimal compared to a whole bunch of biochemists and nutritionists and marketers flailing around in labs and focus groups.

Moral of the story?  Research done before the project starts is cheap--dirt-cheap.  In fact, it has a negative cost when compared with the cost of solving the wrong problem. 

- - - - -

* A nod to Socrates' "The unexamined life is not worth living."

**  Snopes classifies the story as "legend," but it's a fun read and far too believable because there's no substitute for hands-on debugging.

*** Clay Christiansen, Scott Cook, Taddy Hall, What Customers Want From Your Products - Harvard Business Review, 16 January 2006