Archive for the ‘shared-idoicy’ Category

232792560

Saturday, January 19th, 2008

I recently stumbled on Project Euler, a series of various mathematical/programming challenges. A lot of them can be solved quite easily in Perl, such a problem 5:

What is the smallest number divisible by each of the numbers 1 to 20?

I’m sure there’s a more elegant solution, but I figured, heck that’d be easy to brute force. So I whipped up a few lines of Perl. Here’s my first pass:


#!/usr/bin/perl -w

use strict;

my $value = 0;
my @divsors = reverse(2 .. 20);

EULER: while (1) {
$value += 20;
print “$value…\n” unless ($value % 1000000);

for my $i (@divsors) {
next EULER if ($value % $i);
}

last;
}

Anything like while(1) always makes me worry about an infinite loop, so I threw in the status line & watched it.

Happily, there was no infinite loop & it terminated.

0.0001 seconds later I realized what an idiot I was.

The programs goes through all the hard work of figuring out the value and then… well, nothing.

I forgot to add a line to print it out the final value.

So, in a nutshell, my first attempt worked — all the heavy lifting bits were correct — but it was worth naught as I overlooked a trivial bit.

Sadly, this is apt microcosm of my life.

The truth about editor.singleLine.pasteNewlines

Sunday, February 18th, 2007

A while back, some where on the great wide Internet, I remembered reading about Firefox’s editor.singleLine.pasteNewlines setting. The advice was how to tweak it, so that if you ever had a long URL with line-breaks in the middle, e.g.:

You could just copy both lines, paste into Firefox, and the right thing would happen.

I.e., you’d get a working:

instead of a truncated

This happens a lot with long URLs in email, so sounds pretty handy, right?

I don’t remember where, but I distinctly remember reading the number value you set for it was the maximum number of line-breaks it would trim. The article recommended setting it to 3, so you’d get rid of up to 3 line-breaks.

Why 3, I wondered. Why not 4? If 3 is good, obviously 4 would be better!

This is America, baby! We go big!

So, being an American, I set mine to 4.

And it never worked.

Well it sorta did. It did remove the newlines. Only it replaced them with commas.

WTF!?!

Now, don’t get me wrong. I have nothing against commas. I like conjunctions, strings of adjectives, and prepositional phrases as much as the next guy. I just don’t like them in my URLs.

I was also a little confused about why people thought this setting was so great. After all, it clearly didn’t work. Yet, I would see it again and again and again in blog posts.

I figured it was one of two things: Either I had seriously whacked my install of Firefox somehow (which, as an Extension junkie, was quite possible) or there was a secret mass collusion out there & the entire Internet was fucking with me. I figured it was mostly the former, but I had to admit, there where times I thought it was the latter.

Anyway, bored, surfing the Internet & watching TV, I thought I’d look the setting up. So I did.

http://kb.mozillazine.org/About:config_entries

editor. singleLine. pasteNewlines
Determines the behavior when pasting content containing newlines into single-line text boxes.
0 (default in Linux): Paste content intact (include newlines)
1 (default everywhere else): Paste the content only up to (but not including) the first newline
2: Replace each newline with a space
3: Remove all newlines from content
4: Substitute commas for newlines in text box

Now, it seems to me that 3 would be the most logical default everywhere. After all, in 99% of the cases, that’s probably what the user wants to do.

I can understand 0 & 1. Well, not really. But I’ve been in enough geek flamewars to know the type of idoit logic that could result in them being seen as the preferable solution. Here I would imagine the argument to being it’s more important to do what the user literally stated (an invalid url with newlines) than what the probably meant (a valid url without newlines).

What I can’t see is how anyone ever made a case for option 4. The thing here is Firefox is open source. So not only did someone think it was a good idea, they managed to convince someone else it was a good idea too.

What I want to know is how that conversation went down.

“Listen boss, I’ve been thinking about this pasteNewlines thing.”

“Yeah?”

“Well, so far we options 0-3. But it was bugging me last night. We’re missing something. Then this morning, while taking a shower, I realized what it was.”

“Oh?”

“Commas.”

“Commas?”

“Commas. Instead of just providing variations on newlines, we should let the user have an option to replace them with commas.”

“Commas. I see it now. My boy, you’re a genius. Get this patch on the trunk asap!”

“Right away, sir!” Scurrying back to his desk.

“Checkmate, Mr. Gates. Checkmate, indeed.”

So, fine. I’m an idiot for not having used 3 like everyone else on the planet, but whoever came up with an option 4, you’re just as retarded as me.