BeanQuest

July 30, 2006

Blogathon Cheating

Filed under: perl, pointlessness, web-ish stuff — Brian @ 11:35 am

Update: Sweet. I won the first ever “George Washington ‘I Cannot Tell A Lie, I Hacked Your Contest‘ Script Kiddie Special Achievement Award for Outstanding Accomplishment of Incredibly Trivial Ends”. Perl rox0rs.

When Eric announced that there would be a prize for the person who could provide the longest list of sequential header images from his blog during Blogathon, I immediately thought, “cool – I could automate that!” And then, almost as immediately thought, “hey – that would be cheating,” followed by “well, I’ll just disqualify myself. This will be too much fun to pass up.”

So, the night before the Blogathon began, I made sure to have the latest version of WWW::Mechanize (a Perl module from the always friendly and generous Andy Lester) and set about writing a script that I could quickly modify to read the actual HTML Eric would use during the Blogathon. I figured I’d just grab the first image in the HTML, and that would probably cover it. Before the Blogothon began, this did, indeed, grab his masthead image. Confidence was high.

In the morning, when it all began, I found that my script was getting an image, but not the one I wanted. It was getting an image from the first post in the page.

Turns out, Eric pulled a switcharoo, and was placing the header image with CSS, not HTML. The script I wrote parses HTML just fine, but doesn’t care much for CSS. Uh-oh.

Fortunately, he was loading the image from a static location, and making the hourly switch by replacing the image file with a different one, using the same name. Well. That makes it too easy – it’s just a call to a single, unchanging URL; every hour, the image there will be different. So I threw away my script and replaced with this:

wget  http://www.ericsiegmund.com/fireant/images/blogathon2006/bg.jpg

Run that every hour via cron, and I’ll have my collection of images, to sort through at my leisure.

Now that I had it working, I e-mailed Eric to explain my scheme and recuse myself from the competition, confident that if this isn’t cheating, I don’t know what is.

After a few hours (OK, maybe ten hours) of quietly retrieving the images, I went to look at the folder. There was the first one, which I’d saved manually, then the second, which the script got. Then about ten more. Those ten were all copies of the second one; I had a collection of Texans in Hatchbacks! The same Texan in the same hatchback, every time.

Not what I was looking for.

Now, I’d had no reply to my e-mail. I figured Eric was too busy live-blogging from the HEB to read it. (The HEB is a grocery store, but it’s apparently quite a grocery store, as they allow blogging and gaget hackery to take place inside.) Apparently not. I’m guessing he got it, and figured he’d mess with me. Since I had kind of started it, this was entirely appropriate, and a welcome surprise!

So, I dug out the original script, and tweaked it to make it more Eric-proof. The new version (a) gets the blog’s index page, (b) finds the URL of the stylesheet it uses, (c) gets the stylesheet, (d) gets the URL of the image used for the background of the CSS ‘header’ div, and (e) gets the image itself, saved with a timestamp (f) once per hour, scheduled with cron. Oh, and it uses a Safari identification string (user-agent), so it wouldn’t call attention to itself with a casual look through the server logs, should Eric decide to look.

And I left the other one running, so it *did* show up in the server logs – this way, it’s not obvious that I changed anything.

I wrote it as the last thing before going to bed (yes, I’d ignored the output of the original attempt for far too long. It was a Saturday! A day of rest! It looked fine on the surface!), so it’s a little wordy, and a bit messy in places.

But it was a great exercise in writing a more resilient approach, and in writing regular expressions (that’s the part that looks like gibberish, with the slashes and splats and brackets and parens). And, more importantly, it worked all night as I slept!

Here’s the Perl:

#!/usr/bin/perl
use strict;
use warnings;

use WWW::Mechanize;

# create a mech that calls itself "Safari", so we aren't obvious in server logs
my $mech	= WWW::Mechanize->new( agent => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X;'
.  'de-de) AppleWebKit/125.5.7 (KHTML, like Gecko) Safari/125.12' );
my $now 	= timestamp();
# default bg image url
my $bg_url 	= 'http://www.ericsiegmund.com/fireant/bg.jpg';
# url to start on
my $url 	= 'http://www.ericsiegmund.com/fireant/';
# name to store image under
my $bg_file = 'bg' . timestamp() . '.jpg';


$mech->get( $url );
my $page = $mech->content();

