Monday, November 25, 2019

WP Plugin Hacking: Adding a [learn-more] tag to Simple Calendar's Event Template Tags

I'm helping a team of folks revamp our Shul's website and one area we're focusing on is the events/calendar section. Like most organizations, we've got to balance sharing information with the need to minimize maintenance. Simply put, having to keep event data manually in sync in multiple locations is a recipe for disaster.

The Simple Calendar WordPress plugin solves most of this challenge. It lets the office staff maintain a master Google Calendar and the website's event page renders using this data.

The ability to use the plugin's Event Template Tags means that the web team can customize how events appear and can publish them in the clearest way possible.

The challenge comes, however, when we consider the amount of information tracked in a Google Calendar entry. The essentials are there: title, when, where and a description but extra information that we'd like published on the website is missing. Is there a fee for this event? Is it kid friendly? What's the dress code? And so on.

We could cram this information into the description of a Google Calendar entry, but that will be both painful to manage and throw off other apps using the master calendar feed.

Our solution is to create a WordPress post for each event that contains all the event details. This is easy enough to do, but leaves us with the new challenge of how we link these posts from within an event template. I'd hoped I could write a bit of code to do this, but the Simple Calendar plugin docs don't mention any hooks or filters that I could tie into.

Fortunately, looking through the plugin source code I realized that such hooks do exist, mainly: simcal_event_tags_add_custom and simcal_event_tags_do_custom.

Below is the code for a trivial plugin that lets you auto-link a 'Learn More' post to a calendar entry. Once the plugin is enabled, you can use the [learn-more] tag to link to the relevant post within an event template:

Posts are associated with a calendar by setting a custom field to the relevant calendar entry ID:

Calendar entry IDs are shown to admin users when they visit the events page. So using them requires a bit of copying and pasting, but it isn't hard to do.

This scheme should provide us the best of both worlds: a centralized calendar for easy management, and support for detailed information on the website that is auto-linked to the calendar.

Here's the plugin code that makes this all work:

<?php
/*
Plugin Name: Simple Calendar Learn More
Description: A plugin to add a [learn-more] link to the simple calendar Event Tags.
Version: 1.0.0
Author: Ben Simon
*/


add_filter('simcal_event_tags_add_custom', function($tags) {
  $tags[] = 'learn-more';

  return $tags;
});

add_filter('simcal_event_tags_do_custom', function($body, $tag, $partial, $attr, $event) {
  if($tag == 'learn-more') {
    $id = str_replace('@google.com', '', $event->ical_id);
    $attrs = shortcode_atts([
      'newwindow' => 'yes',
      'label'     => "Learn More"
    ], shortcode_parse_atts($attr));

    $posts = get_posts([
      'meta_key' => 'calendar-id',
      'meta_value' => $id
    ]);

    $html = '';

    if($posts) {
      $label = $attrs['label'];
      $target = $attrs['newwindow'] == 'yes' ? 'target="_blank"' : '';
      $url    = get_permalink($posts[0]);
      $html = "<a href='$url' $target>$label</a>";
    }

    if(current_user_can('edit_posts')) {
      $html .= "<p style='text-align: right'><small>calendar-id is <i>$id</i></small></p>";
    }
    return $html;

  } else {
    return $body;
  }
}, 10, 5);


?>

Friday, November 22, 2019

One Route to a Route Planning Spreadsheet

Ever live by a sage piece of advice, only to go back and find that such advice was never actually given? That's how I'm feeling about the topic I'm writing about today.

In my mind's eye, I can recall learning an important lesson from DIY Endurance Athlete Matt Kirk: step one in crafting a self-designed adventure is to create a spreadsheet outlining the plan. Back in 2015, I can see evidence of Matt's advice in action with his Cross Florida Run. Here is the planning spreadsheet that made such a big impact on me. I haven't looked at this spreadsheet or his trip report in years and yet I still find both move me!

But here's the thing: I can find no evidence that his Cross Florida Run or any other adventure was planned initially in spreadsheet form. Either I can't find the post where he offered up this advice, or more likely, I just assumed it. For all I know, Matt Kirk hates spreadsheets and thinks trip planning using them is a waste.

Either way, I took his never-dispensed advice on my last big run. You can find the planning spreadsheet here. Matt's planning doc covers nearly 150 miles. In comparison, mine covers a paltry 22. I created mine mainly to field test the idea for longer adventures, and yet, I found the document to be surprisingly useful. Using it I had a solid sense of both timing and caloric needs and it let me relax and enjoy the run knowing I was prepared for the ordeal.

