Say Cheese(ish)!

I overheard (slash walked into) what turned out to be an interesting situation this evening.

The back-story is simple. I drink and there’s a bar I can walk to/fro my house in a few minutes. Quite safe and I like it that way.

At the bar this evening I heard some talk about a massive roadblock/traffic stop just down the street. I typically don’t have a problem with those, though I’m certainly never happy to hear about the “over-zealous” officer that occasionally happens. As I walked home, I clearly saw that everything was still in place.

With the help of the drinks I’d had, I decided I should randomly take pictures as I walked by. Maybe a bad idea, but I kind of wanted to see what happened here after the stories I’ve read about random folks trying to document something in public. So here we go…

One of the officers noticed me immediately and knew to “blind” my camera with his hand-held spot light - I’m going to call him Mr. Spotlight. They weren’t doing anything wrong as far as I saw, I just wanted to take some pics… especially if they’d rather I didn’t.

Again… also, between this and the next pic, I had a fairly genial exchange with the officer.

More white-out…

Whoops! Don’t think they wanted me to capture this platoon of motorcycles. It’s nice to know how to take a pic with your phone at the side :)

Typical roadblock stuff - to be clear, that’s a street lamp, not them trying to hide anything

Another completely harmless pic I managed…

Moments later I turn back to take a pic … and there’s Mr. Flashlight again!

After the encroachment on the previous pic, I wanted to take some more… at this point Mr. Flashlight has moved closer and is still obviously aware I’m still around…

Last one - he kept watching me as I went and made sure the light was up every time he noticed me taking a pic.

Now, just to make those bikes more mysterious…

here are some of the cars sitting around at the actual stop point… no one there seems to care. why should they, right?

Oh, the motorcycles are gone….

Still don’t care…

Still don’t care…

Still don’t care…

And finally, they still don’t care.

Once the bikes left, everything else dispersed as they disengaged “their” motorists. It really seemed that my presence may have made them move along. I find that amusing considering that their presence was known well before I passed by.

To conclude, it seems there was absolutely nothing happening here aside from a typical Friday night roadblock. The pictures I took appear to be 110% harmless. But the actions of the officer “blinding” me just make the whole thing seem suspicious.

Base 64 URL encoding/counting

Several years ago I had the need to automate rate management for a system running the Harris Protocall calling card platform. Never heard of it? You’re probably a better person for it.

Previously the system was maintained by hand which obviously was extremely error prone. Just to give you a quick idea how easily it was to screw up, consider this… the system was completely powered by FoxPro “databases”. Not even Visual FoxPro - we’re talking old school, early 90s FoxPro 2.6 for DOS. The rate updates required manually updating things across 4 or 5 “tables” via an ASCII interface prettied up with some ANSI coloring.

That mostly just sounds antiquated, not difficult. Now consider that we’re talking about at least 20 or 30 Rate Plans in the system and to squeeze every penny out of international telephone rates, you’re talking about upto 3500 rates per plan, split up by country and city codes. Updated by hand. From a spreadsheet. Possibly several spreadsheets. Ugh.

Anywho, back to the point - this old ass system was NOT built to support that many rates. To fit that many rates into the system, I needed to be able to convert some 4 and 5 digit numbers into a 3 character field. Without some massaging, that obviously does not work. My initial thought was to try converting decimal to hex since that’s something pretty universally supported across languages. No dice, that simply didn’t compress the numbers enough. That was definitely the correct approach, though, so I put in a little work and started doing Base32 “encoding” or “counting”. It worked perfectly.

Skip ahead to late 2008/early 2009 and I found myself needing to create shortened URLs for a couple sites thanks to Twitter. I could have simply used the Base32 encoding I’d previously created, but I really wanted the most bang for my buck, so I decided to start playing with Base64 “encoding”/”counting”. The biggest issue here is that you have to be very careful about the character set you use since they need to be characters that do not require being encoded in URLs, so things like “=”, “/”, “?” and so on are not viable options. You may immediately thing “oh, sure, I have a function for Base64 encoding” and yes, you do, but it includes unsafe characters and is not actually for compressing things - in fact, it will make a string/number longer. As you’ll see below, I quickly filled up 62 characters by using “a-z”, “A-Z”, and “0-9″. I then picked “-” and “_” since they should be safe and appear in tons of URLs.

