Sunday, January 31, 2016

Possible New Look

Which should I incorporate first, the stache or the eye patch? Thanks to my little partner in crime for creating this masterpiece with me.

Friday, January 29, 2016

Command Line Hardware Hacking 101 - Raspberry Pi controls an LED

While games are fun and all, I wanted to use my Raspberry Pi as more than just a little Linux box. Specifically, I wanted to use it to drive electric circuits. The Hello World of this sort of project is getting the Pi to turn on and off an LED. Fortunately, the kit Shira gave me as a present came with the LEDs, resisitors, and everything else I'd need to accomplish this little experiment.

It took a bit of poking, but I finally found this YouTube video which walked me through the whole process of hooking up an LED to the Pi. It even gave me the few lines of Python code I'd need to get the LED to turn on. Thanks to Murphy's Law, following the instructions exactly yielded a dead circuit. But on a whim I swapped out the red LED with a yellow one, and whooo! It worked!

It was official, I was a hardware hacker!

With that little success in world of hardware, I decided to turn back to the software side of things. As mentioned above, there's a small Python script that drives the above LED. I wondered, could I replicate this from bash? Turns out, I can. In classic Unix style, there's a set of devices files under /sys/class/gpio that I can trivially write to which controls the state of the LED.

In the Python example, I needed to reference GPIO pin 11. However, at the shell level, I needed to access 17. I sort of get why this is, but for now, I'm not dwelling on this. The bottom line is that I needed to run the following code as root to initialize shell access to the LED:

  echo 17 > /sys/class/gpio/export
  echo out > /sys/class/gpio/gpio17/direction

From there, I could turn on and off the LED by echoing 0 or 1 to /sys/class/gpio/gpio17/value. Which is just too cool, if I do say so myself. Once I had this capability in place, I was able to whip up two quick shell scripts. The first is led and it's a shortcut for turning on and off the LED:



case "$1" in
  on) echo 1 > $GPIO ;;
  off) echo 0 > $GPIO ;;
  *) echo "Usage: `basename $0` {on|off}" ;;

The second is blink which does the same sort of thing, but iterates through durations to turn the LED on and off for:



if [ -z "$1" ] ; then
  echo "Usage: `basename $0` on-time off-time ..."

while [ -n "$1" ] ; do
  echo 1 > $LED
  sleep $1 ; shift
  if [ -n "$1" ] ; then
    echo 0 > $LED
    sleep $1 ; shift

echo 0 > $LED

With these commands in place, the command line hacking can begin!

# led on ; sleep 3 ; led off

# while true ; do ./blink 1 1 ; done

# while true ; do ./blink .5 .5 .25 .25 .5 .5 ; done

# while true ; do ./led on ; sleep .25 ; ./led off ; sleep .25 ; done

Thursday, January 28, 2016

The Adventure Continues on My Android Phone

I just blogged about how I fired up adventure, a very old school text based game, on my Raspberry Pi. The process was actually quite simple, and it's just as straightforward on my Galaxy Note 5. I fired up Gnuroot and typed: apt-get install bsdgames:

From there, I typed adventure and just like that, I was immersed in Interactive Fiction:

Installing bsdgames gives you more than just adventure to play with, learn more here.

Happy spelunking, and remember, beware the knife wielding dwarves!

The Simons Get a Gaming Console!

Check it out, I'm a gamer!

OK, it's not exactly a gaming console per se. It's more a Raspberry Pi running a single old school Unix game. But it's fun none the less!

Shira bought me a Raspberry Pi for my last birthday and I've been struggling to find time to build a wicked cool project with it. It was therefore time for Plan B: do something, anything, to get the Pi out of the box and into use. So I plugged it into our TV downstairs and followed the onscreen setup. Eventually it finished and I was presented with a normal Linux boot up screen. Ahhh, those boot messages fill me with excitement and hope every time I see them. I then followed the instructions to enable WiFi. Within 15 minutes I had a fully functional Linux box that was on the network. Now what?

I've always had a respect for text adventures games (aka Interactive Fiction) and so I thought I'd start there. Installing the grand-daddy of all text adventures games on the Pi was easy. I just ran:

  sudo apt-get install bsdgames

