Scott sent me this link tonight, and it couldn’t be any more true 🙂
Category Archives: Uncategorized
3pm: Passed out on couch. Please do not rouse until tomorrow.
Week-in-Review:
- Sunday
- Excellent chicken parmesan with Stef & Dave
- Monday
- Homework during day, Halo 3 launch at midnight. Played until 7am
- Tuesday
- Sleep 7am to 10am, class 11am to 3pm, short nap, Enlight meeting, 4 more hours of Halo, 2 hrs of Algorithms homework
- Wednesday
- Sleep 2am to ?, class, compilers HW, make a calendar merging program to display my life on the web: my calendar, Algorithms HW 3:30p-5:30p, supper, Algorithms HW 6:30p-3:45a.
- Thursday
- Sleep 4a-8a, Algorithms HW 8a-11a, class, Algorithms HW 12p-1p, class, handin (!) Algorithms HW, Google tech talk, Grab sub on the way to work on compiler project, Hang out w/ Dave & Stef (thank heavens, or i’d have gone insane), then do DSP HW 11p-3a
- Friday
- Sleep 3a-9a, Dave wakes me up cuz i told him i wanted to go to the prof’s OH, do that, finish 431 assignment by class at 11, then finish compiler project 12-1:30p, another Google tech talk, Write blog post, Pass out.
Peace.
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
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”; # 😉
Flying First Class
It took me 5 hours to get to work today
1: Wake up in Portland, OR, 4:05am
2: Drive to the airport parking lot
3: Take the shuttle bus to the airport proper
4: Breakfast in the line to check in / outside the security checkpoint. Jeni recommends not drinking the coffee. Do it anyways for the caffeine. It wasn’t as bad as she said, but it wasn’t good, either 🙂 Muffin was good.
5: Arrive at gate to discover that you have been upgraded from boarding group C: “Steerage” to boarding group B: “People who have a slight chance of a preferred seat if they sit in the back of the plane”. I got a window, it was sweet.
6: Fly to San Jose, finishing book “Sphere”, and listening to 88-year-old first-generation Italian American woman tell me the story of her family. Twice. She was interesting to listen to though. I hope I am as active when I reach 88, though preferably with either a better short-term memory or someone with as poor a short-term memory as me to talk with…
7: Arrive San Jose airport, traverse to “Ground Transportation”
8: Get on the 10 to Santa Clara Caltrain. Be instantly reminded of everything you dislike about California, all rolled into one girl yelling into her cellphone:
It’s my birthday in 5 months.
(Pause)
It’s my birthday in 5 months.
Oh my god, I’m going to be 19. Ewww.
(Remainder of conversation deleted due to inability to filter intelligible discourse from the expletives.)
9: Transfer to the 60. Save $1.75 because the coin machine is jammed.
10: Disembark at Scott & Walsh. Walk to work.
11: Wish it were still Portland