Archive for November, 2007

Mile Marker Sixty-Eight

Thursday, November 29th, 2007

Mile Marker Sixty-Eight

Just one mile again today.  But fast this time.  I read some sort of weight-loss thing online that said that 3.5 mph was the speed you wanted to be at for “brisk” walking, so I put the hammer down, got it up to 3 mph just to start off with.  Big mistake.  I could keep up the pace for awhile – maybe I walked a quarter mile that fast — but not only could I not keep it up for long, I ended up having the soles of my Nike Shox skid uncomfortably (not to say dangerously) on the treadmill.  Not good.  So I slowed it down, finished my mile, and decamped to the local sports bar to watch Cowboys-Packers (a triumph for the good guys).

Sixty-eight miles down, thirty-two miles to go.

Entering WordPress Variables Into An XPath Statement Using PHP (No, Seriously)

Thursday, November 29th, 2007

You won’t mind a little coding, will you?  Just a little?  Good.

Here’s the thing.  Let’s suppose you have an XML feed, and you want a very specific item out of that XML feed to display on your WordPress blog.

(Everyone who doesn’t know what XML is can stop reading now.)

Let’s say that you’re working out of a large XML file.  I’m going to use one of the XML files out of the Hollywood Stock Exchange; this one lists all the stock information for different upcoming movies.  (Know before you click that it’s a very large file.)  Let’s suppose I want to pull out the release date for the next Indiana Jones movie (which has the stock symbol in HSX of INDI4).  In fact, I’ll go ahead and copy out the relevant clip of XML from the file, so you can see it (although I won’t go to the trouble of explaining what all the codes mean):

<sec tkr=”INDI4″>
<name>Indiana Jones and the Kingdom of the Crystal Skull</name>
<sts>ACT</sts>
<yc>256.32</yc>
<ipo>18.25</ipo>
<rls>22-MAY-2008</rls>
<phase>W</phase>
<genre>Adventure</genre>
<gross>0</gross>
<wh>256.95</wh>
<wl>255.69</wl>
<mh>256.95</mh>
<ml>247.5</ml>
<sh>256.95</sh>
<sl>219.78</sl>
<yh>256.95</yh>
<yl>132.21</yl>
</sec>

It’s very easy to pull out one specific bit of text from the XML within WordPress.  Within a PHP statement, you type the following:

$mst = simplexml_load_file(‘all_hsx_mst.xml’);
$releasedatearray = $mst->xpath(//sec[@tkr="INDI4"]/rls);
$releasedate = $releasedatearray["0"];
echo $releasedate;

Cool, huh?  Let’s explain that in English.

$mst = simplexml_load_file(‘all_hsx_mst.xml’);

This line just sets a PHP string called “$mst”.  (It could have been called anything, but it has to start with a dollar sign.)  It assigns that string to a PHP 5 command called Simple XML, which loads the URL of the XML file we want to start off with.  (I have actually omitted most of the real URL for the real file here a little so as not to screw up the formatting of the blog.)  (It matters muchly that we’re using PHP 5 — check with your hosting service — because if you’re not, you can’t use Simple XML, you have to do something incredibly cumbersome called a DOM statement.)  Okay?  Second line:

$releasedatearray = $mst->xpath(//sec[@tkr="INDI4"]/rls);

This is our XPath line.  It sets up a string called “$releasedatearray” — and again, that’s just what I call it, you can call it $snookums if you can remember it better that way.  The XPath line first accesses the XML file (through the $mst string we did in the first line) and then does an XPath search for the information we want — in this case, the ticker symbol (“INDI4″, which is an attribute of the “sec” value of the XML quoted above), and the release date that’s associated with that symbol (rls).  (If you want to know more about XPath, this is a good tutorial, and this testbed site will help you practice forming XPath searches.)

Third line:

$releasedate = $releasedatearray["0"];

What you get back when you do an XPath search is an array — even though in this case, the array is really just one item.  You don’t want to show the array, just the one item, so you set a string (arbitrary again) “$releasedate” to equal the first cell in the array (which is zero, don’t ask me why).  Then your fourth line just prints out the “$releasedate” string (22-MAY-2008), and you’re done.

Okay, but what happens when you don’t want just the INDI4 release date, but release dates for whatever symbol you want?  What happens when you want there to be a variable there instead of INDI4?

Well, the way I would have thought that you do it is how you do things in WordPress generally.  Let’s say the title of your given post was INDI4, and you wanted the title of your post to appear within the XPath.  (It doesn’t have to be the title — in WordPress lingo, the_title — but let’s say.)  What if you tried this as your second line:

$releasedatearray = $mst->xpath(//sec[@tkr="<?php the_title(); ?>"]/rls); 

Looks sensible, right?  You’re putting in the PHP expression that returns your title in the XPath; it ought to turn up that variable in every XPath search on every post.  Right?  Wrong.  This doesn’t work.  You can’t bring up a PHP command inside an XPath search expression.

So here’s what you do.

$ticker = get_the_title($post->post_parent);
$first = “(//sec[@tkr='";
$last = "']/rls)”;
$path = $first.$ticker.$last;
$mst = simplexml_load_file(‘all_hsx_mst.xml’);
$releasedatearray = $mst->xpath($path);
$releasedate = $releasedatearray["0"];
echo $releasedate;

Again, line-by-line analysis.  First line:

$ticker = get_the_title($post->post_parent);

This sets the WordPress “the_title” variable to a text string called “$ticker”.

$first = “(//sec[@tkr='";
$last = "']/rls)”;

These lines set up text strings that correspond to eveything that goes in front of the ticker (“$first”) and behind the ticker (“$last”) in our XPath command.  Then you concatenate the three strings into another string, as follows:

$path = $first.$ticker.$last;

This creates a text string called “$path” that creates your XPath expression, with the “$ticker” symbol (the variable, that we got from the_title) in the middle.  Then, in our XPath line:

$releasedatearray = $mst->xpath($path);

And that works.  You just plug your text string in your XPath command, and you can plug whatever variable you want.

Thank you if you read this far.  I truly hope this was helpful for someone, because I was absolutely pulling my hair out trying to get this to work last week, and the answer for the question wasn’t anywhere on line that I could find easily, at least not within the WordPress context.

Mile Marker Sixty-Seven

Wednesday, November 28th, 2007

Mile Marker Sixty-Seven

Apparently, this is a mile marker on the old Mason-Dixon line, from back in 1766, and it’s a mile marker 67, even though it doesn’t look it.  You should look so good when you’re 343 years old.  (Actually, it’s not the famous Mason and Dixon line — the one between Pennsylvania and Maryland — but a different line, between Pennsylvania and Delaware.)

Just did one mile today – I was tired, cranky, and basically non-compliant with pretty much everything.  (How is this different than any other day, you ask?  Hmph.)  The only thing that was motivating me was walking the .667 miles I needed to be officially two-thirds done with this nightmare.

Sixty-seven miles down, thirty-three miles to go.

Mile Marker Sixty-Six

Wednesday, November 28th, 2007

Mile Marker Sixty-Six

Jumping from sixty-two to sixty-six because I didn’t have computer access for the last 48 hours, for any number of good reasons, which I won’t go into here — and when you don’t have computer access, it’s easy to say, well, hell with it, I’ll just go walk.  Two miles on Monday, two miles on Tuesday, and even with just thirty days in November, I ought to be able to make 70 miles by December 1, when the real fun begins.

Unfortunately — well, fortunately for you, the Northbound reader — this is getting incredibly boring to write about.  There’s really nothing more I can say after I’ve said “I hate walking on the treadmill” fifty different times.  I hate it.  You get it, I get it. 

I suppose I could start saying “I hate Google Spreadsheets” — and I do, oh, how I hate Google Spreadsheets — and it would sound the same.  The content would be different, but it would be the same, just nonstop whinging and moaning, and I think we’d all agree that I’m above that.  Most of the time.

I’m going to continue treadmill-blogging until the end of the year, and then it will stop.  Not one more word.  I’m going to keep track of annual mileage in the sidebar, and that’s it.  Maybe big huge milestones, but no more day-to-day drudgery, at least not after December 31.

The plan for next month is two miles a day, five days a week, for three weeks — that’s thirty miles by December 21, which means I don’t need to walk over Christmas vacation.  I am not saying I can do this, because I don’t know that I can for sure, but I’m going to try.  It’s a stouter pace than what I have set for myself so far, but it’s at least theoretically doable, and I don’t think it will actually kill me.  Or I hope not.

Sixty-six miles down, thirty-four miles to go.

Mile Marker Sixty-Two

Wednesday, November 21st, 2007

Mile Marker 62

Why, yes, I would just as soon take the bus.

Sixty-two miles down, thirty-eight miles to go.  Happy Thanksgiving, everyone.

Mile Marker Sixty

Tuesday, November 20th, 2007

mile marker sixty

I hate to use the really obvious roadfan pictures, but sometimes it’s slim pickings.  If you don’t know what a roadfan is… well, maybe you’re better off.  But if you want to know, you could do worse than start on Wikipedia and looking up the Wikipedia site of your favorite interstate highway (oh, yeah, it’s on there) and branching out from there.  If you’re driving down Arizona’s Route 60, and you see a guy hanging out the passenger side window taking pictures of road signs, well, that’s what we’re talking about.

What you will not see (and I pray God you will never see) is anyone taking pictures of fat guys walking on treadmills, because it’s just not what you call photogenic.

Sixty miles down, forty miles to go.

Mile Marker Fifty-Eight

Tuesday, November 20th, 2007

mile marker fifty-eight

Thank goodness for real life, it gets in the way of exercising.  Still, only took off a week (lots of different sorts of responsibilities and errands intruded) and was… well, let’s not say pleased, but surprised to find that I was able to maintain a decent pace (2.6 mph most of the way) and that I was able to finish my two miles yesterday evening with relative ease.  I’m a little bit behind my pace as of today, but I ought to be able to catch up at least a little bit this week, and really pound out the miles next week to get to 70 miles by December 1, which is where the real challenge begins – thirty miles in twenty days.  (That’s so I don’t have to log any treadmill hours over Christmas vacation in Texas.)

Fifty eight miles down, forty-two miles to go.

Booth Review

Friday, November 16th, 2007

In my last job, I spent a lot of time working the booth at various exhibit halls at various conferences all over the country.  I still do it occasionally in my current job.  And if you do anything long enough, you start to notice things, like how people act when they walk into exhibit halls.  Generally speaking — and I mean this very generally, not commenting on the actions of any particular individual at any particular conference I may have ever gone to or will ever go to — you can break down the way people act in (I think) three separate ways, as follows.

(Let me stress again that I am not making fun of anyone in particular; if you find that one of these behaviors describes what you do, it’s probably just a coincidence.)

PEOPLE WHO WANT NOTHING TO DO WITH YOU

  • Pilots:  Pilots are the people who walk past your booth with their heads looking at the ceiling, trying desperately not to look at you or your booth or your brochures or, well, anything but maybe the exit sign.  From the other side of the booth, it’s like they’re cruising along at twenty thousand feet above the exhibit hall, ignoring the world below. 
  • Rubberneckers:  Rubberneckers are just like pilots except they have their eyes at ground level.  Or you’d think so, if you could just see their eyes.  You never see anything but the backs of their heads.  Rubberneckers look determinedly away from your booth, just as though your brochures were bright lime green with purple polka dots.
  • Boulevardiers:  The Boulevardier strolls by your booth, oh, ten or fifteen times.  He’s not ever going to stop at your booth; he’s just walking around, taking in the sights, like the convention center is Paris in the springtime.  There’s usually one or two at every conference.  No one knows why Boulevardiers go to conferences or what they get out of them other than exercise.
  • Chatters:  Chatters are people who camp out in front of your booth and chat — either with other attendees or on their cell phones, cheerfully oblivious that they are blocking your booth and boring you to tears.
  • Sidecars:  People whose spouses or signficant others have dragged them to the exhibit hall.  Sidecars could care less about anything or anyone.  They just want to die, or failing that, to go back to the hotel room and watch SportsCenter.

PEOPLE WHO WANT NOTHING TO DO WITH YOU BUT ARE WILLING TO AT LEAST LOOK AT YOUR STUFF

  • Scanners:  This really isn’t a good name for them, mostly because there’s a lot of variation in their approach.  Basically, what these people will do is a) come up to your booth b) grunt at you when you say hello c) look over your brochures and d) walk away without ever once making eye contact.  This is probably the most common conference behavior. 
  • Bumpers:  Bumpers are Scanners with short cycles — it takes them all of five seconds to look your materials over and then book out of there. 
  • Readers:  Readers are the oppposite of Bumpers; they’ll hang around your booth for five or ten minutes, looking carefully over each brochure, and maybe even deigning to take one.  On rare occasions, Readers will read over each of your brochures, look up, see that you’re there, and ask, “What do you people do, anyway?”
  • Loiterers:  Loiterers are Readers who are there longer than ten minutes.  Shoo!  Move along!
  • Mother-May-I’s:  Readers who ask if they can take your brochures.  This may be my personal pet peeve, but these may be the worst of the lot.  Of course you can take one of the brochures, that’s what they’re there for.  The pens?  What do you think, we have a big bowl of pens out for decoration?  Take, take.

PEOPLE WHO WANT NOTHING TO DO WITH YOU BUT WANT TO HAVE A CLOSE PERSONAL RELATIONSHIP WITH YOUR STUFF

  • Hoarders:  People whose goal in life is to collect at least one copy of every publication at every conference they go to.  They are exceptionally easy to spot, because they have a big bag full of other people’s brochures — almost always, a bag they got from some other booth.
  • Grabbers:  Grabbers don’t want brochures, they want your promotional items, and they’re not picky.  Grabbers will take everything you have if you let them.  This is just my personal observation, but K-12 teachers are some of the worst Grabbers out there — they’re always running out of pens and paper and office supplies (and the funding to buy them with) and will glom on to anything you have.
  • Trick-or-Treaters:  Just give them the candy and nobody gets hurt.

PEOPLE WHO YOU WANT NOTHING TO DO WITH

  • Finally, Someone With Nothing Better To Do Than Listen To Me Go On About My Problems For A Half-Hour:  Self-explanatory.
  • Networkers:  “Hi, I’m selling widgets at Booth 313, you should stop by, we’re having a demonstration at 3:15, see you there!  Here’s my card.  Take two.”
  • The Creepy Guy In The Booth Right Across From You:  Just trust me.

Thank you, and enjoy the rest of your conference.

Mile Marker Fifty-Six

Thursday, November 8th, 2007

Washington Monument

Walked six miles today in our nation’s capital, going from the Gallery Place metro station south to the Mall, and then over to the Lincoln Memorial, and then all the way down the Mall (with detours by the Vietnam, Korean, and WWI monuments) to the Capitol reflecting pool, and then up to Union Station, where I took the train home.  A little more on this later, perhaps, if I feel up to writing.

Fifty-six miles down, forty-four miles to go.

Mile Marker Fifty

Thursday, November 8th, 2007

Crystal Gateway Marriott

This picture is of the Crystal Gateway Marriott in Crystal City, Virginia.

Crystal City Marriott

This picture is of the other Marriott in Crystal City.  I walked to the wrong one when I arrived there Tuesday night, and ended up (according to Google Maps) walking a little over a mile going from the Metro station all the way around part of the Crystal City mall across the highway to the wrong Marriott and back across the skybridge to the right one.  I don’t want to talk about it other than that.

Fifty miles down, fifty miles to go.