Typing adventure at the command prompt gets you started:

  $ adventure

  Welcome to Adventure!!  Would you like instructions?

  Somewhere nearby is Colossal Cave, where others have found fortunes in
  treasure and gold, though it is rumored that some who enter are never
  seen again.  Magic is said to work in the cave. 

Notice I said had respect for these games, not that I was good at them or even had logged significant play time. That's because every attempt to play a text adventure game has been a dud. When I've fired up adventure in the past I've managed to just wander around the forest being utterly confused. I wanted to like text adventures games, but my experiences playing them were awful.

But not this time! This time I stuck with it! Oh, and I also cheated. See, there are walk-throughs of the game that will help get you started (heck, they'll help you 'win' if you can call it that). So yes, I got a push from various resources on the web. But I've been puzzling my way through the game and have managed to figure out a couple of obstacles all by myself. I dare say, it's actually fun! I'll probably have more to say on this topic as I make more progress in text adventure land.

As for the Pi, it really is an impressive little device. For now, I'm using it as a little more than a Linux box, something that my phone can easily accomplish. But as a learning tool, I see huge possibilities. Much of my daily computing savvy comes from basic Unix and programming skills; skills that an aspiring student could learn using nothing a Pi, their TV and a keyboard.

Update: Here's a handy list of hints that solve specific parts of the game. That's probably preferred to looking at the walk-through which is jam packed with spoilers.

Wednesday, January 27, 2016

The Feel Good Story about Newspapers that Wasn't

Stupid facts; always ruining a good story. See, I had a blog entry pretty much written in my head. The short version went like this:

While talking about yet another detail of our latest winter storm I had an odd thought: our family's definitive source for all things weather is the Capital Weather Gang, which is part of the Washington Post. Isn't it odd that in this day and age, the best weather info I can get is provided by a newspaper? I mean, back in 1913, newspaper based weather reports were probably advanced technology. But by now, doesn't radio, TV and the web trounce newspapers in this department? So what makes the Washington Post so successful?

The problem with this thesis is that the Capital Weather Gang, while owned and hosted over at Washington Post, is really a blog. According to the CWG About page, it was the first local weather blog, started in 2004. In 2008 moved over to

So I don't get my weather from an antiquated source (no offense, newspapers) that's rediscovered its purpose, I get it from the the leading edge of technology: online.

Like I said, facts are so annoying.

Still, there are a number of important lessons here.

First, never underestimate the power of a blog. I know, by now that term is practically antiquated. Still, with a few clicks, you can have your idea online and be competing with established players, and as the Capital Weather Gang shows, you can be victorious. Sure, it takes a huge amount of work, but it's far cheaper than buying printing presses and outfitting a TV studio.

Second, never underestimate the power of good content. Weather seems like it should be nothing more than data. Heck, if I say: OK, Google...what's the weather today I'll get a response from my phone in just a couple of seconds. But as the Capital Weather Gang shows, there's a whole lot more to the story than raw data, and with solid writing, I'll actually want to read about it.

Tuesday, January 26, 2016

Where the Sidewalk Ends, and Other Make-Winter-Great-Again Mysteries

Today Shira I took a leisurely slog along Mount Vernon Bike Trail. The trail is supposed to be on Arlington's list of plowed locations, though, we quickly realized that the trails are getting no love. There was no sign of snow cleanup along the trail, though there were several cross country ski tracks, which made me smile.

In fact, as we finished our little walk, we got notified that the county was now 55% complete in plowing residential streets. That blows my mind: even 3 days after the storm, there are residents who are looking out at their streets and seeing almost two feet of snow piled up in front of them. No wonder schools still have to be closed. Amazing.

To Arlington's credit, they're trying to keep residents informed and are providing twice daily updates of plowing progress.

By the way: I have no idea what's up with the red hearts in the snow below; they were just there and I grabbed a photo. Are they candy? Soap? I've got no idea.

And in answer to the post's headline, the sidewalk ends a few hundred yards past the Pentagon. Apparently they have their own snow cleanup crews, and they're glad to clean the sidewalk. To a point.

Sunday, January 24, 2016

Recovering from MakeWinterGreatAgain

It's official: we made it through the snowfall of MakeWinterGreatAgain, aka Snowzilla, aka Jonas and now we're on to the cleanup. Our particular street is rated by Arlington County as a secondary priority road, which means that by the time we were done shoveling our driveway, you could see the pavement in front of our house. A number of other streets in our neighborhood, which don't rank on this scale, have yet to see a plow at all. So yeah, nobody's going anywhere tomorrow or probably the next day.

I wanted to do more exploring and perhaps a bit of sledding but Arlington County has been pleading with residents to stay off the roads, including walkers. So we're trying to give the folks doing serious cleanup work a break and staying put. Now I've just got to convince Shira to help me build one of these...

Stay warm and safe.

Friday, January 22, 2016

How to Prepare for a DC Snow Event

Here it is, your handy three step guide:

Step 1. Get things going early. Say, by suggesting 4 days ahead of the snow that the storm will be a threat to "life & property"

Step 2. Name the storm. This step is essential; you can't fear what you can't name. By the way, I'm fully behind the currently recommended name: Make Winter Great Again.

Step 3. Actually panic. Basically, do this:

And there you go, you're all set for a DC weather event!

Gotcha of the Day: Finding the source of SPAM from a WordPress install

One of my clients who runs WordPress reached out to me earlier: they had received notification that they're system was sending out SPAM. D'oh. I helped them do the usual fixes: update WordPress and plugins, change passwords, and double check the security scanner they had in place to see if there were any other know issues.

While poking around for a possible lead to the cause of their issue I came across this post: Tracing Spam from PHP Scripts. The very short version of the post is this:

If you set mail.log in php.ini to a webserver writeable path, all calls to mail(...) will be logged for you.

I set this up and as the author Eric promised, a few hours later I saw entries like these:

mail() on [/var/www/vhosts/]: \
  To: -- Headers: From: "XXX XXX"  ... \
  Content-Type: text/html; charset="iso-8859-1"  Content-Transfer-Encoding: 8bit

And just like that, I knew where to find the malicious script in question. A quick search under uploads yielded 3 .php files, all filled with malicious code.

This Whack-a-Mole approach, of course, isn't sustainable long term. I've already suggested that this organization sign up with sucuri, as I've had great success in having them finding and fixing WordPress issues (one memorable occasion happened on Christmas Day, no less). But to actually witness this attack in action is pretty sweet; and all through a simple config file tweak no less.

mail.log is definitely my new SPAM stopping best friend.

Thursday, January 21, 2016

All of 2015's Weather in under 2 minutes

While poking around I came across this archive of US weather maps and thought what any reasonable person would think: I wonder what a movie showing all 365 days of weather would look like? To answer that question, I did the following:

Step 1. Grab the raw images. This was too easy:

$ cat > grab


for m in `seq 1 12`; do
  for d in `seq 1 30`; do
    for h in 00 12 ; do
      url=`printf "" $m $d $h`
      wget -O `printf "map_%02d%02d%02d.gif" $m $d $h` $url
$ chmod a+rx grab
$ ./grab

Step 2. Convert and crop the files so that they just contained maps. Again, we're talking child's play:

$ mkdir jpegs
$ for f in *.gif ; 
   do convert -crop 510x366+0+0 $f jpegs/`basename $f .gif`.jpg;

Step 3. Convert the images into a mp4 video. So simple:

$ ffmpeg -framerate 7 -pattern_type glob -i 'jpegs/*.jpg' -c:v libx264 -pix_fmt yuv420p out.mp4

Step 4. Upload the file to YouTube and watch the Likes roll in. Uploading the file was easy enough and adding audio definitely helped make the video at least somewhat watchable.

So what does one year of weather maps strung together into a movie look like? Well, here you go:

I've got to say, the results are Feh at best. The characters are weak, the plot is predictable and the special effects way over the top. In all seriousness, it was an interesting exercise, but unless you're a weather geek, I doubt you'll find this particularly riveting.

Wednesday, January 20, 2016

Compass Kudos

A few weeks back I noted that my last two attempts at carrying a compass on my keychain had resulted in two out of whack compasses. The compasses in question were the Silva Metro and County Comm SERE. After posting about my experience I dropped a note to both companies asking for help.

CountyComm quickly got back to me letting me know that they'd gladly replace the compass. Silva responded by saying that I needed to contact the Swedish branch of Silva ( not the US. I did so, and they gave me an address in Sweden to send the compass back to.

I quickly scribbled off hand written notes to both companies, dropped the compasses in a regular old mail envelope and dropped them into the postal abyss.

And yesterday, to my shock, I received back two new compasses: one from County Comm and one from Silva in Sweden. Heck, the one from Sweden even had a nice little hand written note:

For now I'm continuing to use the TAC Compass, which is ridiculously tiny, yet still somewhat accurate:

What the TAC Compass loses in accuracy it gains in being so stashable. I'm just hoping it can hold up to the pressures of being tossed in and out of my pocket.

Well played Silva and County Comm, well played.

Tuesday, January 19, 2016

Welcome to Manhood

Such confidence! Such wisdom! Such appetizers! My nephew knocked the ball out of the park yesterday with his Bar Mitzvah. He led services, read Torah, and gave an insightful and entertaining speech--it was truly awesome. It didn't hurt that my Brother and Sister-in-Law delivered on one heck of a party (oy, I think I'm still full!). Such a good time.

