A Brief Encounter with the Underground Economy

Where to start, where to start. My longest ride ever? The things I saw? The nearly-endless interval sitting on the concrete, my legs stretching out into the sun, in emotional and medical shock, staring at my water bottle lying in the middle of the sidewalk as I reconciled myself with never seeing my bike again? The stunned disbelief as two strangers brought my bike back to me?

I’ll start with water. I drink a lot of water, even when siting in an air-conditioned office. I have convinced myself that my second-biggest obstacle to climbing my mountain (It’s not “Mt. Hamilton” anymore, it’s My Mountain) is water. Unless I pull a trailer with one of those big ol’ coolers behind me, I’m going to have to find ways to replenish on the climb.

So, I’ve started to be more conscious of the places water is available, even on my more modest routes. Trying to get it into my rather thick skull that’s it’s ok to load up at any opportunity. (I do not know if there will be opportunities on my mountain.)

Eight days ago I set out on a ride, not sure exactly where I would go, but confident there would be a lot of miles. I knew when I was done that Strava would congratulate me on my longest ride ever, and I was looking forward to that pat on the back. Machines are notoriously free with their validation, but some machines are more worth impressing than others.

So a long ride north exploring what is intended to be a bicycle artery, which is really well done except for two stretches that are terrible. I was on roads I didn’t know, and the sun was straight overhead, but I knew I was going the right direction by the headwind. If you’re riding into the teeth of the wind, you’re traveling roughly parallel to the runway at SJC. I hate headwinds, but this one at least I know will pay me back when I was heading home on weary legs.

But… all this riding around isn’t what I teased above. I was a good ride. I found some cool things I will have to explore again. I made my way over to Alviso and began my tailwind ride home south on Guadalupe River Trail.

The trail includes a stretch of roughly ten miles with no interruptions — no traffic signals, no cross streets — that you just cruise and enjoy. But when I got to the south end of that, thirty miles into my ride, I had consumed all the water in my big bottle and the Gatorade I put in the second holder as well.

By now, I was not far from home. I could have made it without too much discomfort. But I told myself that I needed to start to get used to finding water on the trail if I planned to do longer rides. So, just for practice, I stopped at a little park to fill up my water bottle. This may seem like a strange thing to practice, but for me “stop pedaling for two minutes so you don’t die later” is not as simple as all that.

So I stopped for water. It was at a little park with public restroom made out of the same brown faux-stone that all public restrooms are made of in all city parks west of the Mississippi. There were people outside as I rode past, so I guessed that the covid water shutdowns had been canceled. I would fill my bottle. I doubled back.

The park is separated from the street and the sidewalk by a low metal fence – not a barrier In any real sense, but a symbolic demarcation. As I rolled through the gate into the park and turned back toward the water, I decided I didn’t trust the people hanging out there so much, so rather than leave my bike near them, I leaned it against the fence, a few feet away.

That was a very bad decision.

I said hello to the couple standing in the shade of the restroom blok. He was, let there be no doubt, a fan of the Oakland A’s; he was garbed in yellow and green from neck to toe, with plenty of logos. She was dressed for the summer heat, a light top but still blue jeans.

This next bit is hard to tell, because of how stupid I was. The drinking fountains on the outside of the building didn’t work. “The taps work inside,” the A’s fan said.

It would only take a moment. Pop in, fill the bottle, back out. Just a few seconds. I went in, and for five seconds of increasing anxiety I tried to make water come from the spigot, alll the while thinking “my bike is out there” and finally dashing back out, in time to see a stranger reach over and hoist my bike over the fence.

“NO!” I shouted. “No! No! No!” And I started to run after him.

An aside here, and an important one. Many times I have told myself that in a situation like this, I would do my best to be a witness, not a hero. Be smart. Really look at the person, so that in court I can be confident. Get the details. Consolidate them before lawyer questions can shake them. I failed at this. Absolutely flunked the course. I chased, vaulting the little fence and still shouting. Maybe a shitty mustache? When talking to the police I was also able to offer that he was wearing long pants, which seriously narrows the suspect list.

Instead I was a hero. I chased the guy, vaulting the fence in what might have ben an impressive maneuver. But I was in bike shoes (SPD so better for sprinting after bike thieves than others) and after about five strides past the vault I knew my left leg was blown. Still I was not being a good witness. My eyes were on my bike, the rear safety light still blinking. A folding knife dropped out of the thief’s pocket as he rode away. He headed South and took the first turn to the east and he was gone.

