It’s been a while since I’ve done a programming post, but something came up the other day that I thought might be useful.

In one of my current projects, I needed to determine the number of words in a string. Simple enough, but before I wrote the code, I did a Google search to see if there was some obvious better way. Surprisingly, not only didn’t I see a better way, but all the examples I found were either really inefficient or wrong–or both!

In the inefficient and wrong category, a lot of people were doing a split on various white-space characters (or just a space), creating an array just for the purpose of counting. Not only do you end up with a potentially massive data structure you don’t need, but if there are multiple spaces or odd white-space combinations, you end up with bogus entries. Yikes.

Anyway, It seems that the test for accuracy is comparing to MS Word’s algorithm. My algorithm is pretty simple, but is fairly efficient, and matches the MS Word results for every test I’ve tried. This doesn’t mean that it is right–merely that, if it is wrong, it is wrong in the same way as MS Word!

I wrote it as an extension method, so it needs to be put into a static class. White space and comments removed for brevity:

public static int CountWords(this string value)
{
  int count = 0;
  bool inWord = false;
  for (int i = 0; i < value.Length; i++)
  {
    bool isWhiteSpace = Char.IsWhiteSpace(value[i]);
    if(!inWord && !isWhiteSpace)
      count++;
    inWord = !isWhiteSpace;
  }
  return count;
}

Not much too it. Hopefully it will be useful to someone…

Tagged with: ,

Recently I posted about a couple of my short stories that just came out, including Waiting to Sleep in Literary Hatchet #24, and R.I.P. in Ink Stains Anthology #13.

At the time, Waiting to Sleep was only available in print and R.I.P. was only available as an e-book. Well, now both are available in both formats! Here are the links:

 

My short story Waiting to Sleep just came out in the magazine Literary Hatchet #24. At the moment, only the (free) e-book version is available (although you have to register to download it), but the print version should be out in the next few weeks.

This is sort of the reverse of my last published story, R.I.P., which is available in print, but not yet as an e-book.

Waiting to Sleep was an attempt to create a “creepy” story, but your mileage may vary. It was inspired by my waking up in the middle of the night, and mistaking a pile of blankets for Anna.

 

My story R.I.P. just got published in the Ink Stains Anthology #13!

Since Anna is such a big zombie fan, I figured I should try writing a zombie story, which turned into R.I.P. It is not exactly a classic zombie story though (so Anna tells me, and she should know :-).

My copy hasn’t arrived yet, but I did get the very creepy cover art. It took a while to notice that the figure standing in front of the window is facing inwards. (FYI The cover art is not related to my story).

Most of the stuff I write would probably be classified as science fiction, but for some reason, more of the stuff I sell tends to be horror. Not sure if I should be disturbed by that…

The Kindle version doesn’t appear to be out yet, but I’ll put up a link when it becomes available (I’m assuming it will be rather cheaper than the print version).

About a year ago, I posted about the 2018 Bulwer-Lytton fiction contest, in which one of my entries was a runner-up in the Crime/Detective category. Well, this year I did better (or worse?) – I won in the Fantasy & Horror category!! Here is my entry:


Driven from the sea by pollution, Aglaope the Siren found an economy apartment in New York City with the hope of luring the big city buses to their doom, but to her dismay she found that her song was drowned out by police cars, fire trucks and jackhammers, except for one joyous day when she was fairly sure that she caused a skateboarder to crash into a light pole.
           –Arlen Feldman, Colorado Springs, CO


But wait, there’s more — I also got another dishonorable mention in the Crime/Detective section!


As he pounded on the door, Billy ‘Four-Toes’ Capalone, wondered, not for the first time, if he wouldn’t have been better off in the joint, or even taking a concrete nap, but instead, he straightened his tie and gripped his bible, determined not to blow his cover in the Jehovah’s Witness Protection Program.
           –Arlen Feldman, Colorado Springs, CO


Here’s the 2019 grand prize winner:


Space Fleet Commander Brad Brad sat in silence, surrounded by a slowly dissipating cloud of smoke, maintaining the same forlorn frown that had been fixed upon his face since he’d accidentally destroyed the phenomenon known as time, thirteen inches ago.
           –Maxwell Archer, Mt Pleasant, Ontario, Canada


And here are a few of my not bad enough entries:

  • Nigel had always wanted to be a hard-bitten detective, but life had not worked out that way, and he now worked at the San Fernando zoo–though when he discovered that he’d accidentally been locked into the lion cage with the anesthetic on his patient wearing off, he realized that he was soon going to be a hard-bitten veterinarian.
  • His professor recommended against protesting against the hate group’s planned speech, saying that you shouldn’t give them oxygen, but since the school was located on the moon, John interpreted that to mean that he should open all of the airlocks.
  • Professor Banes eventually won the Nobel prize for his ground-breaking work combining ruminant biology with sub-atomic physics, after his surprise discovery of the Higgs Bison.
  • She was the girl of his dreams, right down to the polka-dot flippers, the lobster claws, and even the bowl of strawberry-banana Jell-O.