Definitely a simcha to savor!

Please Auntie Sheri, may I have some more? infinite supply of treats. In Auntie Sheri's defense, she was dolling out blueberries, and she is a certified Gradma.

Sunday, January 17, 2016

He's Da Man

OK, technically he'll be the man tomorrow, after his Bar Mitzvah. It sure was awesome celebrating the upcoming event with my nephew, niece and the rest of the family.

Would I have liked a photo with all my family in it? Sure, but they're a loud and disorganized bunch, so that was never going to happen. The photo below will have to serve as just a sample. Definitely fun times!

Finally a dose of Winter Weather

OK, it's not exactly a Winter Wonderland, but it is our first real snow. Whoo!

Friday, January 15, 2016

The Children's Book You Thought You Knew

Time for a little quiz. Don't worry, it's easy, I promise.

What's the name of this 'family?'

Even though I haven't read one of these books in years, the answer is obvious: it's the Berenstein Bears! Like The Little Engine That Could or The Rabbi and the 29 Witches, the Bears were beloved books of my childhood.

There's only one small detail. That's not the name of the family. As I found out a few days ago, I've been wrong my whole life. That's the Berenstain Bears in the cover above, as in 'stain' not 'stein.' If you're like me, you'll rush off to Amazon to check. No problem, I'll wait here. Google will gladly correct your spelling, as well.