I staggered forward far enough to collect the knife (carefully – fingerprints, after all) then limped back to where my witnesses were standing. They asked If I was OK, and told them that actually I was not. “Do you know that guy? I asked.

“I know him, but I haven’t seen him around for a while,” the guy answered.

I will not reproduce the entire conversation, but as they assessed the damage I had taken, and my long white beard, the woman said, “do you want us to go after him?”

I heard that as “can we sound helpful and leave?” but I answered “If you really think you can find him, then yeah, sure.” And they left.

I’ll fast-wind ahead through remembering my watch is also a phone and calling The Official Sweetie of Muddled Ramblings and Half-Baked Ideas and calling the police and sitting, staring at my water bottle which I had carried at least long enough that it was on the street side of the fence, the lid a few feet farther along, in the shade of a tree that was small enough to only be a promise of a future idyllic neighborhood. My head started to spin, and I laboriously stood only to cling to the damn brown brick so I wouldn’t fall over again. I was not in a good way.

And then there they were. With my bike. With my fucking bike.

“I’m so glad you’re still here!” she said, huffing and flushed with the effort of a quick ride. “I was worried if you were gone we’d never find you.”

There were some moments of joy and simple gratitude that followed, snd she (and he, to a lesser extent) seemed of a mind to chat. “He was heading for the labyrinth,” she said. “It’s a place they sell stolen bikes. But he took a wrong turn.” The labyrinth is well-named. “When we found him, he was looking at the back gears and having a hard time.”

“This bike shifts differently,” I said, and she laughed. We talked about the bike for a bit, about how this outfit in Utah was making great bikes. I opened the pouch on my bike that also held my wallet, and was happy to find some cash inside, that I keep in reserve for waitstaff. I offered it to her.

“You don’t have to,” she said. Twice, before taking the money. It was fifty dollars. In this city, that’s not much.

In our conversation, she proudly proclaimed that they had paid for their bicycles. But I haven’t mentioned that the two of them had three bikes, and both were skilled at “ghost riding”: pedaling one bike while pulling along another. It’s an important skill for bike thieves. She also said “I offered him this bike in exchange, but he just gave me yours back.” For her, bicycles are generally fungible. My bike was unique, which made it more dangerous, but also I was a graybeard with a blown leg who clearly didn’t know how to deal, and I think it was that more than anything else that led to my happy reunion.

I mentioned to them that I had managed to call the police, and he said with a laugh. “I’m no interested in talking to them.” and she laughed too and they rode away with their three bicycles.

I am not angry, not even at the asshole who snatched my bike and rode away. There is a world of necessity that festers in our cities, a world invisible to the Uber class. On my favorite ride I pass a camp filled with chickens and stolen bicycles. This is not big-time organized crime, it’s people struggling to survive. They’re living in tents for crying out loud. The underground economy of stolen bicycles is not the disease, it is a symptom of a deeper ill.

So, I lied, actually. I am angry. I am angry at a nation where people eating too much is a major health crisis while we also have kids gong hungry. I am angry at a nation where the homeless problem is solved by making them go somewhere else. We have enough. We have enough to put a roof over every head. We have enough to put food in every belly. But we don’t. Honestly, we don’t even try.

I rode home, slowly, on my own bike, pedaling with a very unhappy leg — a person of privilege who had somehow found sympathy from people who have far less than I do. I will pay that back.

8

Bicycling’s Ultimate Wingman

It was a hell of a day on the bike today, but I’m not ready yet to tell that story. So let’s talk about the Tour de France instead.

Today, a rider named Mark Cavendish tied the record for most stages ever won in the Tour. The Manx Missile once seemed to be on track to shatter the old record, then injury and misfortune almost ended his career. After a brutal few years, he got his last chance on a major team, and likely because of internal politics he was selected to ride for that team in the Tour.

There are a lot of different ways to win at a stage race like the Tour de France. The most-remembered winner is the rider who completes all the stages in the smallest aggregate time. But there are also awards for the best in the mountains, and the fastest in the sprints, and each day is a mini-race; winning a stage is a great accomplishment. winning lots of stages, over many years, makes you a legend.