A month or so ago, I noticed a pool of water in our basement, by the floor drain. Given that all of our things, particularly in basements, appear to be hydrophilic, this made me sad, but less so than the recent burst pipe in our wall that ruined carpet and dry wall!

However, the drain issue was some place I could see, and the problem was relatively obvious. There were three pipes running from the furnace, AC and humidifier, and they all just ran along the floor to the general vicinity of the floor drain. I didn’t think to take a before picture, but just imagine three pipes running to the drain, which was smaller than the three pipes side-by-side.

My first plan was to go to the hardware store and buy something that would let me combine the three pipes into one, but, alas, they don’t appear to make such a thing. Well, actually they do make a four-way connector that looks like a plus sign, but by the time you added the right-angles for the outer lines, the whole thing would get really wide.

So, 3D printer to the rescue (and not remotely an arbitrary reason to play). I created a pipe combiner that took the three inputs and combined them into a single output. Here is a shot of the prototype (i.e. the first one I printed where the holes were the wrong size):

You can sort of see how the lines come together inside. Yes, it is a bit more blocky than I would like–straight lines are just easier to create, although the new drain cover is nice and curvy…

Rather than just having the pipe just sit on top of the old nasty drain cover, I went ahead and printed a new cover that would take an angled fitting. You can’t see it so well in the picture, and I didn’t take a picture of it before putting it in place, but here is an image of the 3D model:

I had to do a little bit of trigonometry to position all of the smaller holes, but I like the way it looks:

More important, no more pools of water!

 

Tagged with:

We have a frog in our pond! I can only assume spontaneous generation. He (or she) doesn’t seem to bother the fish (we have 3 goldfish and 3 Koi, which I’m told are different things).

 

 

 

 

 

Here is a shot of the whole pond:

I can’t tell if this is the worst or best marketing I’ve ever seen.

I’d say it was tasteless, but honestly I didn’t try it.

Bad trees, bad trees,
Whatcha gonna do, whatcha gonna do
When they rot right through?

Bad trees, bad trees,
Whatcha gonna do, whatcha gonna do
When they fall on you?

Another year, another stupid costume for Karvel Kon!

And yes, we sang the song with the actual Cops theme music.

If you’ve not heard of the Cops TV show, then this costume probably doesn’t make any sense whatsoever. On the other hand, if you have heard of the Cops TV show, it probably doesn’t help a lot.

Here’s the back of the costumes:

Although the costumes are fairly simple, there are a few interesting details for those who are interested:

  • Camouflage clothing is usually quite expensive, and we started with Goodwill, but ended up in Walmart. Anna has an app that looks up the actual price of things in their system vs. the marked price. I was pretty dubious, but the trousers were listed for about $12.00, but were actually on sale for $6.00, and the hoodies were listed as $28, and were really only $5.00! We ended up spending more on the fake tree branches than on the clothes (Anna has claimed the trousers for pajamas, and the tops for use when clearing snow, so they live on).
  • It’s a little hard to see in the picture, but The COPSE text on our backs is more-or-less in the same font as from the show:

The font is called Due Date. Anna cut out the letters using her Silhouette Cameo Electronic Cutting Machine. In theory, she could have taken the image as a file, but it ended up being easier to just scan a printout and then have the machine cut it out of sticky vinyl. We had a little problem with the loose pieces of the C and the E coming off, so had to be a bit careful moving around–we could have applied the letters in a more permanent manner, but Anna wanted to be able to reuse the outfits later.

  • Here is a close-up of our “Bling”:

The bird house was a dollar at the craft store. I 3D-printed the air freshener. Then we just spray-painted them both with a metric-ton of glittery-gold spray-paint. The black chain came from the hardware store (they didn’t have gold). Anna thinks I should hang the air freshener from the mirror in my car.

Last week, the EFF (Electronic Frontier Foundation) sent a letter to the director of the US Patent and Trademark Office, Andre Iancu, and I am one of the cosigners of the letter.

I will probably be talking a lot more about patents (particularly software patents) over the next few years, but I can tell you that the system is broken.

The patent office grants incredibly vague, non-innovative software patents all the time (which is hardly surprising, given that the average patent application only gets about 19 hours of review before being granted). Companies then use these patents as bludgeons against small companies. More than 80% of patent cases last year were filed by patent trolls who don’t create anything–they just shake down companies–most of whom cave, because it is too expensive to fight.

There have been a number of court cases in the last few years that have improved the situation, but there is a big fight to try and undo this progress, both in Congress (that whole pro/con thing is a bit confusing) and in the patent office. There seems to be a genuine lack of understanding of the damage that these patents cause.

And yes, as you can see from the picture, I am also a holder of a software patent (and have another pending). This may seem a tad hypocritical, but in the current environment, they serve a defensive purpose (and only a defensive purpose). I would happily give them up in exchange for fixes to the system.

You can read about the letter here, and see the letter itself here.