If you're also like me, you're world has been shaken a bit. Don't worry, this post has the answer:

Here's the thing. These books play such a huge role in the collective memories of so many people, all of whom clearly and distinctly remember "BerenstEin", that I am not the first to propose the notion that somehow, at some time in the last 10 years or so, reality has been tampered with and history has been retroactively changed. The bears really were called the "BerenstEin Bears" when we were growing up, but now reality has been altered such that the name of the bears has been changed post hoc.


I would like to make a modest proposal: We are all living in our own parallel universe.

There is at least one other universe parallel to our own. I will distinguish the two by the stEin universe and the stAin universe, depending on the surname of the creators of the famous children's book. The stEin universe was the world we resided in during the 1990s. Sometime after we all stopped reading kids books, that is when we were shifted in to the stAin universe. There may be more differences than just the surname of the Berenst_ins, in fact there almost certainly are more differences, and we just need to find them.

Somehow this theory of parallel universes seems more comforting than the possibility that we pronounced it wrong. Either way, go read the whole theory here, it's definitely a mind bending way to start your Friday.

Thanks to and for leading me to this theory. Berenstein Bears forever!

Thursday, January 14, 2016

The $3.00, 11 gram Water Filter You Probably Shouldn't Use

I was so impressed with djbarryiii's YouTube video showing how to create an ultra-light, ultra-cheap, ultra-durable water filter that I had to try it myself. The project is really simple: purchase a 1 micron bio-diesel filter off of eBay, cut out a circle and fold it using the technique you probably learned in high school chem lab to produce a sort of funnel. And you're done. Here's the filter next to a LifeStraw for comparison purposes:

Now before you chuck your water purification device of choice, here's a few reasons why the above is a bad idea:

1.The bio-diesel filter is a nominal, not absolute, filter. That means that that most objects 1 micron or larger will be filtered out. Did you catch that 'most'? A nominal filter will allow some particles larger than the size it's rated at to pass. An absolute filter, like the LifeStraw, has no space larger than it's claimed size, so it filters as advertised.