Cavendish, with his come-back story, adds an element to this year’s Tour that would not be there otherwise. He is crafty, knows just what he can do, and especially knows how to work with his teammates.

One of those teammates is Michael Mørkøv, my new favorite rider. Yesterday he did such a good job pulling Cav through a confused and chaotic 100 meters to the end line that he nearly won the stage himself. But his job is to get the main guy to the line, and he does it well. I looked today and in his long career he has won exactly one stage in a major race. But his teammates have won many.

If you watch a stage race that ends with a sprint, you will see the star of the show about four wheels back, behind teammates who are creating a draft the star can ride it, saving energy. In the last few hundred meters those teammates will peel off, and other teams will make their moves, driving their own trains toward the line.

If you’re that sprinter, having ridden 100 miles already that day just to get to this moment, as your crew peels off one by one and the pace of the final dash to the line builds, there is no one you want in front of you more than Mørkøv for those last few meters.

I have oversimplified the role of the leadout rider; there is a lot of strategy involved to set up your teammate for the last dash. Wind, the tactics of the other teams, the strength of the rider you are pulling, of course the terrain — all of that matters.

Cavendish has a burst that no one else on the tour can match. Those same twitch muscles that put him across the line first in the sprints are actually a liability through the mountains. So let’s not forget the rest of the team that kept Mark Cavendish in the race (those too far behind the lead are mercifully eliminated). It was the effort of many that even put Mark on the road today.

It has been the effort of Michal Mørkøv that allowed him to make history. Let us not forget that.

Blogging for Dollars

I was reading an article the other day about Facebook’s brazen attempt to spend another competitor into the grave. In this case the competitor is Substack.com, which is a platform that allows writers to create “newsletters” and have their fans subscribe for actual dollars. Substack, of course, takes a slice of those dollars for themselves.

But Facebook thought that was a pretty cool idea, and decided to launch their own clone of the service, but (at first) they will not take a cut of the writers’ subscription fees. So, they’re dong it for free, but the writers creating these “newsletters” don’t have to give up a slice of their pie.

From The Washington Post article:

Asked for comment on Facebook Bulletin, Substack spokeswoman Lulu Cheng Meservey said, “The nice shiny rings from Sauron were also ‘free.’ ”

I put “newsletter” in quotes because these are blogs. Bloggedy blog blogs. These are platforms to allow bloggers to make money.

And… hang on a second… I’m a blogger!

So after reading this, and deciding instantly that I would not be participating in the Facebook thing, I was still left with the thought… maybe I could make money by blogging.

Fear not, good reader(s), Muddled Ramblings and Half-Baked Ideas will not be disappearing behind a paywall. Be assured that this is not out of any altruistic impulse, but is rooted in the calm belief that MR&HBI is fundamentally unmarketable. If you don’t believe that now, just wait for the next episode.

To be one of those blogs that people read, there must be a theme. I can’t just spew whatever nonsense crosses my mind and expect people to pay for it; I have to wrap that nonsense in a central theme, and have that nonsense resonate with people who have never actually met me. There has to be a connecting point.

Like maybe an overweight greybeard trying to climb a mountain on a bicycle. That might sell, if the “newsletter” built a larger story about goals and effort and self-loathing and it was written well enough that people who read one installment would look forward to the next. There might be a formula for the episodes — some logistics, some details of ride to the base of the mountain, then getting to the grind of the climb with a juicy piece of crazy thought that went through oxygen-starved brain, then the discomfort and pathetic fear of a timid descent. Some background, here and there, about the world, about life, about whether pursuing happiness is an oxymoron.

I think I could do that.

I also think that because I am completely hopeless at marketing, that the “newsletters” will die in obscurity. But is that any reason not to do it? It’s an autobiography, and Lord knows I do like talking about me. It’s a story, but unlike serial fiction each episode is built on my latest run at the mountain. “I got this” one week turns into “I don’t got this” the next. There might be discussion of bicycle infrastructure. Or blimps.

But my two subscribers will be pushing me forward, lifting me, and when I get to the top of that damn mountain, our roar will be heard all the way to next door.

2

They are Not Like Us

Clearing out the email today and found one from Strava, the bicycle-centric performance-tracking app. It turns out that some of the riders on the Tour de France are sharing their rides with the rest of us.

