Tuesday, July 29, 2014

Gotcha of the Day: Accessing AWS EC2 Tags from within PHP

I've got bunch of dedicated EC2 instances running, and I'd like an easy way to configure the web app that runs on them. While I could control their configuration any number of ways, it occurred to me that it would be pretty dang sweet to be able to set parameters from within the Amazon Web Console. Each instance can have a number of tags associated with it, so if I could access those tags from within the server, I'd be golden.

Turns out, getting access to the tags isn't especially hard and is explained here. Essentially, you need to grab two programs from the web: ec2-metadata (or, use curl) and ec2-describe-tags.

Given these tools, I was able to write the following init script:

#!/bin/bash

##
## Capture the ec2 tags associated with this server. Not
## really a long running process. Just something that can
## be invoked whenever
##

RETVAL=0
prog=`basename $0`
ec2_metadata=/usr/local/bin/ec2-metadata
ec2_describe_tags=/usr/local/bin/ec2-describe-tags
etc_tags=/usr/local/etc/ec2-tags

function start() {
  echo -n "Starting $prog: "
  instance_id=`$ec2_metadata | grep instance-id: | sed 's/^.*: //'`
  $ec2_describe_tags | grep  $instance_id | awk -F'\t' '{printf "%s:%s\n", $4, $5}' > $etc_tags
  echo "OK"
}

function stop() {
  echo "Stopping $prog: OK"
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    stop
    start
    ;;
  *)
    echo "Usage: $prog {start|stop|restart}"
    RETVAL=2
esac

(This lives in /etc/rc.d/init.d/ec2tags)

I then setup a softlink to this init script in /etc/rc.d/rc3.d/S80ec2tags.

Now, when the server boots the script runs, which generates /usr/local/etc/ec2-tags. For now, I'm manually updating the configuration by changing the parameters and running /etc/rc.d/init.d/ec2tags restart. Though, that could certainly be setup to be automated.

Finally, to get access these values in PHP, I've written this function:

function app_env() {
  $env = array();
  $fd = fopen("/usr/local/etc/ec2-tags", "r");
  while($line = fgets($fd)) {
    list($key, $value) = explode(":", $line);
    $env[trim($key)] = trim($value);
  }
  return $env;
}

And I'm all set. Now, my PHP code can efficiently read EC2 tags, and I can control the configuration of my servers from a central location.

Like Lego Blocks For Your Yard

I have to admit, a gray block of cement doesn't strike me as an ideal gardening tool. But, if you trust the web, you'll see that I'm wrong on this one. Cinder blocks turn out to be a Lego-like tool for creating gardening solutions. Because of their natural heft, they allow you to do many interesting projects without using any additional tools. Just stack, and go. You can use them to fill up large areas, small areas, build up, or create terraces. Pretty dang impressive.

I think they'd fit well with the experimental gardening approach I've been fooling around with this year. They let you start small, see what works, and add on as necessary.

Now, if I can just convince Shira that gray blocks of cement in our yard are going to look glorious, I'll be all set. (Yeah, good luck with that.)

Below are some samples from the web of ways cinder blocks have been deployed. Click on the images to see the story behind each design.

Check out pinterest for even more designs. And here's a list of projects for all those left over cinder blocks you've got lying around after you overbought for your garden.

Monday, July 28, 2014

One More Billy Joel Post

A picture's worth a 1000 words, so what's 30 seconds of audio worth?

I'm not sure, but I know it's worth something.

Listening to this ridiculously low quality recording from a 2005 U2 Concert may not mean much to you, but to me, it's nothing short of a time machine.

In that spirit, here's some audio snippets from the Billy Joel concert we attended over the weekend.

Listen to all audio clips I captured here.

Sunday, July 27, 2014

The Piano Man's Still Got It

Last night we saw Billy Joel in concert, and to be expected, he really rocked the place. It's actually my second time seeing him play, the first time was 8 years ago at the Verizon Center.

