Skip to content

Instantly share code, notes, and snippets.

@earino
earino / gist:3068269
Created July 7, 2012 22:11
Using LWP to mess the content type
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
my $req = POST 'http://localhost:3000/',
Content_Type => 'form-data',
@earino
earino / gist:3061200
Created July 6, 2012 16:33
Using random backoff
use POE;
use POE::Component::Client::TCP;
use Proc::BackOff::Random;
my $backoff = Proc::BackOff::Random->new( {
min => 5 ,
max => 100 } );
POE::Component::Client::TCP->new(
@earino
earino / gist:3061188
Created July 6, 2012 16:29
Using linear backoff
use POE;
use POE::Component::Client::TCP;
use Proc::BackOff::Linear;
my $backoff = Proc::BackOff::Linear->new( {
slope => 5,
b => 0,
x => 'count' } );
@earino
earino / gist:3061120
Created July 6, 2012 16:15
The standard way folks handle reconnection
Disconnected => sub {
my ($heap, $kernel) = @_[HEAP, KERNEL];
$heap->{'logger'}->error("disconnected from ".$config{'scanner_host'}.":".$config{'scanner_port'}." enqueueing reconnect.");
$kernel->delay( reconnect => 60 );
$backoff->failure();
},
ServerError => sub {
my ($heap, $kernel) = @_[HEAP, KERNEL];
@earino
earino / benchmark.pl
Created July 2, 2012 14:08
Benchmark for qr code creation
#!/usr/bin/env perl
use warnings;
use strict;
use Imager::QRCode;
use Data::Dump qw(dump);
use String::Random;
my @sizes = qw/ 1 2 3 4 5 6 7 8 9 /;
@earino
earino / gist:2996703
Created June 26, 2012 16:04
Snippet of code using Inline::C and leptonica for super duper fast image resizing
# stuff setting up moose and the environment omitted
sub BUILD {
my $self = shift;
my $application_environment = $ENV{'APPLICATION_ENVIRONMENT'};
my $conf = new Config::General($self->config_file);
my %config = $conf->getall;
@earino
earino / gist:1166495
Created August 23, 2011 20:52
Error installing MooseX::Declare
cpanm (App::cpanminus) 1.4004 on perl 5.012003 built for darwin-2level
Work directory is /Users/earino/.cpanm/work/1314132501.52001
You have make /usr/bin/make
You have /usr/bin/curl
You have /usr/bin/tar: bsdtar 2.6.2 - libarchive 2.6.2
You have /usr/bin/unzip
Searching POE on mirror http://lvmirrors.lightningsource.com/CPAN ...
Downloading index file http://lvmirrors.lightningsource.com/CPAN/modules/02packages.details.txt.gz ...
Uncompressing index file...
POE is up to date. (1.312)