So while Matt Kirk never said (or said it, and I've lost the source) a planning spreadsheet is key for your next Big Adventure, I'll say it is. And I'll go further, I'll give you my algorithm for creating such a document.


Step 1. Plan a general route by dropping waypoints into a Google 'My Map'.

I have mixed feelings about Google's My Map tool. On one hand, it lets you easily notate key points on a map. On the other, I find the tools generally clunky and frustrating to use. The distance tool, for example, is always tripping me up. Regardless, I know of no better way to generally outline your plan than waypoints on a My Map.

Step 2. Export your My Map as a KML file and convert the KML file to text using GPS Visualizer.

GPS Visualizer is your map-data Swiss Army Knife; learn it and love it. Google My Maps deals with KML files, my Garmin InReach likes GPX files and Google Sheets likes delimited text. GPS Visualizer will let you convert to and from these formats with ease.

Step 3. Import the CSV file into a Google Sheet.

Importing from a Google My Map insures you're not copying and pasting lat/long values which are easily mucked up.

Step 4. Use the imported waypoints to construct a detailed set of checkpoints.

In this case I'm doing an out-and-back route so the second half of the checkpoints are a mirror of the first half.

Step 5. Add terrain, distance and calculate estimated duration per checkpoint.

I've had success estimating distance using Google's My Map measuring tool as well using Google Map's built in distance measuring tool. I find the Google Maps tool to be far easier to use than the My Maps version.

After noting the distance to the checkpoint, I'll consider the terrain I'll be encountering while getting myself to that checkpoint. Each terrain is assigned a minutes per mile pace in a lookup table:

Finally, a bit of basic spreadsheet math is used to calculate the amount of time needed to make it to the checkpoint:

  =(vlookup(D2,Pacing,2,false) * C2)/1440

The vlookup() pull the minutes per mile value, and the division by 1440 (the number of minutes in a day) converts the value to a Google Sheets time value. Once the time value is calculated, you can adjust the format to 'duration' to see a properly formatted time.

Step 6. Create a route summary including a calorie needs estimate.

The route summary consists of basic spreadsheet math. The distance and estimated time sum up the relevant columns from the Checkpoint sheet. The caloric estimate is calculated by assuming I'll eat a certain number of calories every X minutes. For a long run, I plan to consume 100 calories every 30 minutes. But of course this is a spreadsheet, so those values are easily tweaked.

Step 7. Add in calorie source details.

There's nothing special about the caloric detail. It's simply a sum of all the calories I'll bring with me on the adventure. Having this in spreadsheet form is useful because I can substitute foods the day of and know that I'm still nutritionally covered.

Using the planned nutrition data I can trivially calculate how much of a buffer of food I'm planning to bring:

Step 8. Create a GPX file for import into Backcountry Navigator and the Garmin In-Reach

Back to GPS Visualizer we go! The goal will be to convert our textual data from the Checkpoints tab to a GPX file that most navigational programs and devices understand. To simplify this, you can create a formula that generates the data GPS Visualizer expects:

="C" & text(A2,"00") & ": " & B2 & "," & F2 & "," & G2

And your done! You've now got a document that serves a number of important uses. It lets you think about a large adventure in small chunks, plan a reasonable amount of time for said adventure and insure you've got a nutrition plan in mind. You also have a document you can share with family and friends so they know your route and plan.

You can find the sample document I worked through above here.

Tuesday, November 19, 2019

Escape! Midway! Oorah!

This past weekend we hosted my Mother-in-Law and her boyfriend. We did a number of enjoyable activities, each of which left me with quite the impression.

Escape!

First off, with the help of my Brother and Sister-in-Law, the six of us busted out of Escape Room Arlington. This was Shira and my third Escape Room, and our first one solved without hints! This particular Escape Room is located up the street from us, so Shira and I were excited to try it out, if only to support a hyper-local business. We were all impressed the experience. The challenge, entitled Secret in the Attic sounded scary, but as promised was wholesome family fun.

The room employed a number of tricks we'd seen in our past Escape Rooms, as well as some game-changing new ones. The room was complex enough that we could all be busy working on different puzzles, yet it was easy enough that we kept making forward progress. If you're new to the Escape Room concept and looking for a good first challenge, Escape Arlington's Secret in the Attic is ideal.

Midway!

Saturday night we took in the movie Midway, which takes you through the Battle of Midway during World War II. I'm still processing this movie and I haven't determined whether I liked it or not. On one hand, the story arc seems long to the point of being excessive. I get that to appreciate Midway as a turning point you have to understand just how much of an underdog the US Navy was. But my gosh, that made for a long run-up to the action. Of course, had the film skimped on backstory, I'd probably be griping about how the film needed more context.

And then there are the cliche characters. Perhaps these really were made-for-movie personalities, but everyone from the geeky code breaker to cowboy-fighter-pilot seemed to fit the exact stereotype you'd have for that role. I'm not buying it.

On the plus side, the attack scenes are done well and give you a sense of how seemingly impossible the task of taking out a Japanese aircraft carrier would be.

I was surprised when I glanced over at the IMDB reviews at just how many folks liked the movie. The consensus from the top reviewers was that the movie gets the historic facts right with a minimum of distractions. So maybe the movie deserves more credit then I'm prepared to give it.

Oorah!

We finished our weekend with a visit to the National Museum of Marine Corps. Shira and I have been to the museum a number of times, but it still ranks as one of the best in the area. While I enjoyed my stroll through the various exhibits, it occurred to me after the fact that I really should have mixed things up. At minimum, I should have walked the museum in reverse. Even better, I should plopped myself down in one spot and done some sketching or writing. The exhibits are quite immersive and this would have been a chance to do some battlefield sketching without getting shot at.

As with past visits to the museum, I picked up a number of fresh insights and learned about a number of new personalities. One of which was Kerr Eby who's credited with the following drawing:

Eby's involvement in WWII was unexpected to say the least:

When the United States declared war in 1941, Eby tried to enlist, but was turned down because of his age. He instead received his opportunity to participate when Abbott Laboratories developed its combat artist program. Between October 1943 and January 1944, he traveled with Marines in the South Pacific and witnessed some of the fiercest fighting of the war, landing with the invasion force at Tarawa and living three weeks in a foxhole on Bougainville.

Wait, Combat Artist Program? Yes, Combat Art was a thing:

In January 1943, George Biddle, a mural artist and the brother of the U.S. Secretary General, was invited by the assistant Secretary of War to form a War Department Art Advisory committee and serve as chair. The army, inspired by the success of a small war artist program in WWI, had been considering sending artists into battle since early 1942. Biddle's committee, which would be responsible for selecting the artists, included the noted artist Henry Varnum Poor, the director of the Metropolitan Museum of Art Francis Henry Taylor, and the writer John Steinbeck. Steinbeck was an active supporter of the war art program, and wrote to Biddle: "It seems to me that a total war would require the use not only of all of the material resources of the nation but also the spiritual and psychological participation of the whole people. And the only psychic communication we have is through the arts."

What's remarkable was the mission given to these artists:

...Any subject is in order, if as artists you feel that it is part of War; battle scenes and the front line battle landscapes; the dying and the dead; prisoners of war; field hospitals and base hospitals; wrecked habitations and bombing scenes; character sketches of our own troops, of prisoners, of the natives of the countries you visit;- never official portraits; the tactical implements of war; embarkation and debarkation scenes; the nobility, courage, cowardice, cruelty, boredom of war; all this should form part of a well-rounded picture. Try to omit nothing; duplicate to your heart's content. Express if you can, realistically or symbolically, the essence and spirit of war. You may be guided by Blake's mysticism, by Goya's cynicism and savagery, by Delacroix's romanticism, by Daumier's humanity and tenderness; or better still follow your own inevitable star. We believe that our Army Command is giving you an opportunity to bring back a record of great value to our country. Our committee wants to assist you to that end.

Here's a gallery of art produced by the Abbott Labs project that Eby was involved in. The army, for their part, is still collecting art from its soldiers.

I love this notion of using art as a tool to capture what photography, film or prose may fail to grasp.

What a fun and thought provoking weekend!

Friday, November 15, 2019

Sun Setting; Moon Rising

I'm loving the new Samsung S9+ Night Mode. The second pic was taken using this mode and almost certainly wouldn't have come out as well using the standard 'Photo' mode.

Wednesday, November 13, 2019

Giving Arlington the Run Around

For some time now I've wondered if I could run the perimeter of Arlington, VA. Looking at the boundaries of the county, however, I didn't see an obvious route:

The mostly straight edges of the North-West and South-West borders slice randomly across streets, both big and small. And the Southern tip, which hugs Quaker Lane also intersects Route 395, which is no-go for pedestrians.

Once I relaxed my goal to a rough approximation of Arlington's boundaries, an obvious route did present itself. Starting at Chain Bridge, I could connect the Potomac Heritage Trail, Mount Vernon Trail, Four Mile Run Trail, the WO&D Trail and finally knock out a few miles on Williamsburg Boulevard and I'd effectively have a run around'ish Arlington.

Yesterday afternoon, around 3pm, I tackled this route:

The only surprise in the run came about 30 seconds in. As planned, I left my car at Chain Bridge and started out on the PHT. I ran under the bridge and where the first ascent began I found a washed out section of trail:

I didn't know quite how to get around this obstacle and wasn't sure if I should hit stop and restart my timer on the other side. Ultimately, I just went for it and found myself climbing hand-over-hand out of the gully.

The rest of the run was uneventful. The water level was low enough on the Potomac that the PHT was easily traversed. By the time I hit the Mount Vernon trail the wind had picked up and even a few snow flurries made an appearance. Though, if anything, this kept others off the trail and gave me the path to myself. The full moon and mostly clear sky made gorgeous night running.

In one of the Northern sections of the WO&D I encountered a big 'ol Trail Closed sign, though I followed the detour signs and was able to stay more or less on track.

I had originally planned to run the route in reverse, but given that I'd be finishing in the dark, I decided to tackle the technical trail first. This was a smart move, though it did mean that the second half of the run was all uphill:

Fortunately, the entire route gains only 1,200 feet. After 20 miles of running though, the 'hills' of North Arlington certainly felt substantial.

Overall, I can't recommend this route highly enough.

I was disciplined and snacked every 30 minutes, which for the most part kept my energy level up. While I could have no doubt consumed more calories at these points, I was thankful that my stomach cooperated the entire run. On past long runs I've given in to the urge to snarf down a bunch of food all at once and I was immediately rewarded with a stomach ache. Not last night. More details on the food and gear I used on the run are coming soon.

Here's before and after photos from my parking spot and a few pics along the way.

Wednesday, November 06, 2019

Phillip Phillips and The Myth Making It

I know little about the artist Phillip Phillips. I will forever associate his music with the 2012 US Olympics Gymnastics coverage, as one of his songs was featured heavily there. I also know that a couple of his songs on in solid rotation on the radio.

One evening, I made my way over to his Playlists on YouTube and listened to his most recent album, Collateral. It was good stuff!

What caught my eye, however, were the stats on a number of the songs. Consider My Name:

Personally, I'd be blown away if I produced content that racked up 8,500 views. With that said, I'm astounded at how few views the songs on Collateral have accumulated. Here's a guy with a video that has logged nearly 80 *million* views, and has more than half a million subscribers. And yet he can put out an an album over a year ago, and comparatively nobody has listened to it.

I can't help but see this through the lens of building a business and other creative endeavors in my life. One wants there to be a rule: I'll bust my butt to 'make it' and then I should be able to coast from there. As Phillip Phillip's music shows, this rule doesn't exist. Here's a guy who by all measures has 'made it.' And yet, he has to hustle like any other artist or entrepreneur to keep making it.

I find this both comforting and alarming. Alarming not because of the effort that's involved, but because if you're doing this right, it means that failure is always an option. And comforting, because this is a great equalizer.

In short: past performance is not an indicator of future outcomes. Even if you're a fancy music star.

Tuesday, November 05, 2019

Review: The Incomplete Book of Running

I found Peter Sagal's Incomplete Book of Running to be a delightful 'listen.' It's part how-to, part philosophical treatise on running and mostly entertaining memoir. Sagal is a host on NPR, so I suppose it's not surprising he'd put together a very entertaining audio book.

The how-to aspect of Sagal's book is useful; I could see gifting the book to someone who wants to be a runner but doesn't know where to start. And the witty writing left me smiling, if not outright laughing through a number of his personal stories. Another factor that makes the book work is how he shares his daemons and missteps in such a way that they are fuel for something greater. His battles with weight, depression and relationships are something he may want to forget, but we benefit greatly by hearing his complete story.

After coming off series of dense and epic reads, the Incomplete Runner was just what I needed to lighten things up, while still listening to something thought provoking. Regardless of your relationship with running, you'll be glad you gave the book a chance.

Monday, November 04, 2019

Why Yes, That is a Load Bearing Cookie

We had a fun weekend playing with J & A. Highlights included playing Tangrams and 'building' a Trader Joe's Haunted Cookie House. The house was fun to assemble, but as was our experience with similar kits, it wasn't especially tasty. What it lacked in freshness it more than made up for in entertainment value.

The Tangrams were perfect for both J and A. J tackled some of the puzzles without hints; something I don't typically attempt. And A was thrilled when the shape finally came together. See her moment of joy in the gif below. Too precious!

Friday, November 01, 2019

DC's Latest Memorial Treat

Whenever I think I've found the last unexpected, novel and interesting monument in DC, I find another.

I give you the National Fire Dog Memorial, located at F St NW and 5th St NW:

The monument was inspired by Colorado’s first arson dog – Erin. Her handler, Agent Jerry Means with the Colorado Bureau of Investigation created the monument when Erin passed away May 2010 from cancer. Agent Means wanted to recognize the tireless contributions arson dogs make in arson investigations. The monument design is a standing fire fighter looking down on his canine partner, who is looking back up at his handler ready to work. The monument is titled “From Ashes to Answers”.

It's about a half mile detour from the National Gallery of Art and there isn't much more to see than the pictures below. Still, it's worth taking the time to check it out in person. I'm not a dog person, but even I was moved by my visit.

OK DC, what quirky memorial is going to surprise me next?

LinkWithin

Related Posts with Thumbnails