Skip to content

In Celebration of B-Sides

Dear Reader,

One of the most beautiful rock songs of my lifetime, “Beth” by Kiss, was originally released as the “B-Side” to “Detroit, Rick City”.

I know I’m in the minority here but I will go to my grave believing that with “Beth”, Kiss hit it’s pinnacle. Yet, the relegated it to a B-side.

The band, and their producers couldn’t see the beauty they had until much later when fans started clamoring for it to be played on the radio. It was the band’s highest charting single…ever.  (It hit #7 on Billboards Hot 100 chart.)

Tech Conference B-Side Talks

Tech conferences are sometimes like that. Some CFP programs actually ask speakers “Is this your best talk?”. They are looking for the A-Sides.

Honestly, I have no idea what my “best talk” is. I know the ones that I get a lot of comments about, but I can’t say that those are my best.

I can tell you my favorite talks. My favorite talks are not my keynote talks, my favorite talks are the ones where someone comes up afterwards and tells me that they picked up something that they can use in a project they are working on. They are my favorite talks because they actually helped someone.

I recently tweeted out a piece of speaker advice.

Speaker Pro Tip: Write a second talk. Call it your “B-Side” talk. (Kids, ask your parents what that means) Have the slides with you at any Conf or Camp you attend. So far in the past 3 months I’ve scored 2 extra speaking slots because I was prepared.

I didn’t mean to classify the talks by importance, more by “acceptability”.  There are some talks that it’s easy to get accepted at a conference because they push a hot button or they are about the “shiny”.

“B-Side” talks are talks that are important but that conference organizers don’t feel they can take a chance on.

The next time you attend a conference, look for talks that are off the beaten path. Look for those B-side talks.

Hidden in among all those great sessions is the next “ZOMG DID YOU SEE…” and you will be able to say “Yeah. I saw that one last year and it was great.” :)

Until next time,
I <3 |<
=C=

p.s. There’s nothing wrong with “Detroit Rock City” but it’s an obvious attempt to write a rock anthem. “Beth” was art for the sake of art. Thank you Peter Chriss.

WordPress, REST, and RegEx

Dear Reader,

I’m going to add this to “Using the WordPress REST API“, but I thought I would blog it here as well.

I have a tendency to over think things.

Today, I was working on a REST API endpoint for a client and it needed to have RegEx in it. I hate RegEx with a passion usually reserved for XML, but unlike XML, it’s a necessary evil, so I dove into it.

1
/item/(?P<itemId>\d+)

That’s an example.

For the uninitiated, when you are defining a custom WordPress REST endpoint, one of the things you can do is put in Regex into the route definition and WordPress will use that to pull out content and make it a parameter. The code above defines an endpoint for

https://example.com/wp-json/my-namespace/v1/item/4

When run, it will make a parameter named itemId whose value is the 4 from the URI. It’s incredibly handy. They are very easy to work with, especially if you are using numbers like 4, or even 294875.  Strings…well, strings get tricky.

The above example expect a number (so no alpha, just numeric) and numbers are contiguous.  You don’t have numbers with a space in them. Phrases however, have spaces. And what I needed to pull out was a phrase. So, I did what I always do, I pulled out Regex 101, and started figuring this out. This is where the overthinking part comes in.

I got it working in short order, then I started thinking. “What if…”

  • What if There’s a query string at the end
  • What if there’s more to the URI
  • What if there’s a slash at the end
  • …what if

This is where I got into trouble. I lost a good 2-3 hours designing a beautiful piece of RegEx that handled every situation I could think of. It was art, if I do say so myself. The only problem was that once I pasted it into my WordPress REST Controller, it did not work.

So I did what every developer does, I assumed the problem had to be in WordPress. I rolled up my sleeves and found out how WordPress matches routes.

What WordPress does

WordPress matches REST routes in WP_REST_Server::dispatch() (wp-includes/rest-api/class-wp-rest-server.php)

