Skip to content

Instantly share code, notes, and snippets.

@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)
@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 / 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: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 / 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: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: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:3068294
Created July 7, 2012 22:13
Output from dancer printing a dump of request
<~/play/bad_upload_handler> $ perl bin/app.pl
[54114] core @0.000011> loading Dancer::Handler::Standalone handler in /Users/earino/perl5/lib/perl5/Dancer/Handler.pm l. 45
[54114] core @0.000185> loading handler 'Dancer::Handler::Standalone' in /Users/earino/perl5/lib/perl5/Dancer.pm l. 464
>> Dancer 1.3095 server 54114 listening on http://0.0.0.0:3000
== Entering the development dance floor ...
[54114] core @0.000133> request: POST / from 127.0.0.1 in /Users/earino/perl5/lib/perl5/Dancer/Handler.pm l. 56
[54114] core @0.000527> [hit #1]Trying to match 'POST /' against /^\/$/ (generated from '/') in /Users/earino/perl5/lib/perl5/Dancer/Route.pm l. 84
[54114] core @0.000678> [hit #1] --> got 1 in /Users/earino/perl5/lib/perl5/Dancer/Route.pm l. 102
[54114] debug @0.001524> [hit #1]request: $VAR1 = bless( {'_body_params' => {'born' => '1978','email' => 'earino@gmail.com','filename' => 'file.jpeg','gender' => 'M','name' => 'Eduardo Arino'},'_chunk_size' => 4096,'_http_body' => bless( {'body' => undef,'boun
@earino
earino / gist:3183845
Created July 26, 2012 19:06
high level example
my @list_of_work = qw/ BLAH BLAH BLAH /;
my @list_of_endpoints = qw/ YADDA YADDA YADDA /;
for my $unit_of_work (@list_of_work) {
for my $endpoint (@list_of_endpoints) {
my $value_retrieved = retrieve_value_from_stuff($unit_of_work);
do_stuff_to($value_retrieved);
push_value_retrieved_to($endpoint);
}
}
@earino
earino / gist:3183895
Created July 26, 2012 19:12
parallelized first stab
my $pm = Parallel::ForkManager->new($PROCESSES);
my @list_of_work = qw/ BLAH BLAH BLAH /;
my @list_of_endpoints = qw/ YADDA YADDA YADDA /;
for my $unit_of_work (@list_of_work) {
my $pid = $pm->start and next;
for my $endpoint (@list_of_endpoints) {
my $value_retrieved = retrieve_value_from_stuff($unit_of_work);