Poking around today, I got the data for Ben O’Connor, the rider who won Stage 9 today, and I also found the data for a serious contender who today lost concentration for a second and went off the road. The full list is here.

O’Connor doesn’t share his heart rate data, but some of the others do. There was one guy who I can’t remember the name of whose heart rate almost never broke 150. Another guy climbed a near-vertical road for a minute, pushing his heart to a casual 149, before it dropped right back to 108 a minute later, while coasting downhill.

I’m only starting to appreciate the power numbers, as on my rides power output is a very rough estimate based on slope and speed (I could buy toys to give much more precise power readings, but I don’t think I would actually benefit from that information.) Here we see athletes who can sustain more than 400 watts of power for half an hour, and then do it again on the next hill, and then be able to get back on the bike and do it all over again tomorrow. The riders, even the ones with no hope of winning, are capable of producing crazy amounts of power pretty much forever.

But while all that’s impressive to me, it’s all quantifiable. That changes when it’s about going down the mountain. I will tell you right now, despite the hardship, I prefer going up to going down. I was watching a repeat of last year’s Giro a few months back and a Slovenian kid got his first stage win by smashing up the mountains and then barely not crashing on the way down the other sides. There were times my heart went up into my throat as his rear wheel skidded on the winding roads. He is a beast, but a crazy beast at that (I think I was watching Tadej Pogačar introduce himself to the world, and who has in the last three days turned the Tour de France into a race for second place, but there’s another Slovenian kid who is also a monster.)

It should come as no surprise that the riders who qualify for one of the world’s most prestigious athletic endurance events are superhuman. It’s extra-fun for me, though, because when I look at one of those riders, Strava helpfully puts my recent and career stats next to theirs. (But please note that my post-return-from-Prague career miles are roughly twice what is shown there, since I didn’t start using Strava right away. So it’s not really so different, right?)

By the way, here I’m being compared to Ben O’Connor, who won Stage 9 today. I suspect that his longest ride is much more than 160 miles, so maybe only half his work is showing up in Strava as well. Even from what we see here, he’s closing in on one million feet of climbing. If he did that all in one climb, he’d officially be an astronaut and then some, but he wouldn’t quite reach the ISS. It would be a hell of a ride back down.

I couldn’t find any names on Strava that I knew to be sprinters. They are bigger-legged riders who can put on amazing bursts of power (and therefore speed). I’m really curious what their numbers look like in the final meters of a closely-contested sprint. If I find anyone in that category, I’ll let you know.

Meanwhile, I’ll push the pedals, and while I will never produce huge power numbers, I am about 120% of a climber right now — I just need to shed 20% of me to be in good trim for a romp up a mountainside. I’ll leave the descent to someone else.

Punkstalgia

When writing I used to listen to music much of the time, but not so much anymore. But for some reason tonight I was inspired to put the pods in my ears and fire up some Stiff Little Fingers, starting with Suspect Device, one of the best Punk songs ever, then through Alternative Ulster and Can’t Say Crap on the Radio.

For a band with such an incendiary start, they have stayed together for a long time, and they produced memorable music for a couple of decades (it seems they are still making music together, which gladdens my heart). But those earliest, raw anthems that sing about “them” are my favorites. Stiff Little Fingers are punk, but the musicianship is there, always twisting, sometimes surprising, never dull.

Like all true punk bands, they were political. As a band in Belfast during the Time of Troubles, they were playing in a war zone. Those early concerts must have been damn near riots. I wish now I could have been at one, but I probably would have shit myself.

I haven’t got much writing done tonight, but I’m not sorry. It’s been a long time since I performed Suspect Device at Punk Rock karaoke down in San Diego (Yeah, I fronted a band with Greg Hetson (Circle Jerks) and Eric Melvin (NOFX) for one awesome and really loud three minutes. I’d like to believe Jennifer Finch (L7) was there too, but things are fuzzy), and it’s time to get back in touch.

Punk still lives today, but it’s not white guys with guitars who are making punk, it’s hip-hop and the countless variations I am not qualified to enumerate that carry that political torch of protest and disruption. But I like the guitars.

CODA: As I make my way through their catalog, I am reminded what pioneers that band could be on occasion. “This sounds like what <insert band here> did, only… [checks date] before them.”

