Tag Archives: shell scripting

Last minute talk on automated Perl builds using Hudson tonight

12 Nov

My friend Scott McWhirter, who heads up the Vancouver Perl Monger’s group, asked me yesterday to give a last-minute talk on anything in particular at tonight’s Vancouver.pm meeting. He wasn’t exactly begging, but I know he’s short on speakers this month, and he wanted something interesting to show.

So I decided I’d talk about building and testing Perl-based projects using Hudson. I’ve been planning on writing a blog post on the subject for the past month, but haven’t found the time to finish off the post properly. So if you’re interested in the topic, and you don’t want to wait for me to get around to writing about it online, please feel free to drop by tonight!


Update: The talk went well! Until I have time to put a more comprehensive post up on the topic, you can always read the slides from tonight’s talk.

Have a list of several hundred addresses to get coordinates for? Perl to the rescue!

10 Jun

I recently wanted to try my hand at writing a little iPhone app for helping students find University grant funding.  It turns out to be a bit more difficult than I’d expected, but part of the app was to be a listing of all the available universities near the student.  This, of course, would involve actually having a list of Universities.  To make a long story short, once I got the list (Wikipedia rocks), I needed to get their locations so I could do a proximity search from the user’s coordinates.  Since I didn’t want to spend too much time entering every one of the several hundred University names into Google, I decided to whip up a simple little script in Perl to do this for me.

#!/usr/bin/perl
use strict;
use warnings;
use Geo::Coder::Google;
our $apikey = 'Your-API-Key';
my $geocoder = Geo::Coder::Google->new(apikey => $apikey);
while (<>) {
    chomp $_;
    my $location = $geocoder->geocode( location => $_ );
    print "$_: ";
    if (ref($location) eq 'HASH') {
        print "\n";
        print "    Address: $location->{address}\n";
        print "    Latitude: $location->{Point}{coordinates}[1]\n";
        print "    Longitude: $location->{Point}{coordinates}[0]\n";
    } else {
        print "UNKNOWN\n";
    }
}

If it wasn’t for Perl, this would be fiendishly complicated.  I just threw that in my ~/bin directory and passed a list of addresses to it on STDIN.  Or you could give it a list of files that contain addresses, one per line, and it will give you a YAML output of the results.  For instance:

nachbaur$ echo "University California San Diego" | ~/bin/str2geo.pl
University California San Diego:
    Address: University City, San Diego, CA, USA
    Latitude: 32.854672
    Longitude: -117.204533

I hope you have fun with it.  It was easy to build, but writing little pipe commands like this makes using a Mac with Perl a blast.

Build process experiments with PhoneGap

8 Jun

I’ve made some quick updates on the train this morning, and ended up creating a Bourne shell script in the iPhone directory of PhoneGap for renaming a brand-new PhoneGap fork to whatever your project is called. This also works with the previous changes I made to my buildprocess branch, meaning that when you’re done, you shouldn’t have any references to PhoneGap in your code at all. It also makes developing quite a lot easier, since renaming my XCode project file by hand is cumbersome, and needs to be done every time I start a new project.

(more…)