Archive for the 'Garbage' Category

stumped

Okay, so I was reading through some old code of another programmer at my job a few weeks ago, and noticed something like this:

while (true)
{

//… some code here …
break;

}

I just shrugged it off, simply thinking he must have been on drugs when it was written, but then I noticed that he had used the exact same code in a project we are currently working on. For those not familiar with programming, the “while (true)” means keep doing the stuff inside the curly braces over and over, while the “break;” means to go ahead and stop repeating anything and go on to the next part of the program after the curly braces. I have tried to figure out what possible reason a while (true) statement with a break at the end would ever be useful, but it has me completely stumped. So either I’m not very bright, or I need to report a coworker for substance abuse.

regular expression lookaheads and IE

Okay, so I’m writing two computer related articles in a row, but I’ve been meaning to post this for a while now.

Anyway, a few weeks ago, we needed a regular expression for customer passwords. After searching Regular Expression Library, we found one that looked like it would work, and modified it to the following:

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[0-z]{7,12}$

Normally, that would require the password to contain one small letter, one capital letter, one number, and be between 7 and 12 characters, inclusive. So we tested it, and it worked just as expected.
A couple days later, another programmer in our group told us it didn’t work, so we tested it again with perfect results. After arguing with him for about 1 to 2 seconds, we asked if he was using Firefox or Internet Explorer - he was using IE.

After a couple more days of research, I discovered that IE doesn’t necessarily parse lookaheads properly. Here’s what seems to be happening:

  1. The carot ^ is successfully matched, and because it is a zero-width search, the search position remains at position 0 (before the first character of the password; this is expected behavior)
  2. The first lookahead (?=.*[a-z]) looks ahead until it finds a lower case letter, if one is not found, the regular expression fails; however, if one IS found, IE decides to jump straight to the next part of the search that is NOT one of the lookaheads. That is, it checks that the lower case letter is followed by at least 7 to 12 characters
  3. If that succeeds, then it does the same thing with the next two lookaheads
  4. If all the lookaheads succeed, then the final check must pass; that is, the password can only be 7 to 12 characters long

Trying to put this simply, basically a small case letter, an upper case letter, and a number must all appear within the first 5 characters, followed by, at minimum, 7 more characters. So the password would only ever pass with a minimum of 10 characters (e.g. A0a1234567). And even with 10 characters, if one of the 3 lookaheads didn’t match right at the beginning, the entire regular expression would fail (e.g. aBc1234567 would still fail, since one of the numbers doesn’t have 7 more characters after it).

But being the freakin’ genius I am, I finally figured out a solution that worked in IE and Firefox:

(?=^.{7,12}$)(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[0-z]*$

Basically, this checks the length right from the start, if it’s not between 7 and 12 characters, it immediately fails; the other lookaheads now don’t care how many characters follow, they just care that the lower case letter, upper case letter, and number appear somewhere in the password at least once. The last part [0-z] simply makes sure that no weird characters are entered: just letters, numbers, and some limited punctuation.

would you believe?

Okay, that was pretty cliché, but I just recently found out that they have decided to cast Anne Hathaway as agent 99 in the new Get Smart movie, which is freaking awesome and Anne-tastic. I already knew that they were planning on having Steve Carrell play the part of Max, and while he is a perfect candidate for the part, he just isn’t hot enough (at least to me) to have prompted me to write a journal entry.

Checking around for a little more details about the movie, I came across The Get Smart Page. It is a poorly designed site, but has a lot of information (good and bad) about the show. It appears the site’s maintainer has obtained a copy of the movie script, and is unhappy with it. From what I can tell, his biggest problem with the new movie is that they’ve taken Max, who in the old series was a confident, bumbling fool, and turned him into an insecure, bumbling fool. Hopefully the movie turns out much better than he has interpreted from the script.

And back to some more exciting news: Time Life will be releasing the full original series on DVD soon. Get Smart is possibly one of the greatest comedies of all time; though, I would say it’s hard for me to decide between it and Scrubs. In fact, I’m almost as excited now as I was when I heard Scrubs was being released to DVD. I’ll just have to start saving now so I can afford to buy it.

they’re coming

I know some of you just couldn’t bear the anticipation, and while I know I could have just edited my old post to add this, it was simply too important to just go back and change — my Heelys have shipped and will be here by December 13th!

better than…

I was just testing the password-protection capabilities of this wordpress software. It’s interesting, it uses a permanent cookie to remember the password, so if you’re on a public computer, I wouldn’t recommend reading any password-protected posts unless you remember to clear the cookies afterwards. Anyway, nothing in here about sex yet.

good garbage!

I finally decided to start an online journal; I call it an online journal, because for some reason I just can’t bring myself to call it a blog or weblog. It’s not that I have a problem with conforming, just that I only like to conform when I want.

Anyway (or, anyways, for my friend Dane), I decided to use Wordpress, which wasn’t too difficult to set up and use, though it still took me a quarter of a day to get it the way I want. I got the idea to use Wordpress from Jared Ferguson, who I’d consider a pretty good friend (hopefully that feeling is reciprocal).

I also stole his idea to use the K2 theme, which he updated yesterday to 0.9.1; after seeing how gracefully it pages his articles (the “rolling archives”), I have to say that I like it more than a lot.

It’s getting late, so I’ll write down the rest of my thoughts later. Until then, ta.