2. While 1 micron will filter out the 5 micron size Giardia and Cryptosporidium, it won't filter out other nasty stuff, like Cholera, E. Coli, and Salmonella (source:, not to mention viruses which are even smaller. The LifeStraw does far better with an absolute filter size of .2 microns.

That's not to say that this little hack doesn't have some serious advantages going for it. The obvious ones are that its relatively cheap and quite compact.

With limited experience I can tell you that the larger the disk size, the easier it is to use. When I cut out the first disk I used a tuna fish can as a stencil. The result when folded is a relatively small reservoir, that required slowly pouring water into the filter, being careful not to overflow it. The larger size, as pictured above, was created by using a Cool Whip container as a stencil (what can I say, I used what I had). The result when folded is a nice size reservoir that still requires care when filling, but allows for a descent flow rate.

Oh, and speaking of lessons learned: I originally purchased a 0.5 micron bio-diesel filter bag thinking it would be an even more effective option. Alas, the filter is so fine it has almost no flow rate. It was way too slow to be at all practical.

While the disk above is compact and lays flat, it's not quite small enough to be stashed in my wallet (alas, it would have made a sweet EDC water filter). It's definitely compact enough to store in a glove compartment, dropped into a day pack or stuffed into a under-seat bike bag. Heck, it might even find a place in my trail running kit.

Chemical purification tablets may be smaller than this filter, but they suffer from a number of annoyances. Katadyn, for example, claims to take up to 4 hours to fully work. Further more, the tablets are really optimized for quarts of water. If you want a relatively quick drink now, a filter would allow you to process just a cup full of water, versus purifying a quart and waiting for hours before the water is ready.

Another key advantage to this sort of filter is how flexible it is. I don't mean that literally, though it is indeed physically flexible. I mean that you can use the filter to rig up a water purification system using whatever materials you have handy.

Given all of the above, it doesn't look like I'll be chucking my Portable Aqua tablets anytime soon. But as a backup solution, say on a trail run when space and weight are a premium, I could definitely see putting this filter to work.

Here's the video that inspired it all:

Wednesday, January 13, 2016

Mystery Solved: One Approach to Spot-It Game Card Generation

Spot-It is one of my go-to quick games for kids and adults alike. Many a wait at the pediatrician's office has been made that much more bearable thanks to this handy little game. While there are a few variations for playing it, they all involve the same basic strategy: the faster you can spot the match between any two Spot-It cards, the better. Which brings me to the cards:

The magic of the game is this: every card matches every other card exactly once. Take a moment and confirm this by looking at the cards above.

Every time I play Spot-It I think to myself: how the heck did that do that? And so after a rousing game a few weeks ago I decided I'd have to find out. And what better way to do so than to write some code to generate my own deck of cards?

And so began a multi-week saga in puzzling out a solution. I have to admit, the problem pretty much kicked my butt. If you look at the history of my code, you'll see all sorts of wrong headed attempts. From a random statistical solution, to mutating vectors full of vectors, I tried in vain to crack the problem. For the last few weeks our table has been covered in little scraps of paper, like so:

But I lived with the problem, and during last week's dentist cleaning, I had a bit of breakthrough. Luckily, I had to wait for Shira to finish up, and so that gave me some time in the waiting room to work on a solution. I can't imagine what the receptionist thought as I tore apart pages from my pocket notepad to create prototype cards. From there, I busted out my keyboard and coded up my new insights. Alas, that solution had flaws, but it took me in the right direction.

Finally, I realized I needed a solution that had a component of backtracking to it. Luckily, before I jumped in and implemented amb, and I discovered I could get this backtracking by using simple recursion. I finally figured out the the last iteration of a solution on a jog a few days ago, and then last night I typed it in. And voila!, I give you a generated set of Spot-It cards:

OK, the above uses numbers instead of funky symbols. But the core principle holds: each card (implemented as a list of numbers) matches each other card exactly once. The prettification of the output is left as an exercise to the reader.

I'm sure there's a much more elegant solution to this problem than mine. However, for now, I'm just enjoying that feeling that comes from living with, and ultimately conquering, a problem. Whoo!

And here's the code. The mystery to Spot-It card generation (or at least, one version) is revealed below:

;; Not an actual programming praxis exercise, but it should be.
;; Implement the spot-it game card sequence
;; Every card matches every other card in exactly one way

#lang scheme