Ok, so here is the original PHP code I used:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
    /**
     * Decimal to pseudo-Base64 encoding/counting
     */
    public static function dec2bsf($int){
        $chars = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
                       'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
                       '0','1','2','3','4','5','6','7','8','9','-','_');
        $str="";
        for($i=0; $int >= 0; $i=$i){
            $str = $chars[$int%64].$str;
            $int=floor(($int/64));
            if ($int == 0){
                break;
            }
        }
        return $str;
    }
 
    /**
     * pseudo-Base64 encoding/counting to Decimal
     */
    public static function bsf2dec($str){
        $chars = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
                       'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
                       '0','1','2','3','4','5','6','7','8','9','-','_');
        $chars = array_flip($chars);
        $int = 0;
        for($i=0;$i<strlen($str);$i++){
            $ch = $str[$i];
            if ($i==strlen($str)-1){
                $int += $chars[$ch];
            } else {
                $pow = pow(64,strlen($str)-($i+1));
                $mult = $chars[$ch];
                $int += $pow * $mult;
            }
        }    
        return $int;
    }



I also had the opportunity/need to use this in a Rails project, so I ported that same code over to Ruby:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  # Decimal to pseudo-Base64 encoding/counting
  def self.dec2bsf int
      chars = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
                     'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
                     '0','1','2','3','4','5','6','7','8','9','-','_']
      str=""
      while int > 0
          str = chars[int%64]+str;
          int=(int/64).floor
      end
      str
  end
 
  # pseudo-Base64 encoding/counting to Decimal
  def self.bsf2dec str
      return '' unless !str.nil?
      chars = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
                     'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
                     '0','1','2','3','4','5','6','7','8','9','-','_']
      int = 0;
      i = 0
      str.each_char do |ch|
          if i==str.length-1
              int += chars.index(ch)
          else
              pow = 64**(str.length-(i+1))
              mult = chars.index(ch)
              int += pow * mult;
          end
          i = i + 1
      end
      int
  end


Alrighty then. To finish this up, there are a couple of gotchas that I’ve run into, though they aren’t too major:

  1. Because “a” stands for “0″, when you are decoding these slugs, “y”, “ay”, “aay”, and so on are all the same decimal value : 24. That’s because that’s like decoding into “24″, “024″, and “0024″, which, when dealt with as ints, are all the same number. In reality, this is not a big deal b/c the encoding will never create anything starting with an “a”.
  2. Early on in using this I saw some services decide that the trailing “-” or “_” was not actually part of the URL and took it upon themselves to remove them. I haven’t seen that happen in quite a while, but consider yourself warned. If you are really worried about that, try swapping out those two characters with something you feel better with. If you do, near the end of Section 2.2 of RFC1739 the additional “safe” characters are listed.



Finally, as a disclaimer, I’ll simply say that this works. I guarantee you these routines can be optimized a good bit through some more sophisticated math.

USA Mens Basketball Gold Medal Game

Props to Spain - mostly. They got a little over chippy at the end.


Regardless, I just watched an amazing basketball game. I’m going to say - or really hoping - that Spain basically played possum in the game we beat them in by 37 a week ago. Assuming so, well played, Spain.


At the half it seemed reasonable. The 3rd qtr was a bit of a wakeup call - and shortly into the fourth the game got down to 2 - very surprising. If so, that would make sense since I decided I should start semi-logging the event when there were about 8 minutes left:


Gold Medal Game, last 8ish minutes
8:13 left - 2pt lead for US
Kobe - big shot
7:44 - Lebron James gets 4th foul
Kobe passes it up to Darron Williams… 3!
Kobe - wow - and an assist to Howard.
Kobe for 3
Awesome defensive play by the US
Lebron makes it go
Spain’s Rudy Fernandez make a hell of a 3pt play. Bad Kobe.
Kobe just screwed Pao
4:14 left … 104 - 95 US
3:30 - Wow, Marc Gasol just leveled Chris Bosh - no foul.
3:10 - Kobe for 3, AND the foul AND Spain’s Rudy is out.
Announcers are telling me all the crap I’ve been writing down.
Kobe hit the free throw - 108 - 99
Rudy & Nemenez hit, US has a turnover - 104 - 108 US
Dwayne “mohthafucking” Wade drops a 3 - 27 for him, 111 - 104 US - 1:58
- Spain Timeout : The Final Countdown is playing coming out of it.
1:53 - Kobe gets his 4th foul…
1:20 - Spain has 11 more rebounds that US
Kobe makes *another* key shot - 113 - 105 US
Whoops, Spain - an Unsportsmanlike & Technical on one play… that Kobe gets to shoot? Dudes.
Golden. Props to Spain - seriously - except all that bs at the end. 118 - 107 US


