Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.

2013/12/16

My Body Goals For 2014

I've established my priorities previously. This is to establish the goals that flow from those priorities. This is where the priorities interact.

 There's little in this that independently affects brain power (that I know of), so there's nothing here that I'm marking with (Brain), but otherwise, in order, here are my body goals for 2014:

  • Significantly greater range of motion for my right foot, less pain from both feet (Feet)
  • Weight of less than 200 lbs. Waist of 32 inches or less. (Weight/Body Fat) 
  • Meeting daily steps goal of 6000 daily. Raising to AHA-standard 10,000 steps and meeting that. (Feet,Stamina/Endurance) 
  • At least one 5K race completed in 40 minutes or less. (Stamina/Endurance) 
  • A set of ten standard push-ups (Strength) 
  • One successful pull-up or chin-up (Strength) 
You will notice no specific dietary or exercise regimines here. This is because I consider then as "plans", not "goals". You take on Paleo or Slow Carb or Atkins or whatever in order to take control over your weight, not as a goal in and of itself. You might become a Vegetarian for political/humanitarian reasons, but then "Stop participating in cruelty" is the goal and eating a Vegetarian diet is your plan to do fulfill that goal.

Significantly greater range of motion for my right foot, less pain from both feet (Feet)

As previously mentioned, my feet are weird. My left foot shows -- showed? It's been a while since I saw the doctor -- signs of pronation and bunions, but my right foot is far far worse.

It is my belief that it has always been worse and I just never noticed until 42 years in. It might be the case that I can't fully fix the problem without surgery, and any invasive surgery is problematic and likely to leave it in a continually compromised state. I intend to use stretching and other non-invasive means to get it worked out.

Related, though, is the fact that the mere fact of hitting the American Heart Association's recommendation of 10,000 steps leads me to believe that my years of neglect as a mostly-sitting student and computer professional has caused muscle atrophy in my feet and ankles, and an amount of physical therapy that'll lead me through pain is necessary before I get to where they're where they should be.

I'm finding that, while my ankle hurts when I start moving, once I'm going for a while, the pain subsides. I'm thinking that I have to move more all the time to get my ankles to a better point.

Weight of less than 200 lbs. Waist of 32 inches or less. (Weight/Body Fat)

I am on a downward trend, and the evidence tends to show that I have more to lose if I keep the way I am, but I'm into a time where many people hit a plateau due to the increased consumption around Christmas and the decreased activity due to Winter. I expect this, I hope to work against it, and I expect further loss come Spring. I suspect 2014's weight loss, unlike 2012 and 2013, will be something I have to work for.

I'm tossing in a Kickstarter-like stretch goal of getting and staying within 5 lbs of 180. I think much less than that and I'll look like a bean-pole, but we'll see.

Meeting daily steps goal of 6000 daily. Raising goal to AHA-standard 10,000 steps and meeting that. (Feet,Stamina/Endurance)

I dropped my daily steps goal in FitBit to 6000 steps because it seemed doable without heroic measures, and while I often have spike days above the goal -- even above the 10,000 step goal -- but weeks where my daily average is above 6000 are rare, and weeks when my worst days were above 6000 steps just do not exist.

Kinda goes with the first goal, and certainly relies on it. If my ankles and legs aren't happy, I won't be pushing myself to move.

At least one 5K race completed in 40 minutes or less. (Stamina/Endurance)

As mentioned before, I've "run" a 5K with a time of 45 minutes. I'm happy with it -- I came, I saw, I didn't stop, I got the t-shirt! -- but I believe I can do better. So, my goal here is to prove it.

A set of ten standard push-ups (Strength) 
One successful pull-up or chin-up (Strength)

I am grouping these, as they are predicated on upper-body strength. There's a bunch of core in pushups, but that isn't my primary reason. I've been trying to keep body weight squats in my endurance work, like ten squats every lap, but I don't have a strong way to gauge that, nor a strong reason (pun intended) to work on it. (Did a 5K nature run followed by some Cross Fit including squats, and the squats made my thighs ache for the better part of a month. That is why I do squats.)