1
$match = preg_match( '@^' . $route . '$@i', $path, $matches );
$path is the URI. IN my case
https://example.com/wp-json/my-namespace/v1/item/this%20item%20name
$route was the route I defined in regex.
1
item/(?P<itemName>[w+].*)[?|/|\$]
(I’m working from memory but I think that was it.)
If – and only if – I could set some pattern modifiers I could make it work…but I couldn’t.
Then I began doing the other thing that PHP developers do a lot, I began throwing var_dump();die(); into WP_REST_Server. I thought I needed to see what was going on. Turns out, the answer was there in front of me all the time.
I was assuming that WordPress was applying my RegEx standalone from everything else. If you look at the line above though, you can see that is uses the route that I define in it’s entirety.
  • It puts a ‘@’ at the beginning of it. This tells PHP that ‘@’ is the regex delimiter, not ‘/’ like usual
  • It adds the caret ‘^’ to match the beginning of the line
  • It concatenates the route I defined
  • It adds the $ to match the end of the line
  • It puts the ‘@’ to signify that this is the end of the RegEx
  • It adds the ‘i’ pattern modifier (the things I needed to tinker with) to indicate that all matches should be case insensitive
WordPress doesn’t worry about the query string, or anything after that because it’s already stripped it off. I don’t have to overthink this thing with subgroups and special characters, WordPress has got my back.
My finished product ended up looking like this:
1
item/(?P<itemName>w+.*)
This gives me a parameter named itemNamethat includes everything past item/ to the end of the line.

Conclusion

Stop over-thinking things. Sometimes just let the framework do it’s job. :)

Did I meantion I hate Regex? :)

Until next time,
I <3 |<
=C=

p.s. the section in the book will be more coherant. I’ve spent the day with RegEx so I’m a bit scatterbrained now. :)

Great writers read…a lot

Dear Reader,

Have you ever watched one of those movies where  a software developer (usually called a hacker) is sitting in front of 2 screens and on both of them code is scrolling by at a fast pace while the hacker nods knowingly like they are reading and understanding what they are seeing?

Yeah, that doesn’t happen.

A more common scenario is that a software developer will fork a repo, clone it locally, open their editor of choice and start reading through the code. Scrolling through it slowly. opening another edito for the same code and scrolling back up to a previous section and comparing the two. This goes on for a long time.

Reading other people’s code is probably the best way to learn how to program. If you know what the code does then reading the code shows you how someone else solved the problem.

Just like a great writer reads more than they write, a great software developer will read code, theirs and other peoples, more than they will write code. As a junior developer this goes double for you. Since you do not have a body of work to copy and paste from, you need to see how other people solved common problems so you can understand how to solve them yourself.

Until next time,
I <3 |<

Conferences are for making new friends

Dear Reader,

I met my three best friends, Paul, Keith, and Adam, at PHP conferences.

Meeting people and making new friends is one of the major benefits of participating in a conference. I would not say that ‘the hallway track’ is the reason to attend a conference, but it is in the top 3.

The friends you make at a conference can:

  • Help you find an answer to a problem you are facing
  • Help you locate someone you need to talk to
  • Be your rubber duck for a problem you are having
  • Help you find your next job

Before you travel across the street, or around the world to participate in a conference, sit down, make a plan. Look at the speakers who will be there, and follow the conference hashtag on social media to see who has announced they are participating. Make a list of the people that you want to meet.

As you participate in the conference, look for those people. Seek them out, and make new friends.

The friends you make at a conference will last a lot longer than any knowledge you may pick up in a session.

Until next time,
I <3 |<
=C=

Here’s a video where I give a little on the HOW.

You are not a conference attendee, you are a conference PARTICIPANT

Dear Reader,

For those of you lucky enough to attend a technical conference, you need to change your mindset.

You need to do away with the word ATTENDEE.

Attendees are passive. They show up, that is all that is expected of them.

If you want to get the most out of the conference then scratch through that word on your badge and write PARTICIPANT.

Participants are part of the conference. If all they do is show up, they have fail.

Participants get involved.

  • They ask questions during Q&A
  • They engage with the other participants at the social times
  • They participate in the socials and engage with other participants

They do all of this even though they are shy, or introverted, or whatever their reason is for not normally being so outgoing. Participants understand that for the conference to be good for everyone, they have to do their part.

Make the most of your next conference by seeing yourself as an integral part of the conference, a participant, not a bystander attendee.

Until next time,
I <3 |<
=C=