Skip to content

Instantly share code, notes, and snippets.

@leedo
Created April 27, 2011 16:32
Show Gist options
  • Save leedo/944614 to your computer and use it in GitHub Desktop.
Save leedo/944614 to your computer and use it in GitHub Desktop.
use Plack::Builder;
use AnyEvent::Feed;
use POSIX qw/ceil/;
my @image_urls;
my $img_re = qr{https?://[^\s]+\.(?:gif|png|jpe?g)}i;
my $feed = AnyEvent::Feed->new(
url => 'http://cutegirlsbeingcute.tumblr.com/rss',
interval => 60 * 60, # every hour
on_fetch => sub {
my ($reader, $new, $feed, $error) = @_;
return unless @$new;
@image_urls = map {($_->content->body =~ /($img_re)/g)} $feed->entries;
},
);
builder {
mount "/" => sub {
my $env = shift;
my $image = $image_urls[ceil(rand($#image_urls))];
return [301, [Location => $image], []];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment