August 2010 Archives

The Foursquare gaming code challenge

Mayank Lahiri writes a Foursquare checkin tool in nine Perl statements, and Alex Ford says he has a two line solution, where line means statement, and statement. Part of the reason their solutions look so ugly is that they want to do it with the Standard Library. I was slightly interested in this because someone had asked Randal if he was checking in with Perl (he is not).

Larry Wall once said that he could program anything in one-line of Perl given a sufficiently long line. That is, in a language where lines aren't significant, line count is stupid. If you want to count lines, Python is probably your language.

Faking a Foursquare checking is not straightforward with LWP, which actually makes this problem a little more interesting. The Foursquare API uses either Basic or OAuth authorization, but it doesn't think about web browsers. It figures that your application doesn't need a prompt (i.e. a 403 response) for an authorization header, so there is no authorization realm. This means that LWP's credentials method is useless. However, I can use the add_handler method to fix up the request to force the Authorization header:

use LWP::UserAgent;

my $ua = LWP::UserAgent->new;

# The Foursquare API doesn't have a 403 response, so it has
# no realm. This means I have to force the authorization
# header.
$ua->add_handler( 
    request_prepare => sub { 
        my( $request, $ua, $h ) = @_;
        $request->authorization_basic( @ENV{ qw(FOURSQUARE_USER FOURSQUARE_PASS) } );
        },
    );

$ua->post( 
    'http://api.foursquare.com/v1/checkin', 
    Content => {
        vid     => $ARGV[0] || 8212918,  # The Perl Review
        private => 0,
        geolat  => $ARGV[1] ||  42.01974,
        geolong => $ARGV[2] || -87.67446,
        }
    );

My script isn't exactly the same as theirs, though. I'll let cron handle the other details.

YAPC::EU 2010 videos are on YouTube

The YAPC::EU 2010 team has uploaded to YouTube videos of the conference in the yapceu2010 channel. There's even one of me presenting the White Camel Awards to cog and to Barbie. I don't think I'm terribly interesting, but I like their comments as they accept their awards.

Paul Fenwick couldn't be there, but maybe someone can convince him to do a video acceptance speech. He's dressed as a Star Fleet officer, a pirate, and a mad scientist. What should he be in the video?

Which Perl XML module should I use to ...?

I asked Which Perl XML module should I use? on O'Reilly Answers to survey people about their XML module use, but my question was too general. Before you can recommend an XML module, you need to know what the task is.

I've refined the question into three more specific questions:

Maybe someone should start the same sort of questions for Perl web frameworks or any of the other topics that have multiple (hence, confusing) options.

Which XML module should I use?, on O'Reilly Answers

O'Reilly Answers has an interesting, new poll feature. I've asked Which Perl XML module should I use?.

The Perl activity on O'Reilly Answers has been a bit low, but with a little work, we can get it back up there along with the other topics on the front page.

And, unlike other sites, you can actually redeem the points you earn on O'Reilly Answers for valuable things like books and conference passes. Perl monger group leaders, speakers at O'Reilly events, and people in the book review blog program get starter points just for signing up.

The 2010 White Camel Awards

This year, on behalf of Perl mongers and O'Reilly Media, I present the White Camel Awards at YAPC::EU in Pisa.

The White Camel Awards recognize significant, but non-technical, achievement in the Perl community, traditionally in three areas: Perl advocacy, Perl user groups, and Perl community. Non-technical work tends not only to be thankless jobs which nobody praises in public. However, these people keep doing the work despite the possibility or reward or recognition. Curiou…

My continuing dream of a Perl XML(::Twig) cookbook

I ran into Michel Rodriguez at YAPC, so I started talking to him about my idea for an XML::Twig cookbook. I really, really love his module and want more people to use it. It takes a bit to get used to, so I think it's ideally suited for some cookbook-style documentation.

His advice is that XML::Twig is what you use when parsing and futzing with XML is not the primary purpose of your program (e.g., you have some config files to read). That turned into a bit of a discussion with those around us about when you should use which XML modules, and that we should answer the same cookbook reci…

About brian d foy

user-pic I'm the author of Mastering Perl, and the co-author of Learning Perl (6th Edition), Intermediate Perl, Programming Perl (4th Edition) and Effective Perl Programming (2nd Edition).