1

In It to End It — With Your Help

Domestic abuse is a problem as old as humanity, but the last couple of years have been particularly bad for vulnerable people. The first step to recovering from abuse is often, “just get out of there,” and that’s never a simple calculus, but during a pandemic it gets ten times harder.

Several Bay-area organizations have banded together to make things less awful, and now that group is running a fundraiser. It’s a fitness-based endeavor, where participants set a mileage goal. Bikes are welcome, but it’s calibrated for running, so on a bike I can rack up a significant portion of their overall mileage goal.

And you can participate, too! You have two options: Sponsor me or put on miles yourself.

This is a local charity, so if you would rather support people closer to where you live, go for it. But please, please, support someone.

Top Golf

One of the awesome people who helped me get my shoulder working again was a friendly guy named Patrick. To succeed at a job like that, it takes more than a bunch of school and an internship and working one’s way up through the ranks. You have to be a people person. While Patrick was working on my soft tissues and testing my progress, there was also conversation. Physical therapy is like getting your hair done in that respect.

So while Patrick was exploring how far he could bend me before I yelped, we were also chatting about this and that. Since my presence there was due to a bicycle crash, naturally riding was part of the discussion. But Patrick also likes to swing a golf club, and eventually he told me about Top Golf.

I must confess I still don’t fully understand what this is, but I have grasped the most important part. Top golf is a place where you and your pals can go and have a beer or three and hit golf balls. But wait! There’s more! it seems that at Top golf there are computers and shit that analyze you shot and based on that you score points or kill monsters or ascend to primary breeder in your troupe. I glazed out at that part.

But the brilliance of all this is that someone asked the question, “What if we took the onerous task of hitting a golf ball, and turned it into a game?” Revolutionary!

Yep, someone has gamified golf. About time, too.

The Right Way to Build a Hotel on the Moon

There are three reasons to visit the moon:

  1. Low-gravity sex
  2. To say you did it
  3. It’s the fucking moon.

I have seen in my day more than one plan for a moon hotel. A few of those plans have some good ideas (really tall towers you can jump down the core of), but none of those designs understand a fundamental truth: Construction matters — every mark the construction crew makes on the landscape will outlive humanity.

On Earth, bulldozers level the property, the hotel goes up, and then the landscapers erase the scars of the machines used to create the hotel. On the moon, that won’t work.

Those footprints will still be there long after humanity is forgotten

When I’m looking out the window of Lunar Hotel 6, I don’t want to see the shattered remains of a landscape that will remember each footprint for tens of thousands of years. I want to see the moon, the way it is now. Every mark made during construction cannot be undone, so construction can make no marks near the hotel.

One of my best stories (note to self: submit story to next market) takes place in a hotel on the moon. Much of the story takes place in a dome that was raised from an underground tunnel and deployed like an umbrella, so that no human disturbance is evident on the other side.

I’ve got nothing against towers, either, but unless you want the tower dwellers to forever look out over wretched destruction, those towers have to be built from the inside. (Flashing to a 3D printer that turns material excavated from the tunnels below into the walls of the tower, lifted up one level at a time until the tower is two miles high and the horizon is curved. I might have a spiritual sequel.)

My note to any who might be considering building a hotel on the moon: It’s the moon. Respect that. Understand that. Hire me as a consultant. I’ve just given you good stuff for free, but I have more.

A Matter of Consistency

While I was attempting (and failing) to write an episode thirty days in a row here at Muddled Ramblings and Half-Baked Ideas, a kid named James, known as the Iron Cowboy, today wrapped doing 100 full-length triathlons in 100 days.

Yep, 2.4-mile swim, 112-mile bike ride, followed by a full-ass 26.2-mile marathon.

100 times. In 100 days.

He did it to raise funds and awareness to rescue children from sex trafficking and sexual exploitation, so maybe he’s crazy, but it’s the right kind of crazy. My pals at Fezzari Bikes are proud sponsors, and I love them for that as well.

I can only imagine how it will feel for the Iron Cowboy to take a day off tomorrow. Congratulations, James!

Measuring Myself Against the Mountain