(define (inc x)
  (+ x 1))
(define (dec x)
  (- x 1))

(define (make-symbol-generator)
  (let ([x 0])
    (lambda ()
      (set! x (inc x))

(define (card-match? c1 c2)
  (cond ([null? c1] #f)
        ([null? c2] #f)
        ([member (car c1) c2] #t)
        (else (card-match? (cdr c1) c2))))

(define (make-deck n sym-gen)
  (if (exact? (sqrt n))
      (apply append
             (for/list ([i (sqrt n)])
               (let ([sym (sym-gen)])
                 (for/list ([j (sqrt n)])
                   (list sym)))))
      (error "Deck size must a perfect square")))
(define (can-add-to-pile? card pile)
  (cond ([null? pile] #t)
        ((not [card-match? (car pile) card])
         (can-add-to-pile? card (cdr pile)))
        (else #f)))

(define (grow-pile pile size deck)
  (cond ([= size 0] pile)
        ([null? deck] #f)
         (let ([card (car deck)])
           (if (and (can-add-to-pile? card pile)
                    (grow-pile (cons card pile) (dec size) (cdr deck)))
               (grow-pile (cons card pile) (dec size) (cdr deck))
               (grow-pile pile size (cdr deck)))))))

(define (remove-pile-from-deck pile deck)
  (filter (lambda (card)
            (not (memq card pile)))

(define (match-pile pile sym-gen)
  (let ([sym (sym-gen)])
    (map (lambda (card)
           (cons sym card))

(define (done? deck)
  (let loop ([cards deck])
    (cond ([null? cards] #t)
           (if (andmap (lambda (c)
                         (card-match? c (car cards)))
               (loop (cdr cards))

(define (tick deck sym-gen)
  (let ([psize (sqrt (length deck))])
    (let loop ([i 0] [deck deck] [piles '()])
      (cond ([= i psize]
             (apply append (map (lambda (p)
                                  (match-pile p sym-gen))
             (let ([pile (grow-pile '() psize deck)])
               (loop (inc i)
                     (remove-pile-from-deck pile deck)
                     (cons pile piles))))))))

(define (go size)
  (let ([sym-gen (make-symbol-generator)])
    (let loop ([deck (make-deck size sym-gen)])
      (cond ([done? deck] deck)
              (tick deck sym-gen)))))))

(go 9)
(go 16)

Tuesday, January 12, 2016

The Most Precious Letter Never Mailed

Apparently my nephew Dovid was tasked with writing a postcard, and who should he author it to? But his Uncle Ben and Aunt Shira, of course! Check out this beauty:

A few points of note:

  • The Boy correctly wrote out his address, so I redacted it. Good for him!
  • I love his creative spelling of Uncle. I mean, I completely agree, there should be an i and g in it.
  • OK, so if you read it with the right voice, it kind of sounds like a threat. But it's a good threat, we look forward to the visit.
  • I love that he wrote the letter without using any of the words in the box. Do you think Hemingway would have relied on this crutch? I think not!

I simply couldn't be more proud!

Monday, January 11, 2016

Talking College to Middle Schoolers

Last Friday Shira and I visited a Fairfax Middle School to talk to 7th and 8th graders who are in AVID. Some parts of middle school hadn't changed:

And some parts had:

From what I can tell, AVID is a sort of pre-pre-college prep program, that helps reach kids who might not think going to college is an option. It goes beyond preaching the importance of college, and helps them focus on selecting the ideal college and making the most of your time there. I've always thought that schools should focus on nuts and bolts skills that will help build a foundation for being a responsible adult (Civics, anyone?) and this program seems directly in line with that.

Shira and I actually had two totally different high school, college and post college experiences. In fact, like most things about my wife, I'm her opposite. Shira was in the top of our high school class, I was in the middle. Shira got in early decision to an Ivy League institution, I managed to land a place at a state school (Go UB!). I quickly settled on a major and career path; Shira meandered. It was quite the display of contrasts with an important lesson: you can go about high school, college and career a number of different ways and still be quite successful.

The kids listened and asked questions and generally proved how responsible 7th and 8th graders can be. I think we may have instilled a bit of panic when explaining that some classes in college are curved, and that you might get a 91 on a test and have that be a C.

It was definitely fun to share the good o'l days with a classroom of young'uns.