Watching him play at Nationals Park was a real treat. For one thing, it was the perfect night for open air seating. And for another, most of the ballpark restaurants were open, so I was able to get a Veggie Cheese Steak and it was actually pretty good. (Let's ignore the fact that the prices are criminal, and between the "steak" sandwich and an ice cream cone I needed to take out a second mortgage on the house.)

Gavin Degraw opened for Billy, and he certainly gave it his all. But the sound system just wasn't tuned for his setup, and the result was loud music, but I couldn't really understand the lyrics. Luckily, Billy's setup was tuned to perfection, and he was nice and clear.

Now, I'm not much of a Billy Joel aficionado. Still, I'e been hearing him play my whole life, and his music triggers quite a few memories. I'd get out on the dance floor at USY Dances with my Older Brother to rock out to We Didn't Start The Fire, and I remember sitting in my family room listening to the River of Dreams CD over and over again (that was back before you had instant free access to any song in the world). Of the 23 songs he played last night, I knew 22 of them (time to listen to Zanzibar to learn that one, too). I could at least mumble along to all 22 songs, which isn't something I can say for nearly any other artist on the planet.

Thinking back to our last concert with Billy, I'm pretty sure he had the same set list, and the same rotating piano, and the same black suit (man, that had to have been hot!). But, I can hardly blame him; people came to hear his hits, and that's what he delivered.

An amazing musician, and amazing time!

Friday, July 25, 2014

A Rule of Thumb for Success

Seth Godin gives lots of insights in this interview, but one quick nugget to take away is this:

If I fail more than you, I win.

(The presumption of course, is that the failures we're talking about aren't the catastrophic kind. They may hurt, but they'll allow you to get back in the game and try again.)

Think about the above statement, and you'll see it has powerful implications.

Give the whole interview a watch, it's more than worth your time:

Thanks to Wisdom and Wonder for pointing me to the video.

Name that Tree: Wispy Pink Flower Edition

For months now, I've been coming across this tree with unusual pink flowers, but for one reason or another, I haven't been able to grab a photo of it. That changed last night while running along the Custis Trail. I finally got a few basic photos:

Don't those blossoms look like they belong in a tropical paradise, or at the very least, in a botanical garden? What the heck is this tree doing randomly along Custis Trail, and more importantly, what's it called?

Not quite sure the technical term to describe the flowers, I just took my best guess and entered the following into Google Images: Tree Wispy Pink Flowers. The first hit was a perfect match:

I've said it before, but I'll say it again: Google Images is an amazing tool for plant identification.

According to that first hit I was looking at a Memosa Tree (aka Silk Tree, aka Albizia julibrissin). Apparently the trees are both exotic looking and tough as nails, as they will grow pretty much anywhere (including along a random bike trail). It's not all good news, though, as they are considered an invasive species in Virginia, and all those blossoms leave quite a mess, which make them less than ideal for urban design.

There's various back and forth as to what parts of the tree are edible. There doesn't appear to be a common part of the tree people consume, yet in the comments here, people claim that eat just about all of it. It has a tradition of being used for medical purposes, including making tea from the leaves and using the bark as a "mood enhancer". Though, the exact details are all a little sketchy.

Bottom line: looks like this is one of those trees to marvel at, but avoid planting or nibbling on.

Thursday, July 24, 2014

Large Format Photography On The (Very) Cheap

Merging my love of photography, building stuff and clever hacks, this Shoebox Large Format camera is officially awesome:

All you need to build one are a shoebox, some black cardboard paper, a punch tool and a lens. The creator of the project had an old camera lying around they could tear apart for the lens. It looks like this $4.00 (for two!) option from SciPlus would suffice (both are positive meniscus lenses, right?).

The trickier issue is the "film" side of things. The author used photo paper, which isn't too terribly expensive, but then you've got to craft some sort of photo developing lab, to actually bring the prints to life.

I wonder if you could build the camera, but replace the back with tissue paper thereby creating a camera obscura. Then, you could go old school and drape a black cloth over the whole thing. You'd then climb underneath and snap a photo of the back of the camera with your cell phone.

Or is that cheating?

Either way, it's a fun project to try. I may have to pick up the lenses just to have them on hand to experiment with.

Check out the instructions for a sample of the images produced by the camera. Impressive stuff.

Via: brainwagon

Entertained and Informed, No Electricity Needed

Two days ago I caught this piece from the NPR archive: Cigar Stories: El Lector - He Who Reads (also found here) and I was really impressed. Apparently, back in the heyday of hand rolled cigars, the workers would make their task a lot less tedious by hiring a professional reader. He'd sit at a central lectern and regale them with various tales.

Apparently, the content they read was all over the board: from local and international news, to novels and poetry, to political manifestos, to anything else the workers wanted.

The result: the workers were not only entertained, but well educated and informed. No electricity or Internet required; just some reading material and an individual with a gift for projecting his voice to potentially hundreds of people.

That's a mighty brilliant hack. Low tech, and highly effective.

Here, give the piece a listen:

Tuesday, July 22, 2014

Picking The Right Stove for a Destination Camping Trip

We've got a camping trip coming up in a few weeks, but there's a wrinkle: we're flying to the location. Most of our gear can be taken on the plane without a problem; the big exception being the stove fuel. What's a traveling camper to do?

1. Go Stoveless. I'd be all over this option, except this violates Rule #3, which isn't acceptable.

2. Rely on a campfire. Again, this would be my preference, but I'm not quite sure what the destination will have in terms of wood availability (I do know the fires are allowed in designated areas). Better to bring a stove, then chance it.

3. Bring our MSR Pocket Rocket stove. This bad boy is remarkably effective, but I'm not sure how easy it's going to be to get fuel. Again, I don't want to leave our meals to chance. Shipping the IsoPro fuel appears to be a no-no.

4. Bring an alcohol stove. Finding HEET, the readily available fuel alcohol stoves typically use, shouldn't be too tricky. Between gas stations, Auto Parts stores and Walmart someone has to have it. On the other hand, HEET is an anti-freeze product, so it's not exactly in season. While probably available, it's still not a sure thing.

5. Hit WalMart and buy a cheap Coleman stove and propane canister. I seriously considered this option, especially because this camping trip isn't exactly backpacking (though, it's not exactly car camping either). But, what would I do with the supplies when I was done? Seems like a waste / hassle for one weekend.

6. Use an Esbit Stove. I experimented with one a couple of trips ago, and was pleased at how effective it was. Most importantly, they use the one fuel that we can ship ahead of time. There are other advantages to Esbit: they don't spill like alcohol, they're easy to take inventory of, and they are naturally lightweight. The cons, is that they are a crude method of cooking, and there's some variation in burn time and efficiency. You can definitely cook on these guys, so I know that they aren't purely a gimmick.

The winner: the Esbit Stove. I love that I can ship the fuel ahead of time and know exactly where I stand with it. The 12 tablets I ordered should be more than enough for 2 dinners, and 2 breakfasts. This setup should also work because I planning to use the stove as more of a backup, than a primary cooking option (at least for dinners).

While I'm at it, I'll also keep an eye open for a bottle of HEET when we land at our destination. If I can find such a bottle, creating a field expedient alcohol stove should be easy enough. (Just pick up a couple of cans of soda at the same time and there are your raw materials.)

Do. Or Do Not. There is No Try. At least when it comes to drawing Yoda.

Makes and Takes recently featured an excellent set of Learn To Draw Resources for kids. I'm a big fan of Ed Emberley's books, which use similar techniques, but have the benefit of being always available (well, available anywhere you've got the web. Which is always.).

Consider this How to Draw Yoda example from Art for Kids:

It's really well done, and definitely something that would work well for an older kid to follow along with.

I also love the mix and match robot drawing ideas. Definitely a keeper.

LinkWithin

Related Posts with Thumbnails