Plan A today was to head south on the lovely Coyote Creek trail, and depending how I felt when I got there, try attacking a new hill. The trail was blocked by a fire truck, however, as the crew sprayed water over a still-smoldering brush fire. I turned around and decided instead to test my progress toward my long-term goal of summiting Mt. Hamilton. I wouldn’t try to break my record, I decided, but there’s a nice loop that goes up the main highway and then descends on a smaller road that sees almost no traffic.

About a mile after I turned around I thought, “I should have taken a picture — fire trucks are exciting!”

It was even more annoying than usual getting to the base of the mountain, catching almost every single red light as I rode through the city. Grrr. Then it was time to climb. I have gotten better at riding very, very slowly, and I’m strong enough that I can almost sustain that snail’s pace for a decent period of time. The grade of the road is very consistent, but occasionally there’s a short stretch that’s a wee bit steeper, a difference you wouldn’t even notice while driving, but for me it’s the difference between sustainable and deficit. A little less down force on the seat post would put me over the top, I think.

I got to the turn-off for the descent, and after a short breather I decided instead to try to push up the mountain a little farther before going back down. Which is when my legs delivered their big, fat NOPE! I’d hardly gone any distance at all before I turned back and rolled on down the mountain. I added a couple of easy miles at the end for nothing more than pride.

Twenty miles to get to and from the actual ride, and six miles for the climb and descent.

1

The Chosen One

The archives of the True Disciples of the World-Changer were burned to the ground, and it turned out the data backup service they used was owned by their enemies. It is only by the most outside of chances that the content of the email the Disciples sent me was saved by their email provider for marketing purposes.

I did not read the email at the time, and even if I had, it would not have changed anything. When you read the excerpt below, you can see that it comes off a bit… Nigerian.

It began thus:

Blessings upon you, chosen one! You have been “randomly” selected to usher humanity into a new era! What will this new era be like? We all wait with great anticipation to learn the answer to that question from you! As the chosen one, you will leave a permanent imprint on the course of humanity forevermore.

How you exercise this great responsibility is of course entirely up to you, but we True Disciples of the World-Changer are eager to help you come to terms with your responsibility.

Alas, please note that the True Disciples of the World-Changer only invoke the “random-chance” protocol when humanity is under dire threat, and this time is no exception. Should those forces that wish to end humanity learn that you are the chosen one, they will stop at nothing to end you. For that reason, please do not share this email with anyone, no matter how trusted.

In retrospect, that explains a lot of what’s happening now. Especially when you consider that email is not remotely secure, and the Band of Destruction had long since put their tentacles in every email provider. There was more in the email, about contacting them, and giving them info, and thwarting an existential threat, but how many of those do you get every day?

Live and learn, I guess. Sorry, human race. My bad.

php’s missing array_usearch

Pure geekery today, kids.

php has a bunch of functions that work on arrays. (In most modern languages arrays are defined by classes or prototypes and have methods built-in. php is not a modern language.) There are functions like array_sort that takes an array and puts the elements of that array in order. That’s fine if you have an array of numbers or strings, but for more complex things, how does the code decide which comes first?

For that use, there is another function, array_usort that takes an array, and you tell it what code to use to compare the two items.

php also has a method called array_search which finds whether an array has a particular item in it. As before this works fine for simple items, but becomes less useful as the items in the array grow in complexity, or you want to find something that you don’t already have a full example of. What if you have a list of books and you want to find the one titled Huckleberry Finn?

It seems logical that there would be a search function where, as for array_usort, you tell the code what defines a “match”, and then off it goes to see what comes up. Logical, but it’s not there (unless it’s tucked away with a terrible name that makes no sense, which is entirely possible in php).

So after about the eleventy-hundredth time writing a little loop to find something in an array I said, “dangit, I’m writing array_usearch.”

function array_usearch(array $array, Closure $test) {
    $found = false;
    $iterator = new ArrayIterator($array);
 
    while ($found === false && $iterator->valid()) {
        if ($test($iterator->current())) {
            $found = $iterator->key();
        }
        $iterator->next();
    }
 
    return $found;
}

All this does is try each element in the array against a function you provide until the function returns true, then it returns the key for that item in the array. If no match is found, it returns false, the same way array_search does. Simple! Using it would look something like this:

// define a type to put into a list
class Thing  {
    public $id;
    public $name;
 
    public function __construct($id, $name, $category) {
        $this->id = $id;
        $this->name = $name;
    }
}
 
