Dynamic Type Selection in PHP

So, check out this block of PHP code:

class MyClass {
  public function doSomething() {
    echo "Hello there.";
  }
}
$class = "MyClass";
$method = "doSomething";
$instance = new $class();
$instance->$method();

The “new” statement is using a string variable to specify the class being instantiated! What’s more, on the very next line, another string variable is being used, this time to specify the method being invoked.

My background is C-like languages (C, C++, C# and Java), so I was somewhat surprised to discover that this not only executes, but does so without errors. Turns out, this is just how PHP’s new statement works.

In Java, you’d use Class<T> to get the class object, retrieve a specific constructor, and then call the newInstance method, passing any required parameters. So the above example would end up looking something like this:

package myprogram;

import java.lang.Class;
import java.lang.reflect.Method;

class MyClass {
    public MyClass() {}
    public void doSomething() {
        System.out.println("Hello there.");
    }

    public static void main(String[] args) {
        String className = "myprogram.MyClass";
        Class<?> class = Class.forName(className);
        MyClass instance = class.getConstructor().newInstance();

        Method method = class.getMethod("doSomething");
        method.invoke(instance);
    }
}

In a more complex code sample (e.g. passing arbitrary class objects into a method to be instantiated and used in a callback), the Java version has definite advantages in terms of compile time type checking.

But I can’t deny that the simplicity of the PHP version also has some appeal.

Resetting Your Password

You can change your password on any enterprise system by following these simple steps:

  1. Login to the password reset page by answering security questions anyone with Google can look up.
  2. Generate a strong password, such as
    yK5*BDbYv91xAaU!BukN
  3. Discover you can’t paste the secure password into the form.
  4. Click your password manager’s “Generate password” icon which generates a password into the field.
  5. Click Save.
  6. Discover that your password manager was blocked from saving the new password and that you no longer know your password.
  7. Discover that you can’t reset your password twice in one day.
  8. Email the system administrator, requesting that your account be unlocked.
  9. Login to the password page again, using those same easily Googable security questions.
  10. Set your password to
    P@$$word123

(Pro-tip: Substituting a dollar sign for each ‘s’ makes it extra secure.)

Composting

A while back, a friend posted on Facebook that her family was building a compost bin and she was looking for tips. She also mentioned that she was saving kitchen scraps (but no meat or dairy) and what do people think about the “compostable” bags?

Whoo. I try to be a well-rounded geek, and I spend a lot of time doing yard work, gardening, and of course, collecting leaves for the compost pile (to the point where in the fall, the neighbors have started bringing leaves directly to me, skipping the step where I “steal” them from the curb.

The quick version of what I posted on Facebook is:

  • No meat/dairy – because it attracts vermin, it attracts flies, and it stinks.
  • No kitchen waste – that’s apple cores, wilted lettuce, etc. Why? Because it attracts vermin. If you’re lucky, it’s just flies and mice. If you’re unlucky? Rats and raccoons.
  • The aforementioned kitchen waste is awesome however for a worm bin.
  • So what does go in the compost bin? Fall leaves, non-diseased pieces of non-woody plants, and more fall leaves.
  • Coffee grounds are also good in the compost pile. They help the leaves turn to humus much faster.

For the “compostable bags” though… it depends on what they are. If it’s brown paper bags, technically, you could compost them. But recycling is probably a better choice. (I’ve composted cardboard in the past, but unless you tear it up into small pieces, it’s gonna take a long time to break down And any other paper should definitely be recycled, with one exception: shredded newspaper is good for worm bins.

On other hand, if the bags are those so-called “compostable plastic” bags (or any other sort of “compostable” plastic), then they don’t belong in a home compost pile. Those things require an industrial composter and won’t break down in your garden compost pile.

Related reading:

If you’ve read this far, you could do far worse than to visit the You Bet Your Garden question of the week archive, type “compost” into the search box (the one in the middle of the page, not at the top), and read everything that comes up.

For starters, check out the Compost 101 article .

There’s a good starting point for reading about worm bins.

(Image by flickr user kake_pugh licensed via CC BY-NC-SA 2.0)

They Keep Killing Glenn – You Only Hurt the Ones You Love

If “you only hurt the ones you love,” then Glenn Hauman has been loved like few others. Loved to death in fact. Repeatedly. A different way each time.
 
They Keep Killing Glenn is a collection of short stories with one thing in common, in each story, Glenn Hauman dies. One might be forgiven for thinking that this would only be entertaining for people who actually know Glenn (and there is a joke or two which make more sense that way) but overall, the stories should appeal to anyone who enjoys a bit of lighthearted entertainment, regardless of whether Glenn has crossed their path.
 
(Full Disclosure: I know Glenn, and many of the people who killed him. Through some cosmic error, my own tale of his death was also included.)

Finders Keepers

Finders Keepers by Russ Colchamiro is most definitely a fun read.

A pair of cosmic engineers, responsible for constructing The Earth, have misplaced a jar of Cosmic Building Material, essentially, the universe’s DNA. And with the inventory due to be taken, they need to get it back quickly or face the ultimate punishment.

Meanwhile on Earth, a pair of young backpackers are travelling across Europe, looking for someone who can tell them about a mysterious jar found in a cave in New Zealand, unaware that others, exiled from Eternity, will stop at nothing to take it from them.

It’s a entertaining story, broken into small chunks which can be read as time allows (helpful if you find it difficult to carve out an hour or two at a time). Even the minor characters are fleshed out enough to make them part of the story instead of props. And as the story wraps up with some surprising twists, even the most villainous of the characters begins to show signs of redemption.

Numbers in man page references

I’m always forgetting what they mean and how to use them.

There’s a great answer at: https://unix.stackexchange.com/a/3587/223606

For me, the important parts are:

MANUAL SECTIONS
    The standard sections of the manual include:

    1      User Commands
    2      System Calls
    3      C Library Functions
    4      Devices and Special Files
    5      File Formats and Conventions
    6      Games et. al.
    7      Miscellanea
    8      System Administration tools and Daemons

    Distributions customize the manual section to their specifics,
    which often include additional sections.

And the syntax:

$ man 1 printf
$ man 3 printf
$ man -a printf

Targeting a Project in a Solution Folder in MSBuild

Normally, when you invoke the MSBuild task to build a solution file, you can just add TARGETS=”ProjectName”, where ProjectName is just the name of the project, and don’t include the .csproj extension.

I already knew that if your project name includes a period, you need to replace that with an underscore (so the project “MySite.Web” becomes “MySite_Web”).

But the UnitTests project kept coming up as not a known build target name.

Finally, I found my answer in a comment in the answer to “specify project file of a solution using msbuild” on Stack Overflow.

Turns out that when a project appears in a solution folder (as opposed to just being in a directory), you need to include the name of the solution folder, and a backslash. So since the UnitTests project is in the UnitTests solution folder, the MSBuild invocation ends up looking like this:

<MSBuild
    Projects="$(SourceLocation)\$(SolutionName)"
    Properties="Configuration=Release; Platform=Any CPU; OutDir=$(OutputFolder)Assemblies\; WarningLevel=0;" 
    Targets="UnitTests\UnitTests" />

Random Memories of Shakespeare

A Random Memory…

In my mid-twenties, I spent six years living at Lake Tahoe. Literally within a half-mile of the beach. Every summer, I would Volunteer at first the Music at Sand Harbor festival, and then a month later, at the Shakespeare at Sand Harbor Festival. A set of events taking place in the dunes at the Sand Harbor Lake Tahoe Nevada State Park. (The latter event is still around as The Lake Tahoe Shakespeare Festival).

I would work every night at both festivals as one of the security Volunteers. They called it “Security”, but it was really ushering. We were mainly concerned with helping people find a spot for their blanket and then keeping them from going into the environmentally sensitive parts of the dunes. Since I was there every night, and people somehow got the idea I was responsible, after a year or two, I was put in charge of security for both events. Which mainly meant getting there early so I could drag a shovel through the sand to mark where the aisles would go.

People tended to Volunteer for a few nights, so you’d get to know one another. One Volunteer I recall was a young woman named Ashley. She’d arrived early one Saturday and after we’d drawn the aisles, we had some time to kill. I looked at the aisles and commented, “Y’know, those aisles would be a lot easier for folks to see if we marked them with a rope.” Ashley agreed that was probably true, so I asked, “Would you go over to the lifeguard station and ask if we could borrow about 200 feet of shore line?”

Ashley came back about 20 minutes later to report that the lifeguard didn’t have that much available and had suggested she try the park office.

Sadly, the whole thing fell apart at that point because I couldn’t keep a straight face any longer.

(Image by Wikipedia user DimiTalen, used under Creative Commons Attribution-Share Alike 3.0 Unported)

They Keep Killing Glenn

The usual rule with a scandal is that when it first breaks, you start off with the angry denials. This goes on for a few weeks, with increasingly intense press coverage, until at last you get to the next stage, the tearful confession. Well, let’s skip over all that and go straight to the part where the accused becomes the prosecution’s star witness and throws his co-conspirators under the bus in exchange for leniency….

At the 2017 Farpoint convention, I attended the panel for Crazy 8 Press. As nearly as I can remember, most of the Crazy 8 authors were present: Peter David, Robert Greenberger, Michael Jan Friedman, Russ Colchamiro, Aaron Rosenberg and Glenn Hauman. Only Paul Kupperberg was missing (Mary Fan hadn’t yet joined the collective). Kathleen David was sitting in the audience.

The panel started off with comments that the group is looking for ways to boost their book sales, with some dark humor thrown in about how Peter’s book sales skyrocketed after his stroke several years ago. So naturally the question was raised of who was willing to “take one for the team” and boost book sales by having a stroke.

Somewhere in there, the suggestion came up, “Maybe we need to kill someone” to which Glenn replied, “We’re writers. We’re always planning to kill people.” My recollection is that it was Aaron who responded, “Yes, but it’s usually you.” Pandemonium ensued as one author after another took turns suggesting ways Glenn might die.

In short order, they decided to publish an anthology of short stories in which Glenn would die. Once Peter announced the title should be, They Keep Killing Glenn, I knew what I had to do. I pulled $20 from my wallet, marched to the front of the room, and offered it as my contribution to the expected Kickstarter campaign.

And that’s why Glenn says it’s my fault the book was written.


This next part kind of boggles my mind. They Keep Killing Glenn is now available, and this is the list of authors from the book’s back cover

I mean, look at that list of names:

David Gerrold – that’s the guy who wrote one of the most popular Star Trek episodes ever, The Trouble with Tribbles.

David Mack, Robert Greenberger, Peter David, Michael Jan Friedman, Keith R. A. DeCandido – These are Big Names in the world of Star Trek writers. They’ve all been on the New York Times best sellers list. Multiple times.

Paul Kupperberg – that’s another Big Name. He’s the guy who writes the current incarnation of the Archie comics.

As far as I can tell, almost everyone else on that list has been published multiple times and most of them have authored multiple books.

And then there’s that name circled in red. Blair Learn. What’s that name doing there?

Most of what I write is software documentation, describing how the pieces fit together, explaining processes to other developers. And yet somehow, a story I wrote has been included in an anthology with all those big names.

In February of this year, they announced that yes, they really were going to publish the book. And in addition to gathering submissions from professional authors, they were also going to accept up to three submissions from fans. I’ve spent a little time chatting with Glenn over the past several years, and having a story published professionally has been an entry on my bucket list for a while… So I submitted a story titled “R is for Roadster.”

They Keep Killing Glenn will be debuting next month at the Shore Leave science fiction convention, just outside Baltimore. But you can order it from Amazon right now.

George Romero and Monroeville Mall

I’m not really into the horror genre, but in college, I do remember watching the original Dawn of the Dead and laughing at the various scenes shot in Monroeville Mall. I particularly remember watching the heroes drive cars around the lower level and thinking that must have been fun. And, of course, the scene on the ice rink – I grew up in that area and remember skating on that rink. Seeing it used for “zombie hockey” was an odd experience.

For whatever reason, the Twitters dropped a link on me today: it seems a group of fans is putting up a bronze bust of George Romero at the mall.

There’s also a mention of a footbridge from the mall being preserved at the Heinz History Center. I have some vague memories of that bridge. The article includes a link to a story KDKA did in 2015, talking about the bridge’s removal, complete with scenes from the movie and people dressed up as zombies helping to load the bridge pieces into a van. According to the news story, there were plans to put it on exhibit sometime this year.

Photo by flickr user daveynin, used under Creative Commons Attribution 2.0 Generic (CC BY 2.0)