Cookie Notice

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

2015/03/31

Testing my API changes with Perl

I have an API. I like some things about it, but it was kinda clunky in many ways.

I rewrote it. I thought I had everything together, used the same SQL queries, but I wanted to be sure it kicked out the same output.

So, I wrote tests using Perl's Test::Most and cmp_deeply().

A few weeks ago, I knew Perl testing existed but I didn't know much about it. Now it's practical.

2015/03/09

Diet, Exercise and Other Issues

Nerd Fitness posted "Why Exercise is the Least Important Part of the Equation", where Steve argues that getting your diet in line is the necessary first step to health and weight loss, in part because you're going to eat anyway, so eating something different is a small change.

Of course I understand and agree. I can show you my first year of documented weight loss, point out when I started doing Couch to 5K and when I ran walked a 5K, and note that the close-to-straight-line of 1 lb/week doesn't change.

Let's do that.


That red line is what's important. I started running at about day 170 and did the 5K at about 250. Maybe later. I can look it up if it's that important, but the key is, there's no dip in that trend line where I started and stopped "running". It was good for me, I'm glad I did it and need to do more, but it had zero to do with weight loss.

So, what did affect that weight loss?

Dunno for sure.

I have theories, sure, but I can't prove anything. Here's what it wasn't: Food Intake. For years, I only ate dinner. I ate it late, and soon after, I crashed out from exhaustion. Somewhere about six years ago, I started making sure I had lunch, storing a bunch of microwave meals in the office fridge just to make sure. I now do something similar with breakfast, too, and both those changes occurred several years before I started.

That's two of three daily meals that didn't change, and as I didn't try to force any diet changes on my family (and doubt it would've worked if I had tried), the third meal can't be counted as significantly different.

I say Diet Coke instead of diet cola because,
as the pic above shows, it truly was my drink,
from 1987 to 2011.
Honestly, I did two things that I credit for my weight loss:
  • I stopped drinking Diet Coke and started controlling caffeine intake
  • I started plotting my weight
The plot is shown above. The idea came from The Hacker's Diet, which I had heard of before but really understood enough to try after reading (part of) Tim Ferriss' Four Hour Body. I had no real expectation of change, but had a desire to familiarize myself with the statistical programming language, R, and needed an excuse and data set to do so. Once I had everything in place and started watching the numbers, I intentionally avoided making too many changes in the rest of my life, just to see how long the one pound a week drop would last.

The significant change is when I stopped drinking Diet Coke, and because there's so much involved there, I'm not sure what the significant parts are.

The first thing it might relate to goes to insulin. Theory goes, just like you're tricking your tongue with the sweet-but-not-sugar artificial sweeteners, you might be tricking your pancreas. All that insulin is created, doesn't find any real sweets to handle, so it goes crazy on whatever else you might have around. This is not widely accepted, as this LiveStrong article shows. Another LiveStrong article on diet cola shows that the effect of stopping varies wildly between people.

Let me introduce a vicious circle: You're exhausted, so you drink caffeinated beverages. You drink caffeinated beverages, so you sleep poorly. You sleep poorly, so you're exhausted. I lived in that cycle for years. It took a lot to get me to sleep, but when I slept, I slept so hard that, I'm told, all of my kids danced on my head while I slept. They were toddlers at the time, but still. Add to this hormonal and decision-making changes, you'll see the problem.

I've mostly switched to just drinking coffee and water — "Don't drink calories", Tim Ferriss wrote —  and not being dehydrated might be a factor, too. Plus maybe something else. I don't know.

Anyway, the 280 lb guy I used to be was just a switch away from Diet Coke to being the 213 lb guy I am today. There's diet switches I should do — the food that's easiest for me to eat at work is the easiest for me to buy a month at a time, decreasing my cognitive load, but not best food for me to eat every workday — but I doubt those changes would've meant much before I stopped drinking Diet Coke. 

2015/03/04

BLE, in case you care


These nRF8001 Bluetooth Low Energy boards are from Adafruit, When I got them, a friend soldered on the header pins, and one didn't work. I started a long conversation with Adafruit — it's not conductive to debugging when you can only do it one evening every two weeks — but I finally got pictures into them, and they suggested resoldering the ground pins. The friend resoldered them and other pins, and now, I believe they're both going. 

Of course, I need to get some more code to write and some more bits to pump before I definitively say "Yeah", but it looks like I'll soon be able to move on to learning to write things that talk to them. 

On Android. In Java.

Or on Windows. 

Looking forward to that.

2015/03/03

Look At My Pretty Pictures

The red parts of this image are a hypocycloid.
The blue parts of this image are an epicycloid.
The gap on the right side is an unsolved problem.
Perl blogger Gabor Szabo of Perl Maven asked me to show off my SVG Spirograph code, and so, here it, released as a Github Gist. I'm not quite to the point where I'm happy with it.

Years ago, as a child, I knew people with Spirographs, and I loved playing with them, making these crazy patterns with just pen, paper and geared plastic circles.

Years later, when I heard that Canvas support was being added to browsers, I developed tools in Javascript to draw these things. Nobody I knew had really any practical use for that skill, and so I kinda left it.

Until I started looking into laser cutters. Essentially, they're high-contrast printers, and they love vector graphics, using a thin red vector as an indication to cut rather than etch. So, when I saw Gabor write about the SVG module on Perl Maven, I knew what I must do.

Right now, I have three functions that generate these images, corresponding to epicycloid, hypocycloid and hypotrochoid curves, with two functions each providing the X and Y coordinates. In each, take a circle, rotate another circle around it (outside for epicycloids, inside for the others). If the point you're using is along the circumference, it's a cycloid, and if it's beyond that, it's an hypotrochoid, which, strictly speaking, could not be done with a Spirograph because the rings would get in the way. With math, Perl and SVG, this is not a problem.

SVG has the capability of drawing curves, but I assure you that the number of curves in the SVGs that created the images here are zero. If you draw lines between points, and those points are close enough, the lines look like curves, and the file sizes explode. On the other end, if you have the distance between points long enough, they are clearly lines, and it takes a large number of loops over to disguise the straight lines and get a thick curve. My code currently cycles through at 1/400ths of a degree at a time, which is fine for epicycloids and hypocycloids, but overkill for hypotrochoids.

Getting this code to handle B├ęzier curves and the like requires more math than I currently know, and might not actually be possible, but would certainly be good for reducing file sizes.

This is a number of  hypotrochoids stacked on top of each other,
cut into balsa wood. I love the 21st century.
The other problem my code has goes back to ensuring an end. Circles and ellipses are special cases of these things, and it is also the case that, with irrational numbers, that the thing will never complete, but instead look like a big black (or red, or blue) circle. So, we need to ensure that, eventually, it'll halt. If it goes over the same part twice, it makes the line thicker, which I don't want, but the problem is we're dealing with floating point, and 0.0000000000000000014 isn't mathematically equal to 0.0000000000000000015, but if we have several x and y coordinates in a row that are within 0.0000000000000000001 of previous pairs, we're probably looping over again. Eventually, I'll poke at that idea. As is, it loops 50,000 times, which is why the "both" image above isn't complete.

And, having an offset, to rotate these things as desired, would also be good. Code below, and also on Github.