I live in Omaha.
 
Navigation
 
Search
 
Random Image
DSC_0035.JPG
 
Me. Elsewhere.
 
Archives
 
Darcy
 
Recently Read
 
Things I Like
mongodb
 
License
 

Charting Weight Change With Google Visualizations

I started trying to lose weight a while back, since we both know I’m a bit heavy and sitting in front of a computer isn’t going to lose the weight for me.

Naturally, it’s important that I incorporate technology into my weight loss somehow, right? So I decided to give the Google Visualizations API a spin.

I worked up a quick data format and a method to pop the data out. Nothing fancy, just a fixed width flat file. This doesn’t deserve a database.

1
2
2010-06-30 235.4
2010-06-29 236.8

Easy to read, easy to edit, and easy to consume. Every morning I just hop on the server, add the day’s weight and log off.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
  // Get the max days back we want to look.
  $max_days = 7;
  if( isset( $_REQUEST['days'] ) and ! empty( $_REQUEST['days'] ) )
    $max_days = intval( $_REQUEST['days'] );
 
  $i = 0;
  $lines = array();
 
  $fh = fopen( 'data.txt', 'r' );
  while( ! feof( $fh ) and ++$i <= $max_days ) {
    $line = fgets( $fh );
    if( empty( $line ) ) { continue; }
    array_unshift( $lines, $line );
  }
  fclose( $fh );

Now I just needed to represent it. The API is very object oriented and easy to work with. I wish there was a less verbose way of presenting the data, but you can’t have everything.

Actually, there may be a better way, I just didn’t come across it while speed reading the docs.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function drawChart() {
  var data = new google.visualization.DataTable();
  data.addColumn( 'string', 'Date' );
  data.addColumn( 'number', 'Weight' );
 
  data.addRows( <?php echo count( $lines ); ?> );
 
  <?php
    $i = 0;
    foreach( $lines as $line ):
  ?>
  data.setValue( 
    <?php echo $i; ?>, 
    0,
    '<?php echo substr( $line, 0, 10 ); ?>'
  );
 
  data.setValue(
    <?php echo $i; ?>,
    1,
    <?php echo floatval( substr( $line, 11 ) ); ?>
  );
  <?php
    ++$i;
    endforeach;
  ?>
 
  var chart_div = document.getElementById( 'chart_div' );
  var chart = new google.visualization.LineChart( chart_div );
  chart.draw(
    data,
    {
      width: 800,
      height: 600,
      title: 'Weight Over Time'
    }
  );
}

And there you have it, fancy charting in no time.

Example Chart

See it in action at http://static.velvetcache.org/weight.php

Get the full source at http://gist.github.com/459148.

Posted July 5th, 2010 - Permalink
Categories: Consume - Geek - Life
Tags: , , , , , , ,
No Comments »
 

Sugru To The Rescue!

I finally got a hold of some Sugru a few days ago. I had pre-ordered a sample pack (12 small sachets) and it arrived at last.

First off, when they say that a sachet is small, they mean it. However, this stuff goes a long way.

Sachet Size
Sachet Size

My first fix was my beloved flip flops. I’ve had these for 5+ years and they are the most comfortable things ever. Darcy would tell you that I only hang on to them because she hates them BUT THATS A LIE! (mostly)

The Sandals
The Sandals (Post-Op)

These sandals had major issues. Before I repaired them there was a rip all the way through (depth wise) and almost all the way across (width wise). Previously I had closed that gap with long nails, which worked for most of a summer, but they were not a long term solution.

Underside Repair
Underside Repair

But Sugru was just the ticket, it worked great. I followed the instructions and washed up then opened a packet and got to work. I found that it stuck to me more than the shoe in my case, but with some push and quick pull-back I managed to get it where I wanted it.

I used two sachets on this, but looking back I could have done the job with one. The first packet I put up top and I rushed a bit and got sloppy. Later I put the bottom packet on and I think that’s what actually did the job.

Foot Area Repair
Foot Area Repair

All in all a nice experience. My only issue with Sugru is that is stained my hands for a while, but that’s a pretty minor complaint. My sandal is comfy, solid and ready for years more action.

Posted July 3rd, 2010 - Permalink
Categories: Consume - Geek - Life
Tags: , , , , , ,
2 Comments »
 

Thursday Quote: Elbert Hubbard

“One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man.”

- Elbert Hubbard

Posted July 1st, 2010 - Permalink
Categories: Life
Tags: ,
No Comments »
 

Summer Odds And Ends

Summer is here and I thought I’d post some recent photos from around the house.

Melvin the Toad
Melvin The Toad Lives In Our Backyard

Garden Herbs Drying
Garden Herbs Drying

Homemade Butter
Homemade Butter

Darcy Making Flour Tortilla Chips
Darcy Making Flour Torilla Chips

Home Fried Flour Tortilla Chips
Home Fried Flour Tortilla Chips

For those concerned, the chips were immediately consumed with homemade salsa.

They were delicious.

Posted June 30th, 2010 - Permalink
Categories: Life
Tags: , , ,
No Comments »
 

r = 1 – sin(θ)

My Inspiration

I wrote this song quite a while ago. We recorded it for Nikolai but we broke up before it made it to a disc.

I really like this song, and I thought I’d share it again.

Here’s the music.

Get the Flash Player to see this player.


And here’s the lyrics.

At the edge of the bell curve, I'd hoped there was one for me.
At the edge of the bell curve, I knew I'd love you, statistically.
 
I've got your number, you've got mine, so call me baby.
We're just two big old primes, together live unfactorably.
 
You'll never find another like me.
I solve your equation so elegantly.
 
At the edge of the bell curve, I'd hoped there was one for me.
At the edge of the bell curve, I knew I'd love you, statistically.
 
Unlike the number pi, you are so rational.
And with you, baby, I always know my set is full.
 
You'll never find an angle on me.
'Cause baby, oh baby, we're complimentary.
 
At the edge of the bell curve, I'd hoped there was one for me.
At the edge of the bell curve, I knew I'd love you, statistically.
 
You'll never find a number like me.
And, baby this love's not imaginary.
 
At the edge of the bell curve, I'd hoped there was one for me.
At the edge of the bell curve, I knew I'd love you, statistically.
 
3.141592
 
At the edge of the bell curve, I found you waiting for me.
At the edge of the bell curve, I'll always love you, infinitely.
 
At the edge of the bell curve, I'd hoped there was one for me.
At the edge of the bell curve, I knew I'd love you, statistically.
 
At the edge of the bell curve, I'd hoped there was one for me.
At the edge of the bell curve, I knew I'd love you, statistically.

Posted June 16th, 2010 - Permalink
Categories: Geek - Life
Tags: , , ,
No Comments »
 
More Posts
 
Copyright © 2006 - 2010 John Hobbs
get userping