Archive for the 'Computers' Category

double frick!

Copy and paste the following code into the address bar of your browser, and press enter:

javascript:if (.2 + .4 == .6) alert("frick!"); else alert("double frick!");

The code basically says, “If .2 + .4 is equal to .6, then pop up a window with the message, ‘frick!,’ otherwise, pop up a window with the message, ‘double frick!’” I didn’t learn this until yesterday, but the problem is that floating-point data types don’t always store exact values, but approximations of them, so the “wrong” pop up appears.

MS Works is no fun

I just spent my weekend fixing my sister-in-law’s computer; it had a virus so I spent the time backing up non-executables so I could do the notorious format and reinstall. That is, her photos, iTunes music and movies, and any other documents I could find.

Of the text documents, she had a surprising number of open document text (odt) files, which I was happy to see, but then I noticed a bunch of files with a wps extension. I originally thought WordPerfect, but when I tried to open them in OpenOffice, they ended up blank, which I could tell was wrong from opening them in notepad.

After a quick search, I found they were Microsoft Works documents, which are not importable in OpenOffice (or even MS Word by default) or convertible using any standalone converter. Long story short, I had to install Microsoft Word Viewer 2003, then install the Microsoft Works 6.0 to Word converter, open them in the viewer, then copy and paste the text into OpenOffice so I could then save them in odt format (after some crappy text manipulation). Not very fun, but it was the fastest, free way to get her documents back to her without installing Works again.

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.

election day is almost here…

Well, it will be election day in a week ago.

I realize this is such a timely entry, but I still wanted to post it. I decided to vote for my last time in Utah (unless I decide to move back, which is entirely possible given the right financial situation); I will be losing my status as a Utah resident well before election time comes around again. And I fully intend to vote here in Arizona when it does.

From the previous paragraph, you can safely assume that my house, wife, and kids are still in Utah. I’ve just received two callers interested in buying our town house, and unfortunately for the current real estate market, had to assure them that my asking price was negotiable. In any case, I hope one of them decides to call back to make an appointment to see it (and, of course, buy it).

While I’m sure my family life is incredibly interesting, I’m sorry to inform you that this entry will more likely cover a topic from the title, probably elections.

It appears that Utah’s billion year incumbent, Orrin Hatch has been re-elected to the U.S. Senate. I tried to get my family and friends to vote for the candidate running against him, Pete Ashdown, but it appears it was too little, too late; hopefully in 6 years, Mr. Ashdown can make himself well-known enough to get our (well, Utah’s, not mine anymore) incumbent out of office.

My wife mentioned that Utahans likely feel that he is getting things done, and I really do hope that is the case, but he has made a comment before that I very much disagreed with. This news is incredibly old, but it’s the reason I looked for another candidate in the first place: Hatch made a statement a couple years ago (long enough ago not to have affected the election enough to lose) that some sort of technology should be invented to destroy the computers of those committing copyright infringement (specifically, downloading movies, music, or other media online without consent of the copyright holder). While the topic of copyright is a large enough topic for 50 trillion more entries, I’ll try to stay focused on why I chose to vote against Hatch.

There are many of Hatch’s policies that I agree with, a few including: allowing media to be edited (specifically, removing offensive content) for resale, stem cell research, tax cuts, and tax reform. Hatch claims to be pro-Constitutional, which I assume is a conservative view that the government only holds the rights specifically given to it by the people, and no more. Unfortunately, his comments about destroying a person’s property without being proven guilty doesn’t seem to fall in line with ”due process” of the fourth amendment. Even though he eventually retracted those comments, it still seems as though he temporarily set aside the fact that this government is required to assume innocence until proven otherwise.

Don’t get me wrong, if probable cause of copyright infringement can be shown, I have no problem with the courts issuing a warrant to determine if any infringement has actually happened (including the confiscation of the property in question, but not the desctruction or permanent confiscation before a guilty verdict).

I don’t really like the use of the word probable, as most people understand it today. Probable cause means that you have pretty damn convincing evidence showing this person committed the crime (fortunately, many judges do still understand this); and not that they “probably” (id est, “might have”) committed the crime.

And the biggest reason I chose to vote for Pete Ashdown, is because he truly listens to the people (or at least does a pretty dang convincing job of it). On his own website he encourages communication on issues by the community (using a wiki), and when he feels they have reached a good conclusion, makes it part of his official policy. The great thing is that these policies are contributed by the people, not just solutions Ashdown has come up with off the top of his head. Because I also agree with the majority of Ashdown’s policies, he was the perfect candidate for me to choose.

However, I do strongly believe that people make mistakes they regret, and are completely entitled to change their opinion, even on extemely important issues; new information can completely change the circumstances on which you may have previously based your former opinion. Since Orrin Hatch is now Intellectual Property Subcommittee Chairman, I sincerely hope he realizes the error, and works towards intellectual property reform that will protect the consumers as strongly as the copyright holders. I would really still like the ability to “own” a book, movie, game, or song (id est, all art); I don’t want to end up in a world where art can only be “rented” (aka, licensed) by consumers.