Good. Way to get back there. Can we try to keep this up?


Also, 42 thumbs up to the women’s team for beating the living daylight’s out of everyone… again…


Ok, so NBC showed a collagey segment that was sweet… but then they showed a couple Winter Olympic clips… wtf?


Also, this: http://twitter.com/jessedp/statuses/897153307


I woke up this morning and….

And these words were in my my head. I have some ideas why, but guessing at that would be like telling you I can interpret my own dreams.

Anywho, here they are:

May I lay down with you
and fall asleep each night

I want to wake up shaken
and have you in my sight

I need to rise each morning
and hold you close and tight

I must have you with me now, please,
will you come in to my light?



Obviously I polished them up, but that was pretty much it. Kinda pretty(?), too.

And now they will likely torture me for the rest of the day :)

Two Months Later…

Had I planned to keep this updated, this has likely been a tad longer than I would have expected myself to get things done in. I didn’t, though, so….

I don’t know how it is for the rest of you, but I usually have a few things that I’m actually generally concentrating on over the course of some weeks and possibly months. Recently those things have been “new music” and “pulling my shit together”.

“new music” is relative to me.That means, newer/ish to me and certainly doesn’t imply any sort of typical time period. If you’ve never noticed, my time & times are … often different.

“pulling my shit together”  is more or less getting my house in order by semi-normal and then my standards. I wouldn’t say that’s any more special than not wanting my house to harm, collapse on or under, or otherwise maim someone - yes, previous ones have. Anything after that is gravy. More on that crap later.

Right now, the music is making me the happiest. While I don’t keep up with much of anything, I know some awesome people that do. Most specifically it’s the folks at Ohmpark and From Exile, and certainly that stupid picture site. And yes, you others too.

The past few days I’ve been working on fixing all the artist, title, and sometimes album/track num/disc num on all my tracks, a lot of which had many issues. I had a progam in the past that was incredibly helpful with setting all sorts of tags using path/file name patterns, but had no reference for it and quicly found a free windows program called Mp3Tag .. and it runs fine under wine ( mostly :) ).

Back to the point - in failing to completely remove & re-add everything and all the corrected info to my ipod, I managed to be late to work and have an empty ipod this morning. I added some safety staples - Smashing Pumpkins, Morphine, STP - and then tried out a bunch of new things I never loaded but had (I’m an idiot - end of story). And the actual point - the “new” things I listened to today were:

Yo La Tengo - I enjoyed the hell out of both albums I listened to and am looking forward to any others I get hold of.

Mastodon - I listened to “Call of the Mastodon” and “Blood Mountain”. I was pretty pleased with both, “Blood Mountain” more, though, I believe.

Sigur Ros - I enjoyed the two albums I listened to a lot. They ended up playing during some real good, solid work time today, so  I don’t remember distinctly, but they obviously pleased me.

Of Montreal - Honestly, I was disappointed with what I listened to - it was their “The Sunlandic Twins” album. I’d swear I’ve heard their stuff before and liked it a lot. I have 2 others I’ll check out, though. Ok, here’s the thing… the song “Wraith Pinned to the Mist and Other Games” sounds like they ripped it off from a fucking Outback commercial. Maybe I just have to put that out of my mind and try again.

Hopefully I also influenced someone’s “music life” today. This finally clicked a couple weeks ago, and I got around to it tonight (see the time comment above). There is a waitress at the bar named Sheila. I love Morphine, so I know they have a song named Sheila about her & her cat. So I asked if she knew of any of that - she didn’t, but was interested… I told her it was jazzy-ish rock w/ a good bit of bass - that should be close enough.  So hopefully there’s a new Morphine fan - I may just burn her “Cure for Pain” and force the `issue`. And if so, hopefully she’s not as upset as I was when I finally realized that Mark Sandman was dead and I would never see them or hear anything new.

eh.

Hooray for Pinball

In the past year and a half or so I’ve become reacquainted with and obsessed with pinball. The game that got me back in was Stern Pinball’s Family Guy game. Stewie Pinball is awesome, and I generally loved the layout of the ramps, etc. In contrast, Stern’s Pirates of the Caribbean was also around, and I didn’t like it at all.