// make a list of them, mixed up a bit
$listOfThings = [
    new Thing(1, 'one'),
    new Thing(2, 'two'),
    new Thing(4, 'four'),
    new Thing(3, 'three'),
];
 
// find the index of the item with id = 4
$id4Index = array_usearch($listOfThings, function($thing) {
    return $thing->id === 4;
});
// $id4Index will now be 2

The function will work on all php array types, whether with numeric indices or strings.

php purists might object to using the name array_usearch because all the other array_u* functions take a callable for defining the function, while this version uses a Closure. There are a couple of reasons: 1) Closures didn’t exist in php when the array_u* functions were defined, 2) it’s the 21st century now and other languages use closures in this manner for a reason, and 3) closures allow the function that gets passed to array_usearch to be reused with different values. With a little extra setup we can make searching super-clean:

// function that returns an anonymous function that captures the id to search for
$idClosure = function($id) {
    return function($item) use ($id) {
        return $item->id = $id;
    }
}
 
$id4Index = array_usearch($idClosure(4)); // value will be 2
$id2Index = array_usearch($idClosure(2)); // value will be 1

Now we can write code compactly that can search for matches of arbitrary complexity, and we can create little factories to produce the search functions themselves, so the complexity is tucked away out of sight. This variation takes an array of key/value pairs and searches for items that match all of those values:

function firstIndexMatching(array $array, array $criteria, bool $useStrict = true) {
 
    if (count($criteria) < 1) {
        return false;
    }
 
    // create a closure that has captured the search criteria
    $testWithCriteria = function($criteria, $useStrict) {
 
        return function($item) use ($criteria, $useStrict) {
 
            foreach($criteria as $key => $value) {
                if (!isset($item->$key)) {
                    return false;
                } else if ($useStrict && $item->$key !== $value) {
                    return false;
                } else if (!$useStrict && $item->$key != $value) {
                    return false;
                }
            }
 
            return true;
        };
    };
 
    return array_usearch($array, $testWithCriteria($criteria, $useStrict));
}

Now if you have an array of people, for instance, you can search for the first match with a given name:

$joeCoolIndex = firstIndexMatching($people, [
    'firstName' => 'Joe',
    'lastName' => 'Cool'
]);

The loop and the comparisons are moved out of the way and all the main part of your code need to do is supply the criteria for the search.

Ultimately after a search like this, you will want to have the item, not just its index. That’s easy enough, but don’t forget that if no match is found, array_usearch will return false, which php will often conflate with 0, so extra care has to be taken when using the returned index.

$joeCool = $joeCoolIndex !== false ? $people[$joeCoolIndex] ?? null : null;

Obviously this could be added to the firstIndexMatching function if one is never interested in the index itself.

And there you have it! A simple callback-based search function, ready to keep your main code clean and clear.

Gettin’ the Lingo

The official Sweetie of Muddled Ramblings and Half-Baked Ideas recently acted on an long-term resolution to become better at speaking the language of many of our neighbors. After all, our city of residence is not Saint Joseph.

To pursue this goal, she has subscribed to Duolingo, an online language-learning application. She has been sure to put in a little time on the project every day, often combining it with time on our exercise machine. Buffing up brain and body at the same time!

When she went to the payment section of the portal, she discovered that a family pack didn’t cost that much more than an individual license, and she knew full-well that there were several family members who have been wanting to learn one language or another.

So now I’m signed up, too. I will be learning Spanish too, but first I wanted to get a start on remembering what little Czech I once knew. I have family members who speak Czech, so it makes sense. I figure a month to show progress with the Czech before I add in Spanish sessions as well.

It’s pretty exciting, but when the program tested my current level of Czech proficiency, it politely said, “let’s start at the beginning.” So I’m starting at the beginning, but when they throw a new word at me, there’s a pretty good chance I already know it.

Is Duolingo better than other language-learning software? Honestly I don’t know, and I’m not sure how much that even matters. What matters is devoting a little time each day to add a new phrase or two. Beyond the actual lessons, Duolingo devotes enormous energy to rewarding consistency, and bestowing worthless cartoon trinkets for taking an extra lesson in a session. I got my five-day-straight pat on the back today.

Big June

It’s been June for about two hours now, Pacific Daylight Time. It’s going to be a big month. I have mede some commitments.

