Wednesday, April 29, 2015

Mom of the Year. Wait, What?

It isn't often the Internet can agree on something. But apparently it has: the Baltimore mom beating her son for participating in looting is a hero. Mom of the year, in fact.

Sure, I'll give her major credit for stepping in and extracting her child from this awful situation. But isn't anyone just a tad bit outraged by the fact that she does this by beating her child?

I realize I've got a fairly unique perspective on the topic of corporal punishment. As a foster parent, that's simply a no-no in our world, end of story. This isn't just because of the silly notion that we shouldn't be hurting children, but because there are more effective means of instilling discipline. (Yes, there are more options than: (a) hit my child or (b) let my child run wild; and yes, discipline is a critical part of parenting and isn't just a euphemism for hitting your child.)

I mean, not to be picky, but if Mom was truly MomOfTheYear, would her child be out there rioting in the first place? And how can you say that beating your child is effective if you need to beat him as a teenager?

And what, pray tell, is the message your child is learning from getting assaulted? Violence is wrong, unless I'm doing it to you, in which case it's OK. Uh, see in flaws in that logic? If he struck his girlfriend *exactly* the same way his Mother hit him, we'd be outraged.

The whole scenario makes my brain just hurt.

Finding and Appreciating Pennies

I've been having trouble getting into Pilgrim at Tinker Creek by Annie Dillard, so I just started flipping to random sections and reading. My hope was that either I'd finally be sucked into the text, or I'd be justified in giving up and declare the book isn't for me. While doing this, I came across this anecdote:

When I was six or seven years old, growing up in Pittsburgh, I used to take a precious penny of my own and hide it for someone else to find. It was a curious compulsion; sadly, I’ve never been seized by it since. For some reason I always “hid” the penny along the same stretch of sidewalk up the street. I would cradle it at the roots of a sycamore, say, or in a hole left by a chipped-off piece of sidewalk. Then I would take a piece of chalk, and, starting at either end of the block, draw huge arrows leading up to the penny from both directions. After I learned to write I labeled the arrows: SURPRISE AHEAD or MONEY THIS WAY. I was greatly excited, during all this arrow-drawing, at the thought of the first lucky passer-by who would receive in this way, regardless of merit, a free gift from the universe. But I never lurked about. I would go straight home and not give the matter another thought, until, some months later, I would be gripped again by the impulse to hide another penny

Fair enough, that's a cute enough story. And then I read the next paragraph:

It is still the first week in January, and I’ve got great plans. I’ve been thinking about seeing. There are lots of things to see, unwrapped gifts and free surprises. The world is fairly studded and strewn with pennies cast broadside from a generous hand. But—and this is the point—who gets excited by a mere penny? If you follow one arrow, if you crouch motionless on a bank to watch a tremulous ripple thrill on the water and are rewarded by the sight of a muskrat kid paddling from its den, will you count that sight a chip of copper only, and go your rueful way? It is dire poverty indeed when a man is so malnourished and fatigued that he won’t stoop to pick up a penny. But if you cultivate a healthy poverty and simplicity, so that finding a penny will literally make your day, then, since the world is in fact planted in pennies, you have with your poverty bought a lifetime of days. It is that simple. What you see is what you get.

Whoa, the nice lady who's writing I don't totally get is profoundly right. First, there are 'pennies' casually hidden all around. Whether it's a a few tiny sprouts or a short section of recently discovered trail, or any of the other countless tiny wonders around us, they are indeed there.

And furthermore, her point is also right: who gets excited about a penny? In DC, where I'm less than 5 miles away from the US Botanic Garden, it's easy to dismiss the dandelion as just another weed.

Finally she nails it: if you cultivate a healthy poverty and simplicity, so that finding a penny will literally make your day, then, since the world is in fact planted in pennies, you have with your poverty bought a lifetime of days.

What a remarkable insight and something to strive for. Needless to say, I'm back to making my way through Dillard's book. Well played Dillard, well played.

Tuesday, April 28, 2015

How to make sponges interesting

Mylar, aluminum foil, hand sanitizer and parchment paper are all remarkable materials with lots of uses. But sponges? Seriously, how useful can a sponge be?

According to my brother, who sent me these links, quite.

Click here, here, and here to see what I mean.

Some hacks that impressed me: make improvised 'feet' for a dish to keep it from scratching a the table it's resting on; snip and insert into toddler's shoe to fill out too-large shoes, make sponge building blocks and make a mini-greenhouse by combining a wet sponge, some seeds and clear glass bowl over the whole setup.

Sponges are cool. Who knew?

It's Alive!

Look at our X-Garden:

It's still just a big pile of dirt. But look closer, say I. It's alive!

Growing vegetables from seed has to be the most inefficient way to manufacturer food, but the most efficient way to manufacture joy. How can you not be in awe of these little wonders?

Something grew. The garden is now officially a success. The fact that the plants are little more than sprouts is merely an implementation detail.

Monday, April 27, 2015

Let's Hike the CDT!

I truly enjoyed Joe Brewer's PCT hike. He provided 20 minute snapshots of him covering between 150 and 200 miles of the trail. It's enough to give you a taste of the terrain and life on the PCT while not becoming tedious. And it's not just the outdoorsy aspect of the video that I love, Joe's Everything is Cool Attitude has become what I strive for when I'm tackling pretty much any activity.

Joe is at it again, this time he's hiking the Continental Divide Trail, aka the CDT. At about 3,100 this bad boy is a beast. I'm pulling for you Joe!

Joe has put up his first video check in here. Spoiler alert, things don't start particularly well. Much like when his PCT adventure, within a few days he's got an injury which forced him to take a rest from the trail.

But does Joe's attitude waiver for even a second?! Nope. And there he goes, showing us the way to tackle a monster journey like the CDT. Incidentally, I didn't hear him use the phrase cool once in his first video. Still, the sentiment is all there.

Friday, April 24, 2015

Let's Measure That: Soil Moisture

I've got this great view of our X-Garden out my office window. And so far, it's the best looking pile of dirt I've ever seen. In fairness, planting from seed does mean that we've got to sweat it out for a few days to weeks before we'll see any sign of life.

In the mean time, I need to keep the soil most, but not too moist. And we've had a few days of heavy rains which is a good thing, but is it enough to keep the seeds happy? It occurred to me that rather than just worry about this, I could take some action. Surely there's a way to measure how water's in the soil and give me a definitive answer.

And there is. In fact, such a meter is all of $9.00 on Amazon. Today I gave it a try. And verdict is...

Yeah, we've still got some moisture in there, but it's getting on towards watering time.

I've always looked at everything gardening related as one big experiment. No matter the outcome, you learn something. So having more data is better. And everybody knows that experiments need meters. Of course, the next move is to use the meter data to automate watering, but for now, I'm satisfied with just watering the plants the old fashion way.

By the way: we did at least one good thing in our X-Garden. We planted milkweed. Good for us! (And for the butterflies!). Learn about the benefits of milkweed here.

Review: Containment

I'm about 3 years late on this book review. When I got word that the *sequel* to my good friend Christian Cantrell's book was out, I knew I better get off my butt and read the first book in the series. One click on Amazon and a few days later and I held Containment, a Sci-Fi novel, in my hands.

I won't lie. My first thought, given the heft of the book was: Really Christian, you couldn't stick with short stories? Within a few pages I couldn't help but announce to my wife: man, this is the real deal. The writing, the story, the characters, the futuristic details, it was all written so dang well. And by a little over halfway through the book I found I couldn't put it down. Every spare moment I had, I grabbed it and read away. I pushed through the final 40 pages by forgoing lunch because I simply had to know how it ended.

I suppose I should confess it's no surprise that I like the book, as ultimately the hero is a computer programmer. It's not only his coding skills that save the day, but it's his ability to think like a programmer that let's him reason his way out of whatever mess he's in. How could I not root for him? So this character in a well written story was going to be a no brainer for me to enjoy.

I found Containment to be a sort of playground of ideas. Whether it's clever suggestions for addressing global warming (End-of-Life Plans--I so want this), computing ideas or even relationship advice, I never really thought of fiction as being a vehicle for exploring a concept. But Christian shows that it can work. And it makes sense; authors often talk about how they'll start with a character and let them naturally evolve, why not try the same thing with an idea or concept?

At the end of the day, Containment was a fun read. It more than held it's own against anything Sci-Fi I've read and in many cases was better. Perhaps the best compliment I can offer is that I've ordered the second book, and won't be waiting 3 years before I read that one.

Wednesday, April 22, 2015

Slurping in Google Spreadsheet Data in 6 lines of Standard PHP Code

A data analyst and a coder walk into a bar... Actually, scrap that. A data analyst and a coder have to quickly solve a problem. The data analyst has the data in spreadsheet form, but the coder wants a programmer friendly solution. What do they do? The coder could build out a full blown app, first by importing the analyst's data into a database, and then developing a crude UI for the analyst to interact with, but that would be overkill. Remember Programmers should be lazy.

Recently I found myself in this sort of situation. The code I needed to write was basically some trivial PHP. But getting the data in and out was going to be a pain. So I turned to my Digital Swiss Army Knife: Google Spreadsheets for a solution.

I had the data analyst import the data into a Google Spreadsheet. I then used the old school Spreadsheets List API to access the data from within PHP. To make matters especially simple, I had the analyst publish the data to the web and then used the publicly accessible API. The result was that I spent no time worrying about authentication, and could test everything out on the command line using curl.

I used PHP's curl to grab the data and SimpleXML to easily pick through it. There were a couple of speed bumps to get over (like how to access the namespaced elements in SimplXML), but once I figured them out, the solution couldn't have been simpler.

Here's a trivial demo I put together which exercises all this. First, I've got a Sample Data Set, and then I've got some code which slurps in this data and spits out the max and average. Of course, if that's all the info I needed, I'd forgo this whole PHP script. Where this sort of solution really shines is when you need to access multiple tabs from the spreadsheet and either filter or aggregate data in complex ways.

Notice how the actual PHP for picking up the data from the spreadsheet is a measly 6 lines of code. SimpleXML's magic means that while no official API is used, accessing the document is painless.

Happy Hacking!

<?
/*
 * Demonstrate easy access to a Google Spreadsheet
 */

// Before getting into the code, you'll want to:
// (a) make sure the document is published to the web
// (b) figure out the worksheet URL by running something like
// 
//    curl -s 'https://spreadsheets.google.com/feeds/worksheets/[id]/public/full' | xmllint.exe  -format -|\
//       grep '2006#list' | sed -e 's/^.*href="//' -e '/".*//' 
//

$worksheet_url = 'https://spreadsheets.google.com/feeds/list/1IR4JAaJWcScBONP4R3O_IbO4ecyVF5kOBEBzoExjM7E/od6/public/full';

/*
 * OK, we've got our URL so slurp it in and make it an easily accessible
 * document.  Notice how the $gsx namespace is setup for easy use below.
 */
$ch   = curl_init($worksheet_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml  = curl_exec($ch);
$doc  = new SimpleXMLElement($xml);
$ns = $doc->getNamespaces(true);
$gsx = $ns['gsx'];

/*
 * Do something with the data.
 */

header("Content-Type: text/plain");

$nsamples = 0;
$max = false;
$avg = false;

foreach($doc->entry as $e) {
 $nsamples++;
 if($max === false) {
   $max = array('ts' => $e->children($gsx)->timestamp . "", 
                'val' => $e->children($gsx)->pressure);
 } else {
   if(($e->children($gsx)->pressure . "") > $max['val']) {
     $max['ts']  = $e->children($gsx)->timestamp . "";
     $max['val'] = $e->children($gsx)->pressure . "";
   }
 }
 if($avg === false) {
   $avg = $e->children($gsx)->pressure . "";
 } else {
   $avg = (($e->children($gsx)->pressure . "") + $avg) / 2;
 }
}

echo "Num Samples: $nsamples\n";
echo "Max: {$max['ts']} = {$max['val']}\n";
echo "Avg: $avg\n";

?>

Tuesday, April 21, 2015

Front Yard Tea: Surprisingly Good

Keeping on my tasting kick of late, I give you an entry in the Hot Drinks department.

Being an avid tea drinker, I can't believe I've never actually made dandelion tea. While you can get fancy and roast the roots, I opted for the simpler steep the flower heads version. The process couldn't be easier: grab a few dandelion flowers, trim off the yellow parts, drop in a tea filter bag, and let it steep for 5 minutes (I actually let it steep closer to 15 minutes due to a phone call mid-steep).

See:

And the verdict on the flavor: not bad to pretty dang good. The flavor isn't particularly strong, but it's definitely there. There's no bitterness, and it's not a typical black tea flavor. But still, there's *something* there. When you factor in that it comes from a common 'weed,' it's value goes up even further. I'd definitely drink dandelion tea again. For step by step instructions, check out this video.

See, the lawn is already providing tastiness even before the garden is fully planted. Hurray!

Buggy

Monday, April 20, 2015

Gardening Progress: Raised Beds Built, X-Garden Seeded

We've settled on a two pronged strategy for gardening this year. First, we're going to do it Right, and with the help of our friend Dawn, put in some Square Foot Gardens. Then, because I can't leave well enough alone, we're going to have an X-garden for me to play in.

I sent Shira and Dawn off to Home Depot for the Square Foot Gardening supplies and this is how they returned:

I helped pull the wood out of the car and organize it a bit:

I then went back inside and returned some time later to see this sight:

That's Dawn using her power drill, because mine is too small. I retreated back inside to save my manhood (and work on another project). When I returned, the building phase was complete! That wasn't hard at all. (Actually, the trip to Home Depot took far longer than the construction phase of the raised beds).

Later this week we'll pick up the right mix of soil, some plants and we'll be on our way!

Now it was time for the X-Garden. Previously, I had ordered a Big Bag Bed. which while pricier than the small bit of lumber needed for the raised beds, does require zero effort setup (and no mind-losing trip to Home Depot!). I filled it with 9 bags of Nature's Care Raised Bed Soil. It's what Home Depot had, and fit the low effort theme of the X-Garden.

I planted the following seeds: Milkweed (think of the butterflies!), Quinoa, Amaranth, carrots, beans, Borage, Wild Purslane and Golden Berry (aka: Cape Gooseberry).

Will anything grow? Who knows! For now I've got very low expectations. Here's how X-Garden looks once filled and seeded:

As long as we were at Home Depot, we could resist picking up some decorative flowers as we like to do every year. And as usual, it's T & E gardening all the way.

Definitely fun times, and I'm psyched to see the Square Foot Gardening approach coming together.

Friday, April 17, 2015

The Definitive Ranking of Quest Bar Flavors

Do the diet and exercise thing long enough and eventually you'll decide you need to strategically consume protein bars. At least that's what Shira and Dawn tell me. And when you do this, you'll need to find not only a bar that has the stats you're looking for, but ideally doesn't taste awful nor has an ingredient list that belongs in a chem lab. When you get to this point, I'd suggest trying Quest Protein Bars. Any bar that meets Shira and Dawn's high standards has to be good, right?

They tasted a number of bars from the variety pack, and here's how they got ranked. Note: they microwaved the bars a few seconds to soften them up.

And here's their tasting notes:

#1 - Peanut Butter Supreme: Yummy! (there you have it, high praise)

#2 - Peanut Butter & Jelly: Yummy! Whoa, that really does have a jelly taste. Amazing. (I agree. Where did that flavor come from?)

#3 - Chocolate Peanut Butter: Pretty good, but more chocolate than peanut butter tasting.

#4 - Banana Nut-Muffin: Uh, where's the banana flavor? Not impressed. (Though, I was. It's definitely got some banana flavor)

#5 - Apple Pie: Too sweet

While not in the above tasting session, Shira tells me that the Lemon flavor should be ranked #3, and Dawn tells me that Chocolate Chip Cookie Dough should also be ranked #3.

Apparently no flavor is breaking into the top 2 without a heavy dose of peanut butter.

There are more flavors in the variety pack with more tasting updates to come...

Thursday, April 16, 2015

A Simple Recipe for Amazing Adventures

If I squeeze in a 5 mile run and manage to find some pretty looking plants, I call that an overwheming success. But some people, Matthew Kirk in particular, think a little bigger. OK, maybe a lot bigger. Try 150 mile run over three days bigger. Apparently, he just ran from one side of Florida to the other.

This is the sort of craziness insanity impressive feat is normal for Matt who apparently holds the Appalachian Trail speed record of 58 days 9 hours and 38 minutes (not bad for 2,200 miles!).

He appears to have a sort of recipe for tackling this type of project: (1) have simple, yet tried and true, gear list, (2) document a route plan, (3) DO IT, (4), document the results.

The gear and planning is left the simple, so the emphasis is on the adventure itself.

The whole system seems repeatable, even by mere mortals like myself.

Now if you excuse me, I need to open up a new Google Spreadsheet and start planning out my next adventure...

Read the story of Matt's cross-Florida-run here and be amazed. This all fits in nicely with my microadventure theme of late. Or as Matt puts it, "think globally and adventure locally."

Wednesday, April 15, 2015

Evolution, Not Just For Life Anymore

It isn't often you read the following:

... watch this video, which features eleven solid minutes of engineering explanation and is not boring for even a second.

and it turns out to be 100% true. Seriously, Jason Kottke is right, this description of how the Aluminum Can is manufactured is just brilliant.

If that's not evolution playing itself out, I don't know what is. What a thing of beauty.

Watch the Video

Cashew Juice - It seemed like a good idea at the time

Let's say you finish a run and you're outside of a Latin supermarket, say, Food Star. And let's say you go in hoping to pick up a refreshing drink. And let's further postulate that you'd like to find a drink that's: (a) unique, (b) marked Kosher. You may eventually find yourself staring at this bottle:

Cashew Juice, you're going to think to yourself, how perfect!

All I can say is, proceed with caution.

I was in the above situation on Monday night. I came out of the supermarket proudly showing my purchase to Shira and Dawn, when Dawn saved me: you do realized that's marked as concentrate, right? I had not. My plan of cracking open the Cashew Juice would have to wait until I got home.

When I did, I carefully mixed up a glassful. As I went to take a sip I caught a whiff of the substance. Good Lord! It smelled...awful. Seriously, what the heck was I trying to drink? I tried again and took a sip. The the actual liquid tasted better than the smell, but not by a whole lot. I then, per the bottle's suggestion, added a whole bunch of sugar. That didn't improve matters much. As I made my way through the first glass I started to appreciate that I was indeed drinking a sort of citrus type drink. By the end of my first sample, I would almost describe the taste as watered down orange juice.

This begs the question, what I was I actually drinking? I mean, I've eaten cashews before, but this drink didn't taste anything like the nut (which technically isn't a nut). A quick search of Google and realized I was eating this guy:

Apparently that's a Cashew Apple. While I'm used to eating the nut part, apparently there's a big 'ol fruit to eat as well. Having a mental image of a fruit actually helped the drink taste better.

At the end of the day, Cashew Juice is what I'd have to put in the acquired taste department.* I'm apparently not alone in this feeling. I'm currently drinking my second glass, and slowly but surely, I'm beginning to like the taste of it. Who knows, maybe by the time I've gotten through the 14 more(!!) servings that I bought of this stuff, I'll actually like it.

*Or as one comedian put it: This taste awful! Let's eat some more of it!

Tuesday, April 14, 2015

You Don't Need This: The Refrigerator Cam

If you asked me for the most Internet Thing I'd Seen All Week was I'd have to say it's the Japanese Fridge Cam:

But Why?! you may ask, is there a page dedicated to live streaming the contents of one Japanese individual's fridge? I haven't a clue. But I know that there are thorough instructions on how to live stream the contents of your own fridge.

Don't try to figure it out, just enjoy the wackiness that is the web.

Standing Tall

What can I say, tis the season to stop and constantly snap photos of plants.

Monday, April 13, 2015

Cherry Blossoms, Daffodils, Tulips, Oh My!

Yesterday, Shira, Dawn and I joined about billion other people as we jogged along the Potomac River and beside a number of Cherry Blossom trees. We started and finished our run at the Lyndon Johnson Memorial Grove, which means we ran through Lady Bird Johnson Park, which contains "thousands of daffodils and hundreds of tulips." All this meant that I did as much photographing as did running. Here's just a few snapshots from a perfect DC day!

One day I'm going to figure out a running setup that allows me to bring my DSLR and Telephoto lens. Until then, I'll keep making do with my cell phone.

Oh, and if you want to get a taste of the Cherry Blossoms but avoid the crowds (or even coming to DC), check out EarthCam's live view of the Tidal Basin. All the views, none of the crowds.

The Mystery of the Birding and Wildlife Trail Sign

Last Friday, I'm jogging along Carlin Springs Road when I pass by this sign I've seen dozens of times:

I've always wondered where following that Birding and Wildlife sign would take you. So, rather than follow my planned running route, I took a quick right and followed the direction the sign pointed. In no time, I was at the end of the school parking lot where an unmarked trail head could be found. I then jogged a short, but woodsy section of trail, which popped out at 7th street. From there, I retraced my steps till the trail crossed a small creek. At that point, you're effectively at Long Branch Nature center, which has a trail that connects up to Four Mile Run Trail.

In all these years I had no idea that 4 Mile Run Trail / W O&D connected up to this adorable nature center. What this section of trail lacks in length, it makes up for in character.

It had colorful flowers like these:

And a new plant for me to learn about: Podophyllum (thanks to Rabbi Ackerman for the identification help!).

Note: this guy is not edible, but does have some medical uses. If I ever need to accelrate defecation, I know my go to plant.

And check out this audio recording: nothing but soothing creek noises.

Not pictured are 3 deer that were watching me, as I was taking pictures of the flowers and such.

It may have been a nanoadventure, but it was still a fun time!

Thursday, April 09, 2015

An Arlington Friendly Garden Planning Checklist

With views like this one outside my office window, I can't help but feel that gardening itch coming on. Last year it was all about experimenting with seeds. This year, I might be able to convince Shira to go the raised bed route.

Regardless, I'm getting all my ducks in a row. Let's see...

  • Figure out my last frost date. Check.
  • Figure out my hardiness zone. Check.
  • Find the Virginia Cooperative Extension's Vegetable Planting Guide with Recommended Planting Dates. Check.
  • Find a list of easy to grow plants in North Virginia. Check.
  • Review Arlington VA's Soil Map (who knew this existed?). Check.
  • Find a YouTube user to follow, watching as many videos of his that I can, all while appreciating his quirky optimism: Check.
  • Find a plant that most people consider a weed, though is both easy to grow and a super food: Check.
  • Order seeds for said plant. Check.
  • Review Northern Virginia Native Plants to find out what I should be responsibly growing. Check.
  • Review the Master Gardener's of Norther Virginia's recommended plant list. Check.

Now all that's left is to actually start the garden...how hard that can that be?

Oh, and surely I'm missing about a 100 items on the above checklist. So please, set me straight in the comments.

This Bud's For You

See the commercial that inspired the post title. Or, maybe I should have gone with: But We Wanted a Bud Light!. Regardless, this is the view outside my office window. Spring is springing!

Wednesday, April 08, 2015

usem Note Cards: Compact And Oh So Beautiful

I first heard about usem note cards over at edcforums. These credit card sized sheets are designed to store easily in your wallet, yet be as functional as a technical notebook. Between my fondness for pad and pen and my love of all things pocketable, I knew I was in love.

Typically, I'll drool over fancy notebooks and the like, but at the end of the day my preference is the $1.88 spiral variety they sell in countless stores. While cheap, they are totally functional and I never give a second thought to beating them up, scribbling all over them and replacing them with a shiny new one. Still, when I saw they offer a free sample pack I couldn't resist. So I sent in the contact us asking to give these note cards a try.

A few weeks later, these beautiful specimens showed up:

They really do deliver on what they promise: they are high quality paper, fit perfectly in a credit card slot and have technically useful design markings on them.

For every day use, I think I'll stick to my cheap spiral notepad. It's just too effective for me to give up. But for special occasions, like when I'm carrying my 007 setup, grabbing a couple of these cards is ideal. Now I just need to figure out where I can take Shira dressed up in a tux, so I can truly test these guys in the field.

If you're a pen and paper aficionado, you owe it to yourself to check usem out, and if you think they're useful, try the samples. You're going to be impressed.

Tuesday, April 07, 2015

A Little Multi-Radix Programming Fun

I was sucked in by today's Programming Praxis Challenge: Pounds, Shillings, Pence. The goal was to create a couple math functions that worked with mixed radix values (for example, time which is specified in weeks, days, hours, minutes and seconds). Developing the API turned out to be some good fun. The exercise definitely reminded me of my very early days of programming, where you'd be given an assignment to make proper change (damn you pesky quarters, nickles and dimes!) and would have to div and mod your way to a solution. I recall being thoroughly stumped by these sort of tasks, so perhaps this was my way of slaying a very old dragon?

I ended up taking a page from Unix, and built my 'system' on the notion of converting multi-radix values to a single integer value. In the time example above, I convert all values to seconds (just like Unix does) to allow for easy math.

You could hardly call what I put together elegant, but I'm pleased with the results. It almost lets you think about the values you'd like to (in the case below, miles, yards, feet and inches) versus what the computer ideally works in.

(define dist '(1760 3 12)); read: (yards-per-mile feet-per-yard inches-per-foot)

(define short    (make-mr dist '(5))          ; 5 inches
(define football (make-mr dist '(100 0 0))    ; 100 yards
(define marathon (make-mr dist '(26 385 0 0)) ; 1 marathon

(show (mr-add football marathon))
(show (mr-sub marathon football))
...

And here's the complete code:

;; Mixed Radix Math --
;; http://programmingpraxis.com/2015/04/07/pounds-shillings-pence/
;;

(define time-spec '(7 24 60 60))
(define dist-spec '(1760 3 12))
(define hms-spec '(60 60))
  
(define (mr-factors spec)
 (let loop ((spec (reverse spec)) (current 1) (result '(1)))
  (cond ((null? spec) result)
        (else
         (let ((x (* (car spec) current)))
          (loop (cdr spec) x (cons x result)))))))

(define (mr-normalize spec value)
 (cond ((= (length value) (+ (length spec) 1)) value)
       ((> (length value) (+ (length spec) 1))
        (error "Invalid value: " value spec))
       (else
        (mr-normalize spec (append (list 0) value)))))

(define (mr->int spec value)
 (let ((factors (mr-factors spec))
       (cleaned (mr-normalize spec value)))
  (apply + (map * factors cleaned))))
  
 (define (int->mr spec value)
  (let loop ((value value) (factors (mr-factors spec)) (mr '()))
   (cond ((null? factors) (reverse mr))
         (else
          (let* ((f (car factors))
                 (q (quotient value f))
                 (r (remainder value f)))
           (loop r (cdr factors) (cons q mr)))))))

(define (show . x)
 (for-each display x)
 (newline))

;;
;; Slightly higher level API
;;

(define (make-mr spec value)
 (cons spec value))

(define (mr-spec x) (car x))
 
(define (mr-value x) (cdr x))

 
(define (mr-op op)
 (lambda (x y)
   (let ((xv (mr->int (mr-spec x) (mr-value x)))
         (yv (mr->int (mr-spec y) (mr-value y))))
     (make-mr (mr-spec x) (int->mr (mr-spec x) (op xv yv))))))
   
(define mr-add (mr-op +))
(define mr-sub (mr-op -))

 
(define x (make-mr hms-spec '(3 19 45)))

Monday, April 06, 2015

Passover Seders - Insightful, Creative and Soooo Tasty

We had two excellent seders this year, one hosted by Brother and Sister-in-Law and the other hosted by us. As usual, I did a little research ahead of time to try to come prepared with a few new insights. Here are some web resources I found especially useful:

  • Pour Out Your Wrath - an interesting take on the Pour Out They Wrath paragraph snuck in at the end of the seder.
  • Lifeline Bo - here's something I never realized: the same question the wicked son mentions in the Haggadah gets a completely different in the Torah. With some thought, I realized that this was probably pretty reasonable: what makes the wicked son in the Haggadah get such a sharp answer is probably the tone with which it is asked, not the content of the question itself.
  • The centrality of questioning - one of the questions I searched for was this: why don't the 4 Questions have (obvious) answers? The best answer I reasoned out was this: I've actually been reading the 4 questions wrong my whole life. There's only one question being asked ("How is this night different from all other nights?") and in response, there are 4 answers (statements) given. The text of the Haggadah, as printed in the Art Scroll Passover Machzor, shows the "questions" exactly like this. Punctuation, it'll get you ever time.
  • Kol dichfin yasei uyachal - Why is the announcement "all who are hungry let them come and eat" printed in Aramaic, while the rest of the Haggadah is in Hebrew? I don't have a good answer yet. Heck, that whole paragraph seems out of place to me, and perhaps is something I'll look further into next year.
  • Passover Seder: Reasons based on Talmudic Liturgy or Custom of dipping finger in wine? - an informal discussion about why folks use their fingers to take drops of wine out for the 10 plagues. We're definitely a dip your finger in your wine family.
  • THE FINGER - Parshat Va’eira - some commentary about the Finger of G-d mentioned in the calculations for the number of plagues the Egyptians had at the Red Sea. This one is truly interesting. First off, while I've read the paragraphs describing the math used to derive the number of plagues countless times, I've never noticed that it's in that single paragraph Moses' name is mentioned. Why there? Now there's a stumper. And the article goes on to talk about nuances about the finger of G-d. Definitely worth a read.
  • Plagues, 10/50/200/250 - More discussion about Moses getting a mention in the paragraph with plague calculations. Seriously, how did I go my whole life and not notice this?
  • Seder Insights with Rabbi David Walk - This 45 minute Podcast turned out to be filled with interesting gems about the seder. Two of my favorites: Rabbi Walk deftly explains how the 'story' section can be split into two parts: first a discussion of when, how and to whom the story should be told, and then the story itself is recited. In this light, the discussion about Rabbi's staying up all night and the debate about what day to hold the seder actually makes some sense. Another item I liked of his: he explains why 4 cups of wine makes sense. The first and third are for Kiddish and Birkat hamazon, is a no-brainer. The second cup is for the story, because it's used as a prop during the story. And the 4th cup is for Hallel, because Hallel itself is where the notion of lifting up a cup of wine to say Kiddish comes from (See version 13 here). Simple and elegant. Oh, and he also taught me that the 1st of Nissan gets mentioned in the Haggadah not because it's a random date, but because it corresponds to the first Mitzvah the people received. That's right, before they even exited Egypt they were given a Mitzvah. Definitely worth a listen before your next seder.

Finally, in an effort to not make our seder's too serious, I picked up a fresh set of Legos and challenged participants to create something Passover related. Here's what my Sister-in-Law came up with:

And David and I worked out these guys together:

And this one was all David:

Oh, and Shira cooked up a storm. She made Chicken soup, Hot Dog Surprise, Quinoa Stuffed Mushrooms, a kugel of some sort and peach halves with sweet potatoes. So tasty! And don't even get me started on her deserts - she somehow turned Matzah into a toffee like substance which is so good, it can't be Kosher for Passover (but is). Seriously, how'd she do that?

Friday, April 03, 2015

Passover 2015, Let's Do This!

For some, Passover truly begins with that first bite of Matzah, or maybe it's the chanting of the order that kicks off the seder. Or maybe it's that I'm so full, and we just had the soup course feeling that makes Passover real.

For me, it's this:



That's the traditional lunch my brother and I eat a few hours before the first seder. Bread and matzo are both off-limits, so we naturally substitute potato chips. Throw in some tuna fish (alas, not the flaming variety), herring, cheese and sour cream and onion dip, and you've got the perfect pre-seder meal. Oh, and you need some sort of desert. Today we did a chocolate bar, but vanilla flavored vegetable fat bars would have been an equally delicious choice. (Who am I kidding? Make that a far more delicious choice!)

Here's to tradition and meaningful meals! Chag S'meach and L'Chaim!

Thursday, April 02, 2015

Light, Heat and Tuna Fish

I'm so trying this on my next camping trip: Toilet Paper Tuna Torch. The basic idea: set the oil on fire that's found in a container of tuna fish in oil, and when you're done, enjoy the tuna fish. Oh CrazyRussianHacker, you never disappoint.

And I've got ask: does it work with sardines in oil, too? I guess there's only one way to find out.

Here's the video:

Watch Video

The Joy of An elisp Powered Code Review

Back in the day, when I was a team lead, I did more than my fair share of code reviews. What made the process relatively painless (at least for me, the reviewer) was a handy elisp function that made citing code from within emacs a breeze. I'd mark a region, hit a keystroke, and I was ready to paste the discussion-worthy code into an e-mail message. Having this function was like having a spell checker in your code editor; a seemingly superfluous feature, until you realize that you're utterly dependent on it.

Unfortunately, somewhere over the years I've lost this magic bit emacs code. Surely there's a whole package dedicated to citing code, but for the life of me, I couldn't find it. And so when I needed to review someone's code yesterday (something I apparently haven't done in years), I rewrote this function.

Now, I can set a region in emacs and type M-x code-review-region and poof! the code is annotated with the file name I grabbed it from, the line number, and a bit of ASCII art to show the item as being quoted. For example, I just ran this function on some utility PHP code:

+---[web/shared/lib/util.php:25]
| function dev_env() {
|   return strtolower(g($_SERVER, 'SERVER_NAME')) == 'localhost';
| }
+---

And here's the elisp function. Happy code reviewing!

(defun code-review-region (beg end)
  (interactive "r")
  (let* ((text (chomp (buffer-substring-no-properties beg end)))
         (line-number (line-number-at-pos))
         (file (buffer-file-name))
         (path (replace-regexp-in-string "^.*branches/" ""
                                         (replace-regexp-in-string 
                                          "^.*trunk/" "" file))))
     (with-temp-buffer
       (insert text)
       (goto-char (point-min))
       (while (re-search-forward "^" nil t)
         (replace-match "| " nil nil))
       (goto-char (point-min))
       (insert (format "+---[%s:%s]\n" path line-number))
       (goto-char (point-max))
       (insert "\n+---\n")
       (kill-region (point-min) (point-max)))))