Longest Common Prefix Between Two Strings

While working on a “for fun” side project I needed to get the longest common prefix of two arbitrary strings. Since I didn’t find what I was looking for in the PHP string functions I made my own. And for some perverse reason i decided to see what the fewest number of lines I could do it in was without displaying warnings…

I got down to a one line function, and managed to avoid using an @ to silence anything…


function str_common_prefix( $s1, $s2, $i=0 ) {
return ( !empty($s1{$i}) && !empty($s2{$i}) && $s1{$i} == $s2{$i} ) ? str_common_prefix( $s1, $s2, ++$i ) : $i;
}

I’d be interested to see what others come up with.

OnLive trolls

Man, trolls suck be they on forums, in blog comments, or, when playing video games. I just had an experience with the OnLive video game service which has me of two minds.

I was playing Borderlands ( I *LOVE* This game ) single player… And a spectator started watching me. As soon as he entered (before I could even do anything) he gave me 30 “jeers” (essentially its like sitting on the sidelines at a sports game and yelling “BOOOOOOOO YOU SUCK.”)

Now I know that I can go into my preferences and turn notifications of “cheers” and “jeers” off (it’s be nice if I could just turn jeers off, but thats another matter.) The online person being an ass isn’t what bothers me (I’ve run everything from IRC networks to Forums to Blogs, I’ve come to grips with people and their need to troll.) It’s that now someone can troll me when I’m not playing a game multiplayer.

I tend to play games for an escape, the same reason I read books. On my Xbox360 I can play a game locally, and nobody bothers me. On OnLive that’s not the case. Someone can randomly find me – whether im playing a network game or not – whether they own the same game or not – whether we’re friends or not – and give me an, apparently, unlimited number of thumbs down. Even were I to change my settings to not show jeers while I’m playing it still goes on my OnLive profile telling the world “this guy must really suck.”

I think that the technology of OnLive is AMAZING, though I wish their selection of games was bigger and/or more timely, but I’m not sure I like other people intruding on my experience in this way with complete impunity. It really only takes a handful of spoiled apples to ruin the bunch sometimes.

I wonder how prevalent this is and whether other people find it as subtly annoying as I have?

[ Edit: As it turns out I was completely wrong about the permanence of cheers and jeers, they are thankfully not attached to your profile (at least not anywhere that I or anyone else can see them.) In this I was wrong 🙂 ]

Peanut Butter Cup Salad

My wife asked me to recreate the recepie of something we get from the store so we could make it chunkier (yea, thats what I was told) and she could bring it for a potluck/meeting at work today… I got it pretty much spot on, so I thought I’d share it with you.

Peanut Butter Cup Salad

Ingredients

  • 1 cup whipping cream
  • 1 tbsp sugar
  • 1 tbsp lemon juice
  • 2 green apples
  • 2 red apples
  • 20 peanut butter cups
  • 1/2 cup roasted peanuts

Instructions

  1. Boil peanuts until no longer chalky when chewed, remote from water, set aside to cool and dry. If the texture is off-putting to you then don’t boil them, but the “chew” is nice in the finished dish, so perhaps use a more chewy nut instead?
  2. Core and cut apples into 4 wedges, slice wedges into 1/8 to 1/4 inch pieces each with a bit of skin. toss apple slices in lemon juice, set aside. The lemon will help prevent the apples from browning and give them a little bit more “zing” to cut the sweetness of the finished product.
  3. Cut peanut butter cups into desired sizes, chop the last 4 very fine (this is to flavor the whipped cream)
  4. Whip cream and sugar till stiff (if you cut a valley into your whipped cream the sides should not ooze in to fill the gap.) You want the cream just barely sweet, but not overly so, adjust sugar level while still soupy. If you’re feeling really adventurous bloom a packet of gelatin in a small bit of the cream before making your whipped cream, it will make the product last longer and give it a more unctuous mouthfeel (I have not actually tested this…)
  5. In a large bowl mix peanuts, apples, and peanut butter cups thoroughly. Mix them together first because over mixing with the whipped cream will make un-whipped-cream.
  6. Fold in whipped cream in 3 batches with as little “stirring” as possible (otherwise you break the whipped cream back down to just cream.) Everything should be just coated, but not so much that you can no longer see the ingredients (except the peanuts, those will be hard to see).
  7. Place plastic wrap tightly down on the entire surface of the mass in the bowl (cream picks up funky flavors in the refrigerator, and nobody wants their desert tasting like wet yak hair!)
  8. Let rest 24 hours for best taste (it takes time for the whipped cream to really soak in the peanut butter cup flavor.)
  9. Devour

Let me know if you try it and/or have anything to say about it!

Postfix, DKIMproxy, Spamc

If you’re running any moderately busy mail server you’re probably using spamassassins spamc/spamd to check for spam because its tons more efficient than piping the mail through the spamassassin cli. Assuming that you do, and that you plan on adding DKIM proxy to the mix to verify  and sign emails you need to put things in the right order, to save you some headache here’s what I did:

  1. smtp|smtps => -o smtpd_proxy_filter=127.0.0.1:10035 # outgoing dkim verify port
  2. 127.0.0.1:10036 => -o content_filter=spamassassin
  3. spamassassin =>  pipe user=nobody argv=/usr/bin/spamc -f -e /usr/sbin/sendmail -oi -f ${sender} ${recipient} # this delivers to the “pickup” service
  4. pickup => -o content_filter=dksign:127.0.0.1:10037 # outgoing dkim signing port
  5. 127.0.0.1:10038 => -o content_filter= # the buck stops here

If you arent careful with these (which I wasnt) you’ll end up causing an infinite loop between your filters (which I did).  Thus concludes our public service announcement.

Bash: “I Can’t Eat Another Byte”

root@server:/dir/ # ls | wc -l

1060731

root@server:/dir/ # for i in *; do rm -v $i done; done

me@home:~/ #

HUH?

Turns out that bash just couldn’t eat another byte, and next time I logged in I saw this: “bash[5469]: segfault at 0000007fbf7ffff8 rip 00000000004749bf rsp 0000007fbf7fffe0 error 6“… Impressive 🙂

LOLSPAM?

support to spammer: “are you a spammer?”

spammer to support: “oh hai. oh noes!1!!!”

support to spammer: “then what about all this?”

spammer to support “oh noes! they must have didz  used mah open proxee i forgotted about which sawmhow got installed on all 200 of my vertual hostez!!1! teh icanhasspam script”

support to spammer: “oh, sounds reasonable, dont let it happen again okay?”

spammer to support: “four surez!!1! lolz!