I will exercise. I have joined a team health habit challenge with some coworkers and I will not let them down.

I will blog. Every day this month I will post some half-assed shit. Welcome to the first installment of that.

I will write. Every damn day I will add to Munchies. Or subtract from Munchies. Whatever’s right at the time.

Addendum: I will remember to hit “Publish” after I write a blog episode.

A Tale of Two Bicycles

According to the Velominati, the correct number of bicycles to own is n+1. However, I’m pretty content with two.

I bought the first bike in 2014. I went in to a Mom-and-Pop-and-Kids bike shop and told them I would be commuting on a bike but I didn’t need anything fancy. They pointed me to the Escape 0 by Giant, which I think was discounted because it was being discontinued. It is a “hybrid” bike aimed at commuters – mountain bike drive train with lots of gears (important for skinny-leg people carrying lots of stuff), an upright posture good for traffic awareness, but narrower tires intended for road use.

I kind of fell for the upsell when I chose that bike, but I have no regrets. And I had a list of other stuff to load up on before I even left the store: cushier seat, floor pump, helmet of course, and on and on. I left a fair chunk of scratch at the bike store, and I’ve paid quite a bit more since, yet conservatively all of that has been paid and then some with gasoline not burned driving to and from work.

To say nothing of the other benefits. Health, happiness, and Yet Another Bike Episode here at MR&HBI.

Over time I’ve added a beefier rack, gone through a few different panniers (the bags that attach to the rack), put fenders on for rainy days (I kind of like the rain), various lights (including Revolights, which were a great idea but never found their market), and on and on. My mantra was, “the weight I take off the bike should come from my gut.” I’ve put a lot of miles on that fine machine; many good hours being out in the world instead of boxed in metal and glass.

When I commuted by bike regularly, I started to recognize some of the others out there. A lot the other riders were decked out in tight-fitting bike gear, riding their fancy bikes. I would measure myself against those riders, pushing a little extra to maybe catch up with the Big Bald Guy at the next light. I could sometimes keep it close with one spandex-wearer, but if another came along, that was it. they would vanish over the horizon with a wink of light.

Most of that, of course, is because I’m a skinny-leg big-belly graybeard, but it turns out the hardware matters as well. Enter the Fezzari.

When the pandemic came down, I had not been riding regularly. Early on I took the disruption of my life as an opportunity to rebuild some good life habits, and the bike was at the center of that. Things were going great, until a mechanical issue during a major supply-chain disruption left me with no bike for a while. Late one night, I thought, “What if I buy another bike?” The only bikes available were the really high-end ones, but if I was gong to justify another purchase, it had to fill a different role than my commuter bike anyway.

You know how that turned out. And now here we are.

Wednesday I rode the Giant to work, lugging along a change of clothes, a laptop, shoes, about five pounds of food, and other odds and ends. Even if I could fit all that in a backpack (doubtful), then my back would be a swamp by the time I got to work. No problem on the Giant. It is a stable ride, comfortable, with an upright posture and wide handlebars for easy control. Thirty different gear ratios to choose from and that good ol’ cushy seat means that while I’m riding I’m just traveling, getting where I’m going with a minimum of fuss. It’s not a bike commute, it’s simply a commute.

It’s the bike I ride to the store (usually the bike store).

When I got on the Fezzari I discovered a new sort of bicycling. The bike is small, and twitchy, and fast. I’m still learning to ride it, still getting used to the more aggressive seating posture (I’m very happy I asked them to set it up with a “relaxed” posture, adding a bit of height on the handlebars so I’m less hunched over.) My hands tend to go numb on long rides; I’m still searching for the right posture and grip to deal with that extra weight on my arms.

But there are times, many times, when all that is forgotten and I’m cranking along to the sound of my tires whooshing over the pavement and it’s sublime. I love that bike.

I think, in fact, I love it more because I still put in the miles on the Giant. I am constantly reminded just what makes the fancy road bike special. Without that contrast would I start to take my new bike for granted? (Actually, probably not, but it’s still a good reminder.) And what about my faithful pack mule? I love it more, too, for having ridden the Fezzari; I appreciate the comfort and the capacity and the simpleness of riding it. It’s the perfect tool for the job.

Special bonus: twice the time tinkering in the shade of the tree in our backyard.

3