I also intend to get my form together for burpees (a perfectly sadistic exercise in it's own right, one where my form so far has been spastic and ill-disciplined), but that's that would be nice, not I will do this.

Up soon, at least before New Year, is my plans to achieve these. After that, progress reports as I knock these things down.

2013/12/10

My Body Priorities for 2014

I can see myself with a MacBook
This is not to take the form of a set of premature New Year's Resolutions. Resolutions are code for promises to yourself that you will not keep, and I have never wanted any part of that.

This is to take the shape of what I want to change about myself, which will then lead to behaviors I want to develop or cease. The scheme for behavior modification will come, but it will not be "Starting January 1, I'l stop drinking caffeine and stop eating sugar and run 5 miles every day and lift weights and read a book a night and get to sleep before 10pm and wake up at 5am..." Willpower is a finite resource, and you can burn through it this way.

So, my priorities, in order of importance:
  1. My Feet
  2. My Brain
  3. Weight/Body Fat
  4. Stamina and/or Endurance
  5. Strength
Two years ago, I stopped drinking colas and lost over 40 lbs, started sleeping better and felt good enough to start a Couch-to-5K process that lead to me finishing a race. Almost five months ago, I moved to a standing desk, and while that really sucked for quite a while, I'm happy with the results. So, I think I'm past all the outstandingly stupid things I was doing to myself, which means I'm out of shortcuts. Doesn't mean there aren't efficient and smart ways of doing things, just that the no-brainers are done and I'll have to start burning willpower.

My Feet: Two years ago, my youngest participated in a hike with his Cub Scout pack to commemorate the 200th anniversary of the Battle of Tippecanoe, and at the end of it, I noticed intense pain between the smaller toes and the outside of the ankle, which kept with me for several days after. I went through similar pains as a volunteer at an Independence Day 2012 celebration, and as part of my Couch-to-5K process. 

Eventually, the sharp pains in my foot lead me to a podiatrist, who told me had pronation in my left ankle and extreme pronation in my right. They're also pretty flat, to the point where I used to be able to make fart noises with my right foot coming out of the shower. Right now, my feet, mostly my right foot, are the limiting factor for most of my attempts at further fitness. It's one thing, for example, to keep running when you're sweaty, wheezing and tired, but it's another thing when each time you push off, it feels like someone's shoving a knife into your arch.

So, my goal here is to develop stretches and exercises that make my foot less flat, less pronated, and less painful. This is a primary things: I can't really do much with many of the later goals without making progress here.

My Brain: Exercise increases your brain power, and as a programmer, my brain is my most important feature. If I didn't believe that exercise helped my brain, I wouldn't be doing half of this or writing this. This article mentions benefits of both cardio and strength-based workouts, so more activity of whatever stripe is 

Weight/Body Fat: By memory, my top weight was 330-350 lbs. Top weight I recorded is 270 lbs, in Feb 2012. I am 217 lbs as of this morning. I no longer have a double chin. I wear a Large t-shirt (after 20+ years in XL) and 34x34 jeans.

But I still have a gut.

Teenage me could not imagine having six-pack abs. 30-year-old me was befuddled at how he could eat like he did and still be over 300 lbs, and couldn't even begin to imagine something like muscle tone or a lack of love handles. 43-year-old me is beginning to see it.

So, exercise plans will be chosen with an eye to fat burning as priority, but really, it seems to me that this is more a diet thing. Right now, I make breakfast and lunch decisions mostly based on economics and convenience, which means oatmeal for breakfast and microwave Banquet for lunch. My thought is to go with a Slow Carb diet, but I will need to work out how to make it work around my requirements.

A word on "diet": Popular usage has "diet" meaning a temporary change in food intake to achieve a certain outcome. This is not the correct meaning. When they say "A panda has a diet of shoots and leaves", they mean a panda only eats those things, all the time. When I say I'm considering the Slow Carb diet, I'm saying that I'll commit to it, the way I committed to not drinking sodas.

Stamina and/or Endurance: I mentioned running a 5K earlier. I'll add scare quotes and say "running", as I spent much of that race walking, giving me a 45-minute race time. My goal on this is to do at least one 5K this year, where I do a time of less than 40 minutes. I want to spend all that time running or at least jogging, with no energetic walking.

Endurance, as I understand it, relates to having enough to keep going through the race, while stamina relates to having enough to keep you going at maximum capacity. Endurance is for marathoners while stamina is for sprinters. I think what I have is neither and so could use a little bit of both.

Strength: At the previously-mentioned Independence Day celebration, one of my tasks was to move staging, including choir risers. These risers are built to stand the weight of several choir members, and are thus solidly built. I thought I had it in my to lift a riser to stage level, and I just didn't have it in me to do so. I had said that there was nothing in my life I didn't have the strength to handle, and this proved me wrong.

My goal is not bulk; I don't want to look like Mr. Universe. I just want to have reserves of strength when I need them, and I want that strength across my body, not just in my arms and upper body. This means squats and lunges in addition to curls and lifts.

My current objection to strength training is that it's hard to quantify like you can with endurance training.

From these priorities, I will develop plans, which I will put here and document my progress. Any ideas and suggestions, both on what to do and how to keep motivated in doing it, will be appreciated.

2013/12/09

Something That Makes Me Sad, But Probably Shouldn't


Saturday was a good and incredibly geeky day for me. I went to the Indy Quantified Self Meetup, held in one coworking space, spent much of the afternoon in Fry's, where I met someone and talked about a startup idea (planned meeting, not happenstance), then went to Indy Hackers' Holiday Social, held in another coworking space. I listened to tech podcasts all of the way down and most of the way back. There's geeky things I didn't do (converse with my good geek friend Patrick) and otherly-geeky things that aren't for this blog (went to two guitar stores).

It was a good day, but there's one thing that wasn't so good. Maybe.

Above is the entire technical book stock at Fry's Indy. The entire shelf. There's lots and lots of shelves, and once, they were filled with all sorts of technical books. It fills my heart with joy to see a wall of O'Reillys. For the longest time, my first-pass rule for judging a technical project or tool was "Is there an O'Reilly book for it?" The books for learning Perl are Learning Perl and Programming Perl, and I judged Python harshly because the book a Python person would suggest is not Learning Python.

These days, though, your first pass for a technical question is asking Shub-Internet and ending up with a discussion thread, IRC log, or hopefully a Stack Overflow answer. I have editions 1 through 4 of Programming Perl, and they are decreasingly dogeared and beverage-stained as time goes on. I haven't really dug into Programming Perl, Fourth Edition, in part because I know how to write Perl, but in part because, even when I don't know what I'm doing, dead trees are not my go-to.

And, even from the perspective of the writer, writing tech books is a losing game. Jeff Atwood of Coding Horror writes about it when pushing a book, ASP.NET 2.0 Anthology, that he contributed to. xkcd did a comic (which I can't find) which compares the staying power of different book types, grouping math and physics texts as books that can stay without revision for decades, sometimes centuries, while a book on a language or protocol will be out of date very soon, sometimes before publication.

So, it would make sense to have Knuth's Art of Computer Programming on your shelf, but less so Perl, much less Perl 5.18.1. So, it would make sense to publish Art of Computer Programming on paper, but to generate and regenerate language documentation into electronic form.

And really, at places like Fry's, you want as much floor space devoted to things that can only be atoms, like motherboards, cases, LEDs, cables, trackpads and MacBook Pros, and things that can be bits should be bits. Plus, of course, the fact that you can put a whole lot of bits into your tablets and newsreader.

So, I can rationalize it at length, but it still saddens me to know that the world I used to live in, where there were places where a wall of amazement and possibility was available to me. I guess it outs me as a geezery geezer who geezes.

2013/11/27

Why Yahoo is Sad for me

In a perfect world, I would be able to wrap up my tools in a little bundle. I can't. We've made a decision to have one lib directory and put everything in it. So, we have our blessed jQuery, jQuery-UI, Mustache.js, etc. And, we don't use every library in every web app. So, this means for one JS-heavy page, I'm calling those three, jQuery TableSorter, HighCharts and a theme, plus my library which calls that.

Well, really, I can and should pull out the HighCharts libs, as we no longer plot on that page. Which makes things even worse. I call seven (now 5) libraries to do this work which ySlow considers excessive. But because I don't always use jQuery-UI and Mustache, I can't just make and minify a std_lib.min.js with everything put together.

This is where I get a B.

Even worse, I don't run everything through GZIP. (F.) I also don't use a CDN. I am using SSL now, and it seems that SSL and CDNs are mutually exclusive, as everything that doesn't come from your https server is a possible security issue. Even then, almost everybody who is going to use this data is going to be in the same lab. Still, F.

And we're not going to get into how I'm not going to play with the Apache config to get Expires headers (F) and Entity Tags (F).

And we have our Lab Notebook, the place where we store all our work, in OddMuse. And OddMuse remembers who you are with a Cookie. Not having written OddMuse, I can't change that. Not having a good alternate choice, I can't change to another Wiki. So, there's one cookie. (D)

I know that Yahoo's problems are not my problems. Honestly, while I got a grade of 77 (C) on the page as a whole, I know it's one of my better websites, because it handles only a small chunk of data at a time. And really, I'd rather work with my unminified JS so if problems arrive, the JS console will give me a sane reading of where the problem lies.

So, I'll take that Charlie and proceed to the next problem.

2013/11/07

Counting Hashtag Usage with R

Found this on the Revolution Analytics blog: What does Barack Obama tweet about most? In essence, pull down all the tweets from the official Twitter feed for the President, grab the hashtags and create a bar graph.

I don't often use R interactively. I generally make a script, set it in crontab, and have it run automatically. So, I adapted it to run via Rscript.

2013/09/03

Bug in Perl? Or am I just doing it wrong?

Three modules: MyTools::Foo, MyTools::Bar and MyTools::Blee. Foo primarily exports foo(), which returns "foo". Bar, similarly, exports bar() which returns "bar". Same with Blee.

Foo also exports foo_bar(), which concatenates the output of foo() and bar(), and foo_blee(), which does the same with foo() and blee(). Bar has bar_foo() and bar_blee(), and Blee has blee_foo() and blee_bar().

Here, the library holding MyTools is identified using the PERL5LIB environment variable. I do this to model a problem shared by a suite of modules that have spaghetti-like tendencies to interconnect with each other. Previously, I had used use lib '/path/to/lib' to do this purpose, but the need to start using git and the like has pushed me toward using a means to identifying library paths without hardcoding them.

I haven't developed the test case such that, using use lib, it works, but my production uses lib all over the place, and I only noticed the problem when I copied it to a dev directory and pulled those lines.

The problem I'm seeing is that Perl starts to look for foo() in Bar or Blee, when foo() is in Foo. Clearly, It'd be better if Foo didn't include Bar and Blee while Bar included Foo and Blee, etc. It would be nice if I had separated the code better in the first place, but seeing that the code base where I started finding this problem is 19 modules with over 8,000 lines and is used across several systems by someone else, so every change has the potential to break my lab's workflow, I can't really disentangle it right now.

So, it strikes me that Perl is wrong, too. (I fully admit that my code is an unruly hairball. I'm starting to pay that technical debt right now.) I'm somewhat loathe to tag this as an error in Perl and start filing bug reports until someone with more direct experience looks at this and says either "That's odd" or "Dave, you're a dumbass." I would certainly accept either answer.

So, am I wrong?

2013/08/21

Caller ID, Time and Temp with Twilio

The other day, my wife got a new phone, replacing her shattered iPhone 4 with a new LG Optimus. The problem is, by rotation, the upgrade was for me, so the new phone was to have my phone number. They moved it to her phone number, but that left me disconnected from the cell network. At least, I knew at the time I was disconnected, but I was less than sure that her phone was using her number.

My thought was, "It would be nice to be able to call someplace and have it tell you what number your phone is, so we could be sure." So, I wrote something.


This uses Twilio, which is essentially an API into IP telephony. I've used Twilio before, and have two projects on GitHub, Call_Me and SMS_Me, that are generally unidirectional messaging tools, but I haven't done much interactivity with the tool.

It gives the following output, which Twilio then runs through text-to-speech.


The time is currently 4 37 pm

The temperature in West Lafayette is 83 degrees Fahrenheit.

Your phone number is 1 2 3. 4 5 6. 7 8 9 0.

A few notes on the formatting first. I separate the numbers of the phone number (and that is not a real number) so that it says the number with an expected cadence. If I just put 1234567890, it'd say one billion, two hundred twenty three million, five hundred sixty-seven thousand, eight hundred and ninety. If I just broke it up to 123 456 7890, it'd say one hundred twenty three, four hundred fifty six, seven thousand eight hundred ninety. To break up the numbers so it just says the digits, you need to put the spaces. To break it up so the area code and exchange and line numbers are distinct, you need the punctuation.

Times are weird, too. If the time is 4:37, just having the time as 4 37 works, but if the time is 4:05 and broken into 4 05 instead, it'd read it as four five. This is why I use digit letter-"o" digit for the time.

I say lots of bad things about XML and prefer to avoid it when possible, but sometimes, like here, it's just that easy to handle. Kudos to XML::LibXML and NOAA for making that part reasonable and good.

Now that I have this working, I'm curious about doing other things. I can see myself adding to this, checking to see if From is my number, and if so, opening up choices like my whole Quantified Self stuff, the home automation I want to do more of, etc. I'm not sure I like the TwiML module, and might move that over to Template Toolkit, but that remains to be seen.

2013/08/12

Coding Yourself Into Shape

Today, I've hit a new low.

224 lbs. This is as low as I've been in a great long while.

I've been looking and thinking about this graph for a while and have come to some conclusions.

I ran some last year and it didn't help much. 

The first day I was under 240 (the orange line, separating overweight and obese for my height on the BMI index) was October 7, 2012. (I get that it's problematic because Fat Albert and in-his-prime Mike Tyson were about the same height and weight, but there's a huge difference, pun intended, between their body composition. When people start mistaking me for a heavyweight champion, I'll start worrying about being placed wrong on the BMI chart.) I started running at some point in the summer and mostly ended after a 5K I participated in on August 25. The trend line for weight doesn't change significantly, sticking with the ~1lb/week during that time.

Be aware that this is self-tracked, and there are some days where I forgot to weigh and some weeks when I was unable to check against my scale, and this version of the graph does not show the gaps.

So, what did help?

The majority of my weight loss during that time is probably attributable to drinking more water and less caffeine.


There were certainly times when I lived off the stuff.
In April 2009, I started to think about all the bad things they say about caffeine, as well as all the good things, and decided that I'd go cold turkey, test it out on myself and see for myself.

The first day, I took my boys to a pizza place with a soda fountain, and I had two cups of Diet Coke before I thought about it. The second day, I did much the same. This is why we call it a habit, because we start continuing behaviors because that's what we do.

The third day, I remembered and went without anything.

The fourth day, my co-worker looked over at me, with my area's lights off, hunched over, nauseous and with a head that felt like it was exploding, and told me "If you have the flu, you should just go home." I gave up. But I started cutting back. Way back.

Right now, I tend to drink two cups of coffee a day, only on work days, and never on work days. Sometimes maybe a cup on Sundays, but rarely.

The way I think of the problem with cola, even diet is:
  • As I got from Tim Ferriss' Four Hour Body, Never Drink Calories
  • We put artificial sweetener into our drinks in order to trick our tongues into thinking the drink is sugary and therefore tasty. Current thought is that our pancreas is similarly tricked, thus creating large amounts of Insulin and storing our calories as fat. 
  • The body works better with sleep. When you caffeinate, you mess up your sleep. When you don't get good sleep, you get fat.
  • If you don't drink it all the time, there's withdrawal, which give the flu-like symptoms I describe above. I heard a story about how a person's mom tried to get his dad to switch to decaf on weekends, and the illness and headaches almost led to them getting a divorce. Part of what I began to realize was that I was having the same effects, and sometimes still do. 
I have never really trusted the bad things said about Aspartame, but there's enough here to make me choose water over cola every time.

You should never be hungry.

Time was, I would only eat dinner most days. Beyond what it might've done to slow my metabolism, it made me famished by the end of the day, and, as I was either a CS student or a developer for those days, and willpower and cognitive processing draw from the same pool, by the end of the day, as I was exhausted, I made stupid decisions, ate as much as I could, then fell asleep.

Right now, I eat cheaply and probably not right — generally a packet of oatmeal for breakfast and a $1 TV dinner for lunch — I always eat, so I'm never so famished that I couldn't say "no" to the promise of a snack, or to thirds. I don't always do so, as I'm a weak, weak man, but I'm better than I was.

Eventually, you get all the benefits you're going to get for one change.

The story from October to the middle of summer is pretty much +/- 5lbs from 235 lbs, which is pretty much stasis. (Reading Back, that doesn't make sense. Trying to rewrite) The sudden drop at about 375 on the graph above (I really need to put dates into the graph!) occurred over Christmas/New Years', when I was away, visiting with family. Days out and about with my family in Nevada are different than snowy days in Indiana, so that shows that other changes in diet and exercise made more difference at 235lbs than they did before.

My newest changes are more exercise — I try to make it to the gym three times a week but usually more hist twice — and less carbs — as suggested by Randal Schwartz, I tend to eat the toppings off pizzas but leave the bread alone, and not just the crust — and those are leading to the current drop. We'll see how far these take me.

Your body is hackable.

The graph above and the data it shows exist because I read Tim Ferriss' book, The 4-Hour Body. I'm not doing everything in it — it's probably accurate to say I'm not doing anything in it — but most everything in this post started with me trying to affect the inputs to the black box that is my body and trying to get different outputs.

The graphs and the core of my first approach has been mostly inspired by John Walker's Hacker's Diet. My graph shows a several-day rolling average, but not a weighted average like Walker suggests, because that was the limit to the amount of SQL I knew.

My goal right now is to get to and stay at about +/-5lbs from 200, and I think I can do that. My other goal is to not be able to pinch an inch on my belly. I've been able to do that ever since Special K started showing that ad.

There's more things to change than weight.

In many ways, I enjoyed my time trying to build up to a 5K last year. I didn't enjoy all of it. There was intense pain, mostly in my right foot, and running on feet that hurt you is not fun. So, I went to see a podiatrist, who said that my left ankle is pronated and my right was even more so, so much that my right achilles tendon is in the wrong place. She made me orthotics. I personally don't think they did much good, and I stopped wearing them earlier this summer. Over the last few weeks, I've been using a home-made standing desk, basically monitors on top of the hutch and a box holding my keyboard up. I might get a purpose-built desk to replace this in the fullness of time, but this was mostly to prove the concept.

I have to say that, for the first two weeks, my feet were always sore. The problem wasn't the sole of the foot, but rather the arches going into the ankle. The interesting thing has happened in the last week: I've felt something happen with my heel which might be my tendon going back into position, and I'm pretty sure my ankle looks better and has better range of motion than it has in quite some time. So, for that change alone, I don't think I'll go back to a standard desk any time soon.

Making it a more public process helps with motivation.

When I make new milestones with my weight loss, I tweet my weight, linking to a JavaScript graph of my recent progress. I wear a FitBit most every day, and have code that connects to the FitBit API and also tweets my steps and floors each day. You can even follow me directly on FitBit. I even have my running tracker, Endomondo, post to Twitter and Facebook, even if I wish it wouldn't post the map.

I don't feel like running every day. I don't feel motivated to just eat the toppings off pizza every day. That people I know can know what I'm doing and give me encouragement is a major part of what I'm doing. (Learning how to make the graphs and sparklines and such is another big part.)

If you have something you want to change about yourself, the thing I would suggest is to break it into things you can keep track of, then go for it!

2013/08/07

Enemy of the State?

I've been glad for all the new life breathed into the Perl community starting with 5.10, but, honestly, there has been only one thing I consistently used in the raft of new stuff added: say. I disliked having to write print "$var\n" each time I wanted to print a line with a newline, and say allowed me an easy way to do that without changing the behavior of print.

But I've been trying out state.
state declares a lexically scoped variable, just like my. However, those variables will never be reinitialized, contrary to lexical variables that are reinitialized each time their enclosing block is entered.
That sounds like a winner, doesn't it? But it left me some questions.

I deal with SQL a lot, and so I have queries in my code. Sometimes, big queries. I'm wondering if assigning the SQL query each time is more costly, CPU-wise, than declaring it as a state variable and just holding it in memory.

#!/usr/bin/perl

use feature qw{ say state } ;
use strict ;
use warnings ;
use Benchmark qw{:all} ;
use Carp ;

use lib '/home/jacoby/lib' ;
use DB ;

my $sql = <<SQL;
        SHOW TABLES
SQL

sub outside {
    my $arrayref = db_arrayref( $sql ) ;
    }

sub use_my {
    my $sql = <<SQL;
        SHOW TABLES
SQL
    my $arrayref = db_arrayref( $sql ) ;
    }

sub use_state {
    state $sql = <<SQL;
        SHOW TABLES
SQL
    my $arrayref = db_arrayref( $sql ) ;
    }

timethese(
    10_000 , {
    'outside'   => sub { outside( ) ; } ,
    'use my'    => sub { use_my( ) ; } ,
    'use state' => sub { use_state( ) ; } ,
    } ) ;

DB.pm is my wrapper for the very complex DBI module, which gives me just three functions: db_do, db_hashref and db_arrayref. DB has %prepared, such that $prepared{ $sql } = $dbh->prepare( $sql ), so that, when using a query over and over again, a pre-prepared statement handle object is passed out.
Benchmark: timing 10000 iterations of outside, use my, use state...
   outside: 476 wallclock secs (14.66 usr +  8.21 sys = 22.87 CPU) @ 437.25/s (n=10000)
    use my: 475 wallclock secs (14.87 usr +  8.01 sys = 22.88 CPU) @ 437.06/s (n=10000)
 use state: 469 wallclock secs (14.68 usr +  8.14 sys = 22.82 CPU) @ 438.21/s (n=10000)
Looks like, in this case, it doesn't make a whole lot of difference. Still, good to know, right?

2013/07/30

Telling One Liners

I don't do a lot of Perl one-liners. In general, I think if you're writing Perl, you're going to want to repeat it so you should put it in a file.

I say in general, because I ran into a specific situation. For a plot-generating process, we 1) pointed to the version of the plot-maker that didn't use libcairo, so it couldn't be used without X11, and 2) accidentally removed lots from the completed file, where we list the plots we've done so we don't redo them, which lead to 3) remaking lots of plots that exist with a plot-maker that couldn't make plots, meaning files that existed got replaced with zero-sized files.

Once we figured out what the problem was, I wrote this one-liner, which ran for over an hour and 40 minutes.
for i in {1..100} ; 
do (
    ls -lS */nanodrop/*png | perl -lane ' print $F[8] if 0 == $F[4] ' | wc -l 
    ); 
sleep 60 ; 
done 
Basically, it looped over and over again to keep constant watch (the for loop), each time taking an ls -l (the -S, order by size, not strictly being necessary but left over from my initial checking), breaking it apart with Perl, printing the file name ($F[8]) if the file size ($F[4]) was 0. I pipe the output into wc -l,  which counts the number of lines. I then sleep for a minute (as the number of zero-length files was over 7000 at first run, the ls-l took quite some time, so the reports were much longer than a minute apart), and do it again.

Granted, I could've done it all in Perl, but why re-implement tools that exist in the shell when you don't have to? I could've done the Perl stuff in Awk, if only I knew Awk better, but I could get to the point where I knew the damage and the rate of repair much faster with tools I knew. Really, the only thing I needed to learn was that perl -lane was what I needed to get the lines broken easily.

2013/07/29

Making a CarPuter to step into the New Car

It's been a while since I've written on car computing — over two years, it seems — but that doesn't mean I've stopped thinking about it. The top reasons I would've wanted one in years past would've been for Entertainment and Communication, and I think everyone would agree that today, it's far better to just carry a smartphone than to embed one into your car. And, seeing how smartphones are changing so much so fast, doing more than adding the ability to interface with Bluetooth and/or USB to your vehicle seems silly, at least in short-term.

Navigation doesn't fare too much better, so although it's a toss-up whether dedicated units like Garmin and TomTom are better than smartphone navigation like Google Maps, both are accepted as better (more current maps, better interfaces) than in-dash choices.



I think the use that is least considered is recording. Dash cams are common in Russia because they're used for legal protection, but have given YouTube a great catalog of amazing video. I think there's reason beyond "Hold my beer and watch this" for Americans to have dash cams, and I do want one.

But, ultimately, I think the best reason to get into "Carputers" is Diagnostics, getting into the data that is available from your car's OBDII port. The obvious way is to use an OBDII-to-Bluetooth adapter like the ELM327 or Garmin EcoRoute, but it strikes me that there are enough security vectors in to the New Car that adding more is not a wise route. So, I'm thinking that the Raspberry Pi and an OBDII USB cable might be the better way to handle it, except I'm not sure how to export the data, and while it would be useful to keep track while driving, ultimately, off-the-road analysis is where the usefulness of the process comes in.

I'm thinking that a Raspberry Pi, a cable, a small monitor with composite video and maybe a few other things could be easily turned into a car-monitoring system, and I could pretty easily set something up to only sync with my home network when it's close. I'm not sure whether that's more cost-effective than just getting an ELM327 and an ELM327 app from the Play Store, but I think I'd end up learning more that way.

Anyway, I'm still undecided on the phone/Pi issue, but I think this is something I need to do.

2013/07/23

I've got a standing desk, and boy are my legs tired!

Borscht-belt comedy aside, I converted my desk to a standing desk configuration a week ago last Friday, making this the seventh workday where I've spent most of my day standing.

Yes, compared to other standing desks, this is pretty janky. It works for me, though. The tops of my monitors are only a inch or so above eye level, which is pretty close to Hoyle according to ergonomic standards I've seen, and the box put the keyboard at a good typing level. I'm happy with it.

My feet, on the other hand...

My left foot is a bit pronated, which is to say that the ankle turns in a bit and the big toe turns out a bit and the arch is a bit flat.

My right foot? Take every a bit from the previous sentence and put in extremely, and it also lacks the range of motion of my right. I first figured out the issues with my ankles when I noticed I could make fart noises with my foot on the bathroom tile, without trying, but the time I took a hike with my son's Cub Scout pack was when I realized I had a problem, not just an issue.

Since then, I have become much more active. Last year, I did Couch-to-5K, and actually did a 5K. I did it in 45 minutes, finding that I do a mile in 15 minutes or so whether I run or walk, but hey, I got the t-shirt. This year, I've been focused on other activities, but plan to do it again. When I started running last year, I got the same foot pain, which eventually subsided the more I worked. Internet lookup makes me think it's the Extensor Digitorum Brevis muscle that was giving me problems last year, and this last week, this is the pain I've been having again, except this time, in both feet.

The previous pain tells me that I'm doing the right thing, that I'm strengthening my feet and ankles by standing. My recent experience with Cross-Fit tells me that I had better start exercising and strengthening my feet and ankles or this pain won't go away soon.

In terms of productivity, I don't know that I've noticed a difference. I'm in a position at the moment where there's a lot of sit-and-think (or rather, stand-and-think) and not so much great code generation. I don't currently quantify my work, but would be interested in finding a way to do so. Of course, it would've been good to have a body of sitting-desk work in the dataset to use as a comparison....


2013/05/15

Stupid Things with References

It took me a while to figure out why I was writing junk to the DB. More or less, this is my code.

my $request = get_request( $request_id ) ;
my $to_wiki = $request ;

I thought to be making a copy of the hash in the hashref.

I meant to be making a copy of the hash in the hashref.

I wasn't making a copy of the hash in the hashref. I was making a copy of the hashref address. Which means every change I made to $to_wiki, I made to $request.

Instead, I needed to do something more like this.

my $request = get_request( $request_id ) ;
my $to_wiki ;
%$to_wiki = map { $_ => $request->{ $_ } } keys %$request ;

I present this as a cautionary tale. Please, learn from the mistakes of others.

2013/05/10

Ghosts of Coding Sessions Past


Boss wants to be able to clone a request, to take an item on our list and reset it.

Fair enough, but ...

Requests are among the first things I coded at the lab. Before that, I was at the clinic, and while I did a fair amount of coding there, I was much more of an admin than a developer there, and I have learned a lot about developing here.

Thing is, I learned most of it after I wrote he request code.

A request has lots of data about it. A name, an ID number, who requested it and how to get in contact, what they want done with it, etc. Each request has a number of samples, and the samples have names and numbers and amounts and such. Each sample can have a barcode, which I won't explain. Each request can also have 0-whatever statuses. I back-end to MySQL, and I can copy and massage data, and say in the status that request j is a clone of request i. All that is cool.

Then there's the Wiki.

About everything on the web page is also on the Wiki. It serves as the lab notebook, and I create the stubs. Yes, there's synchronization problems between the Wiki and the database. I try not to think about it, because I cannot find a way for the structured data to interact with the unstructured in a good way.

So, I dread the Wiki stub creation code. I coded it in Perl, using the CGI module. Before I came to the lab, I hand-coded my HTML in my Perl, like my $val = "<div> $foo </div>" which isn't good either, but 200 lines of code like $val = $cgi->div( $foo ) isn't doing my mind any good.

Thrown into the mix, we're moving from our old server to virtual server Sidam, which is Midas spelled backwards, as everything it touches turns to sh*t. I should be moving my code to that server, but that looks to be a bigger issue. To make sure that things finish, we want to move the code as close to as-is as possible. Because it's broken by design (see above) I want to use this opportunity to make great, sweeping changes.

I think I'll implement this with Template Toolkit and suck up the technical debt, but I don't look forward to that process.

2013/04/05

Module to automate API form

One thing I've noticed about the web APIs I'm seeing online is that you can often determine what format you want it in. For example, the API URL is something like example.com/api/v1/feed which gives you RSS, but if you want it in ATOM, you can get it at example.com/api/v1/feed/atom. Want JSON? example.com/api/v1/feed/json. This way, your Javascript can AJAX that mess up, while your users can pull it into EXCEL with example.com/api/v1/feed/csv and be happy.

This is cool. So I wrote some Perl to automate that stuff for me.


This does not do JSONP, because I'm not expecting, right now, to want to cross-site script the stuff I'm exporting right now. But maybe. And it shouldn't be too bad of a modification. And this is a naive and potentially stupid way of doing CSV. Maybe wrapping everything in quotes?
The cool step would be to make a dispatch table and function refs to the right thing, pulling the magic for each format out. This might be done later.

2013/02/18

MySQL -> R

Here is how you pull SQL data into R.

Cool, isn't it?

Except there's a password in plain text. Which means I have to modify it when I want to show it off.

I'll have to work on that.

2013/02/13

This is how I'm stupid

I wrote a tool about four months ago, which is long enough that I barely remembered writing it, much less what I had done in it. It connects the data coming out of one of our instruments with the metadata about the samples we fed into it. Part 1 of this is to create a comment field which is easily pushed onto the instrument's data output. The newest part takes the data images from this and combines them with the sample metadata to be published into our electronic lab notebook.

One of the cool bits about this is that, if you are creating plate records that can take 11 samples, but you have 38 samples, it will create four plate records; three with all 11 samples filled and one with just five samples.  

This is where we get into problems. Those four plate records are logically joined, with the thought that you putting them together means they go together. So, the samples are numbered between 1 and 38, in this case. Problem is, samples coming off the instrument are sample 1 through sample 11. So, sample 12 and on just fall on the floor.
I am also stupid because I put the fact that this plate can hold 11 samples into the comment field block but not independently into the database table. 

For four months, nobody who grouped several plates together like this used the tool to publish them to the lab notebook, so nobody found how I was stupid. 

Yes, I am saying I was stupid. Stupid is as stupid does, as Forrest Gump's mama said, and this is two stupid things I've done. I'll throw in "You didn't test it enough" as a third.

It isn't helpful to just say "You're stupid". It also isn't useful to say "You're stupid for using (Tool A which I don't like) instead of (Tool B which I do like)" because people do stupid things in the best of languages and do smart things in the worst. I believe it is helpful to identify the places where you are stupid, like I do above, because those are actionable. I can now add a column to the table to store the number of samples on a plate, which I might do. Right now, I'm using a regular expression to pull the number of samples out of the comment, then using modulus to find the adjusted sample number, and then saying sample number = number of samples if sample number == zero. Yeah, I'll have to add a "sample number on plate" column into the sample database table, too.

I'm glad to know these things. I'm glad they're now patched, and I plan to fix these things better. Mostly, I'm glad to know where I'm stupid because now I know how to be smart next time.