Any who, a few weeks ago they both went away - it was kind of a sad moment. However, Stern’s Shrek game was put in to replace them. While Shrek is not nearly amusing as Family Guy, especially the constant playing of the Smash Mouth “All Star” song, it is laid out exactly like Family Guy.

So, knowing everything in the game is a leg up - then, the game is just more generous : points seem larger, the ball saver (then Death, now Pinocchio) seems to stay up longer and it is certainly easier to maintain it, and the multi-balls seem to come more frequently. Put all that together and I can score WAY higher on Shrek. For example, before tonight, my highest score on Family Guy was approx. 79 million - on Shrek, 198 million … that beat 196 mil., and man was I irritated that I didn’t bust 200 mil. on that game.

Back to tonight - the first game I played was golden. It took me around half an hour for four balls totals (I earned my only extra on the 1st ball). Around the end of the 1st ball’s extra ball, I had approx. 203 mil.:

203 million on 1st ball
and here

I “dropped the ball” on the 2nd ball, then finished off wonderfully on my 3rd ball. Final score…

393 million, bitches!
also here
That turned out to be approx.:

  • 1a) 168M
  • 1b) 35M
  • 2) 10M
  • 3) 126M

And I titled on 1a & 3 b/c the balls got stuck…. both of those were during Donkey (Stewie) Pinball - yes, I actually finished it a 2nd time, one letter at a time…


I’ll be amazed if I get anywhere near that again.

Rails - Know your models

I’ve been trying to upgrade a Rails app that worked on 1.2.6 to 2.0.2 for what seems like ever know. Granted what I mean by “working on” is that I’d spend at most an hour or so trying to tracking down exactly what was causing the one same error that I was getting anywhere I tested

ActionView::TemplateError valid? is defined by ActiveRecord


My assumption the whole time had been that it had to be a plugin, gem, some patching, or something we had defined screwy in our models that was not compatible with Rails 2. Really, it had to be - that covers the whole freakin’ app, so it should have been easy to find, right? Not for me. Seriously, I got this error for the 1st time at least 2 months ago. Luckily moving to Rails 2 wasn’t really a priority :)


Anywho, today I finally tracked down the problem. We had a field named “valid” in our model. Rails 1.2.6 didn’t give a crap about that - at all, ever. Turns out I’d overlooked the ONE time the field is looked at ever in the code this whole time. Once it intrigued me today, I started poking around - once I looked at our migrations, I finally realized that that was exactly what was conflicting here.


A quick migration to rename the column, a change to the one place it’s used, and voila! the app is running in Rails 2.


That was bullshit.

What happens when I need to post code & want it’s syntax highlighted?

I install WP-Syntax and go to town is what! It uses GeSHI, which I’ve heard of but never used - piece of cake to use!


In fact, here’s a little of example straight from the curl_setopt page in the php manual

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
// create a new cURL resource
$ch = curl_init();
 
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, false);
 
// grab URL and pass it to the browser
curl_exec($ch);
 
// close cURL resource, and free up system resources
curl_close($ch);
?>

Welcome

First - do not expect anything. I really can’t emphasize that enough. If I don’t delete this in a few days, I’ll probably be referencing the very first thing I posted (this) often.

This ridiculousness started from one of my regularly inane comments about nothing after I had a salmon blt (it was good and from here) - you can see the whole thread here. Since you are probably a lazy bastard like me, this is it:

jesse said this 2 days ago

Bacon is NOT poison. It is like the bread of life… except it’s bacon. It is, in fact, the bacon of life. The life giving, self-referential, recursively defining source of all that is and will ever be. Period.


That was followed up by a statement I made in a conversation later, shortly after I registered thebaconoflife.com and had no idea what to do with it -

them: it could be a recipe site
have you ever had that fancy appetizer that’s dates wrapped in bacon? OMG.. awesome
me: no, but I’ve had filet mignon wrapped in bacon, and that is awesome. :)
really, you just can’t go wrong wrapping things in bacon.


Really, you can’t.

And with that, I’ll send you to the 1.25 lb bacon sandwich that some genius created. I also imagine that will be the 1st and last link about bacon. Maybe I’ll be wrong.

I am constantly looking at random things on our internets and like to force them on others to enjoy:

sketch is a neat little site where you can draw a very basic image (black “ink” only) , then swap it with someone else. Since this is the internet, you will see cuss words, balls, boobs, and other generally useless picures amongst the great things that some people will send across… here are some screen shots I took playing with it a night or two ago…