Not quite what we were looking to come back to after the football game… thank heavens we still had our mini fridge sitting here, or this would be a rather unfun week.
But it is an ending…
The Wheel of Time turns, and Ages come and pass, leaving memories that become legend.
Rest in peace, Robert Jordan.
Updates
I’ve finally decided to change themes on this here blog. I’m now using a theme called “Redoable”, by Dean J Robinson.
I like it better than the last theme I had, though this one seems to be fighting with some of my plugins, such as the syntax highlighter and SmartBox, so it needs some tweaking or something. It’s also a bit heavier than my last theme, so I’m still evaluating that as well.
Thoughts, ideas, comments in general?
Did that ref just say "disconcerting"?
Subtitled: Is disconcerting even in the vocabulary of the average NCAA viewer?
Apparently it ought to be, since it truly is the rule:
From Rule 7-1-5-a-3 (pg 98): [Note: 1.6M PDF]
No player shall use words or signals that disconcert opponents when they are preparing to put the ball in play. No player may call defensive signals that simulate the sound or cadence of (or otherwise interfere with) offensive starting signals. An official shall sound his whistle immediately.
Learning to Read…
(Walk to class)
(Sit down, open laptop)
(Watch and smile as automatic location detection by MarcoPolo determines that you’re now on Campus, and calls your PERL script to automatically authenticate with the captive portal)
(Smile more as Adium establishes connections and brings your IM online. The script worked!)
(Pull up calendar, news reader, and SVN repo config page)
(Grab notebook from backpack absently)
(Create a new repo to start storing your home directory in: long past due to back up some things)
Anonymous classmate: “Do you think this was the lecture he said was canceled?”
(Look up, confused. There are 3 minutes to class time, and only maybe 10-12 people in the room, instead of 50ish)
All: “What?”
(…)
(Pull up course homepage, note news item: “Reminder: There will be no class tomorrow, September 13.”)
(sad face)
(inform the next 6 people who walk into the room of the news… chuckle over collective mistake)
(go home early 🙂 )
Why are all my LWP POST requests returning status 302?
Quick tip for PERL users:
LWP does not redirect on POST requests by default. If you are trying to POST to a page which replies with a redirect, e.g., authenticating with a webform or somesuch, you need to enable redirects via this line:
push @{ $ua->requests_redirectable }, ‘POST’;
You can also do this by hand, ala:
$resp = $ua->post(…);
if ($resp->is_redirect) {
$resp = $ua->get($resp->header(“Location”));
}
Originally found via: this news post
Aftermath
The only word for last night: Quagmire.
[Update: 8/26/07 16:15]: “You have to wait here. We’re sending the cars up one-by-one when they say they’re ready. We’re going to have you get up some speed, and do not stop until you get completely into your parking space. They’re already getting tired of pushing…”
Not going anywhere for a while…
So last summer I got stranded in Auburn, WA after the Goo Dolls – Counting Crows concert and needed my roomate to come rescue me. I thought that was the longest it had ever taken me to get home from a concert. Until Rage Against the Machine at Alpine Valley, that is. We are now waiting in what can only be described as a mud pond. Picture about 40,000 people trying to move their cars out of a parking lot. Now replace the parking lot with a flooded field. And make all the people drunk. That’s about what we’re at… Oh, and the cars around us haven’t even moved in like 40 minutes. 🙂 See you in the morning?
'No Room'
Playing with PERL
Warning: The following content is of a ridiculously nerdy nature, and probably unsuited for most of the viewing audience. That said, I had a lot of fun writing it, so here it is 🙂
My roommate Dave IMed me the other day with a problem: He needed a program in 30 minutes that would search through a text file for any occurrences of a list of CAPITALIZED words, and convert them to lowercase, wherever they occurred.
I received his message 20 minutes later, set to work, and in the last 9 minutes, developed a script for him, along with an extensive test case. PERL, of course, was born to solve this problem.
Here’s the the test case I made up, and the correct output, to get an idea of what I needed to do:
input.txt
There once was a Chicken named EGgS.
It lived STRINGS in a barn.
The CHICKEN was afraid of EGGSNITCHERS.
Chicken likes Eggs served on STRINGS
output.txt
There once was a chicken named eggs.
It lived strings in a barn.
The chicken was afraid of EGGSNITCHERS.
chicken likes eggs served on strings
(I later realized this missed one rather important case… BUG: see if you can figure out what it is, and what the error in the first three drafts below is)
Here’s the first draft, which works (nearly…see bug note above) correctly and was submitted within the prescribed 30 minutes :-):
munge1.pl
#!/usr/bin/env perl
use strict;
my @patterns = (
"chicken",
"eggS",
"strings"
);
# Make sure user used lowercase
map { tr/[A-Z]/[a-z]/; } @patterns;
my $input_file = $ARGV[0] or die "Usage: go.pl n";
open (FH, $input_file) or die "Could not read from file: $input_filen";
while (my $line = ) {
foreach (@patterns) {
$line =~ s/^$_(W)/$_$1/i;
$line =~ s/(W)$_$/$1$_/i;
$line =~ s/(W)$_(W)/$1$_$2/i;
}
print $line;
}
close FH;
exit 0;
But then I thought to myself… “Self, this is PERL. Surely there is a shorter way?”
Removing some “useless” error-checking and file parsing code in favor of a shell-out, I came up with this:
munge2.pl
#!/usr/bin/env perl
my @patterns = (
"chicken",
"eggS",
"strings"
);
map { tr/[A-Z]/[a-z]/; } @patterns;
map {
foreach $a (@patterns) {
s/^$a(W)/$a$1/i;
s/(W)$a$/$1$a/i;
s/(W)$a(W)/$1$a$2/i;
}
print;
} `cat $ARGV[0]`;
Better, shorter, PERL-ier 🙂
But still not really PERL. I mean, come on. There were 3 entire statements there. Laaame.
So I played a bit, and moved the first map around to compact two statements into one (admittedly, the map is just there to make sure the user’s list of TERMS to lowercase is *actually* lowercase, but I wanted to keep that bit of functionality):
munge3.pl
map { tr/[A-Z]/[a-z]/; } (@patterns = ("chicken","eggS","strings"));
map { foreach $a (@patterns) { s/^$a(W)/$a$1/i; s/(W)$a$/$1$a/i; s/(W)$a(W)/$1$a$2/i; } print; } `cat $ARGV[0]`;
Nice. But still not PERL-y. 😉
Then it hit me: why am I wasting an entire statement to create an array that I will only use in one other statement? Oh, and while we’re at it, let’s cut those 3 regexps down to 1, courtesy of a good insight from Jason. (Use b and B to match word boundaries.) AND, in a throw-back to my early days of escaping URL strings in CGI (like: s/(W)/sprintf("%%%02x",ord($1))/eg
) let’s move the lowercase-ifying inside the regexp as well, eliminating the first map altogether.
munge.pl
map { foreach $b("chicken","eggS","strings"){s/b$bB/lc $b/ieg;} print;} `cat $ARGV[0]`;
Ahhh… that is PERL :-). One line of file-munging goodness. Use only as directed:
/usr/bin/env perl munge.pl input.txt > output.txt
Note: I know this is not good coding practice, it was just fun to reduce to as short of a program as possible. And there’s something to be said for brevity, as well. (… is the soul of wit…)
If you’re concerned about the error-checking of said code, tack this on the end 😀
or die “Caught teh 3rrorz!!1”; # 😉