# In the content of $url, get the stylesheet's URL:
# Look for 
#
my ($css) = $page =~ /link\s+rel\s*=\s*['"]?stylesheet['"]?\s+href\s*=\s*['"]?([^'"]+)/is;


# get the stylesheet, store the whole thing as a string in $sheet
# and split it up into individual lines, one per element of the @sheet array
#
$mech->get($css);
my $sheet = $mech->content();
my @sheet = split/\n/, $sheet;

foreach (@sheet){		# go through the lines of the stylesheet, one by one.
# We're looking for something like this:
# #header   { 
#	background: #[[variable color]] url([[grab this part]]) no-repeat top right;
#	border-bottom: 1px gray solid;
#	width: 100%; 
#	height: 150px; 
#	text-align: center; 
#	}

	if( /#header[\s{]+/ .. m|}| ){	# only look while we're in the '#header' section
		# (below) look for a line that contains 'background' and a URL.
		# that URL is where we can find the image
		if( $_ =~ m|background[^(]+(http://www\.ericsiegmund\.com/.+)|i ){
			$bg_url = $1;	# $1 is what we found in the parens, above
							# that is, the URL of the background image
		}
	}
}

# get the image, and store it in the file whose name we made up at the start
$mech->get( $bg_url, ":content_file" => $bg_file );

# script ends here - below is just the timestamp routine, used to create the filename
sub timestamp{
	my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
# never can remember the order of those things.
# sloppy copy & paste, yes...
	$year 	= $year + 1900;
	$mon 	= sprintf("%2.2d", $mon + 1);
	$mday 	= sprintf("%2.2d", $mday);
	$hour 	= sprintf("%2.2d", $hour);
	$min 	= sprintf("%2.2d", $min);
	$sec 	= sprintf("%2.2d", $sec);

	return $year . $mon . $mday . '_' . $hour . $min . $sec;

}

July 29, 2006

Blogathon 2006

Filed under: whatever — Brian @ 10:56 am

It’s more like “comment-a-thon” for me. I’m hanging around The Fire Ant Gazette mostly. Eric is now blogging from a grocery store.

Side trips to the new-to-me Bakerina, who is fighting valiantly against networking problems.

Jimmy, at Sticky Doorknobs is also … at the grocery store with Eric…

Julie at Lone Prairie is giving illustrated story in pieces. Illustrated with photos of miniatures – very cool.

July 27, 2006

Dave Day Done

Filed under: whatever — Brian @ 9:46 pm

Well, that was fun.

I don’t think we ate half the food, but the goal was never to eat everything.

I think most of the attendees were under the age of 9 – it was fun to watch them all playing with their swords, running around the back yard and defending the playset.

Good time. Tired now. Going to sleep.

Next year’s theme has been announced: “Have a Nice Dave.” Think yellow smiley faces. And maybe T-shirts.

Happy Dave Day!

Filed under: humor, whatever — Brian @ 2:56 pm

The Jolly Roger is flying, we’ve got 88 pounds of ice, 3 coolers, 2 cases of beer, 6 cases cases of pop, 120 hamburgers, 100 hot dogs, 24 rubbery plastic scimitars, 24 eye patches, 24 pirate bandanas, 4,406 songs on Dave’s iMac and my iPod together, 1 trebuchet, 12 raw eggs and 45 golf balls.

…a full tank of propane, and it’s dark out, and we’re wearing sunglasses.

Kidding.

A grey sky, but only a slight drizzle. 60% chance of rain, but my grill has a lid, so we’ll be fine.

Seas the Dave!

July 26, 2006

What to do on Dave Day

Filed under: humor, whatever — Brian @ 9:05 pm

Gwynne asks:

Should we all be doing something silly and somewhat dangerous on Dave Day?

In a word, yes. The “somewhat dangerous” part is totally optional, and not part of the true Dave Day tradition. That’s more me than Dave. But silly is excellent, and friendly is required. Dave Day is about meeting neighbors you might not otherwise know, and having a simple good time.

The tradition was started four years ago by Dave and his neighbors in Illinois. It was an informal get-together of whoever wanted to come, held on the lawn between houses where he lived. It was mainly a barbecue, and an excuse to meet the neighbors and hang out with friends. It was nothing heavily organized, but it was always on July 27 – weekday or not. Some skipped out from work altogether, others just early. A few would spend the day “working from home” nudge, nudge, wink, wink.

This year is the first interstate Dave Day. We’re having our own little barbecue here tomorrow starting in the late afternoon, and inviting friends and neighbors – looks like about 60 people will be here at some point in the evening. I didn’t know that we knew 60 people, much less that they’d all want to come over to our house on a weeknight for hamburgers and pasta salad.

I’d be thrilled if you do something in the spirit of Dave Day to honor his memory. Introduce yourself to a neighbor you don’t know (tell ’em some guy on the Internet made you do it if you need an excuse). Invite someone over or meet up for a quick drink after work. Ask a friend about that thing they’re interested in that you don’t know much about.

If you do do something, I’d love to hear about it.

July 24, 2006

Trebuchet

Filed under: humor — Brian @ 9:02 pm

It’s not just a font, you know.

A trebuchet is a medieval siege weapon – a gravity-powered catapult, that is.

And, thanks to a guy by the intials of RLT you can just buy the plans, saving the trouble of trial-and-error on the physics side.

You see, Dave Day is coming up – it’s this Thursday – and you (well, I) have to do something silly and moderately dangerous in honor of it.

I built the PVC version – just finished it tonight. I’m getting 16 yards out of a golf ball after a little tweaking.

Thursday: eggs.

July 17, 2006

From life to imagination

Filed under: Art, drawing — Brian @ 8:08 pm

I’ve gotten good enough at drawing people from life and from photos that I’m confident I can be good enough (for me) at drawing.

I really love to draw faces – kind of a shock to me, since I always held those up as the hardest possible thing to draw. I don’t get likenesses very often yet, so there’s still room to improve, and a very enjoyable challenge in that. I have a huge collection of portraits saved from photo.net and flickr to use for practice. It’s fun to look for interesting faces and poses – and there’s plenty out there to find.

But I feel like I’m stuck with drawing things I can look at. I don’t yet know how to invent an image in my mind. I can copy what I see, but I don’t yet know how to make up something worth looking at. One guy whose work I really love has intimated that he has a photographic memory for certain things. His example was the colors of a rainbow. He said he never memorized “ROY G BIV” – he just pictures a rainbow in his mind and sees the colors there. I don’t have that clear of an imagination. I can see a rainbow in my head, but not in that kind of detail.

I wonder if the people who make stuff up have a fully-formed image in their heads before they put pen to paper, or if it all just comes together as they work. How much is conscious planning, and how much is the benefit of the experience of having an artist’s eye for the world?

Maybe it’s just practice I need. I like the idea of “I’ll take care of the quantity, and I’ll let God take care of the quality” – I’m just not holding up my end of that bargain.

July 16, 2006

Mirth

Filed under: kidwork — Brian @ 6:49 pm

Last weekend, I took my much-neglected bicycle out for a ride on the path by the river that goes past Ohio Stadium and beyond to (I think) downtown Columbus.

If you’re going to an OSU football game, you could do much worse than parking somewhere along the trail and riding the rest of the way. (Beating The Post-Game Traffic 101, this is). I will surely do that myself, if I ever make it to a game. By myself, of course, ’cause nobody I know would be likely to want to do that, too.

Anyhow, about 19 miles on the bike, round trip. Just over an hour’s worth of riding. Repeated this weekend. I feel so much better when I get some decent exercise. I was telling Jennifer that it’s like I feel “clean inside” – like my blood is moving around better than it was before, and whatever junk may have accumulated is gone. I am developing a list of excuses to go ride my bike, now. I love that thing. I’ve had it for years, and am just now realizing how much I love it.

I just got back from a little outing with my younger (3-year-old) son. We went to Caribou for coffee, a cinnamon roll, and a glass of chocolate milk that would have had me in the bathroom every 10 minutes for an hour, but he gulped down with no apparent effect. Maybe he immediately transforms it into little boy components before it gets to the bladder. He’s certainly growing as if that’s the case.

Stopped on the way home to look for a cheap little USB hub (no luck. “little” yes, “cheap” no), and a few minutes running around the large, bright yellow circle of tile on the floor near the door of the store. One of the best things about going out with a little boy is that you have an unassailable excuse to act like a little boy, wherever you are.

Got home and played a game of checkers. He’s got the rules figured out, and now just needs to work on strategy. We’re still in the let-the-little-guy-win phase, but if he keeps his interest up, that may not last long.

One’s in bed, the other is getting there, perhaps after a quick game of chess. Much work and play done this weekend. Quiet time for the parents now. Time to figure out what to do with the last hours of the weekend.

July 12, 2006

Championship Writing

Filed under: humor — Brian @ 6:09 am

The winners of this year’s Bulwer-Lytton Fiction Contest have been announced.

From the “miscellaneous” category, a runner-up:

“Please Jeffrey, don’t tell him this time” a beautiful woman, with eyes like cobalt fire, implored of me as she staggered obviously a bit tipsy, if not completely obliterated, out of the Wagon Wheel Tavern and onto West Fourth Street and blinking twice from the afternoon sun managed to slink past me and into the arms of a fellow who I’m guessing was Jeffrey.

Robert Salsbury
Spokane Valley, WA

This is an annual contest where the object is “to submit bad opening sentences to imaginary novels.”

Well worth your time, I suggest.

July 9, 2006

Dave’s Kite Flies Again

Filed under: Uncategorized — Brian @ 3:30 pm

I mentioned that Dave and I flew stunt kites in college.

We found his kite among his things, and, with his parents’ blessing, I took it home with me.

Jenn suggested getting it out today – it’s a pretty decent wind out there. A little gusty, but enough to have a little fun. We took it out. It’s the same model as one of mine that I haven’t been able to repair from a pretty impressive crash a few years back, so it’s familiar.

It was nice to watch it fly.

It’s a good kite. A Griffin – wingspan in the neighborhood of 7 or 8 feet. Pretty strong pull in a decent wind. It’s the same colors as the one in that photo.

Older Posts »

Blog at WordPress.com.