Skip to content

Instantly share code, notes, and snippets.

View jeffa's full-sized avatar

Jeff Anderson jeffa

View GitHub Profile
@jeffa
jeffa / query-plack.cgi
Created April 22, 2015 23:25
Minimal Plack app that interacts with query params
#!/usr/bin/env plackup
use strict;
use warnings;
use Data::Dumper;
use Plack::Request;
use Plack::Response;
my $app = sub {
@jeffa
jeffa / MVC.pl
Last active February 24, 2017 03:15
Minimal example of an MVC implementation
#!/usr/bin/perl -l
package Model;
use Moose;
has state => ( is => 'ro', reader => 'get_state', default => 0 );
sub set_state { $_[0]->{state} += $_[1] }
package View;
use Moose;
sub update_display { print $_[1]->get_state }
@jeffa
jeffa / tap2junit.sh
Last active August 29, 2015 14:05
Transform Perl TAP output into JUnit XML
prove -rl --formatter=TAP::Formatter::JUnit --timer > junit.xml
@jeffa
jeffa / djson.sh
Last active August 29, 2015 14:05
Decode JSON file into Perl Data::Dump
perl -MData::Dumper -MJSON -MFile::Slurp -e"print Dumper decode_json read_file shift" foo.json
@jeffa
jeffa / a2b.sh
Last active August 29, 2015 14:05
ASCII to 8bit Binary
perl -e'print /\s+/ ? $/ : unpack B8 => $_ for split //, shift' 'hello world '
@jeffa
jeffa / ssh-auth-add.pl
Last active August 29, 2015 14:02
Bootstrap your ssh public key to a remote server
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
use Getopt::Long;
use Pod::Usage;
GetOptions (
'r|remote=s' => \my $remote,
@jeffa
jeffa / oauth1-perl-sign-on.pl
Last active December 24, 2015 12:18
Twitter APIs Client Library for Perl
#!/usr/bin/env perl
package LWP::Authen::OAuth2::Dancer;
our $VERSION = '0.1';
use Dancer ':syntax';
use Net::Twitter;
use Scalar::Util 'blessed';
our $nt = Net::Twitter->new(
traits => [qw/API::RESTv1_1/],
consumer_key => '',
@jeffa
jeffa / oauth2-perl-sign-on.pl
Last active December 23, 2015 09:39
Google APIs Client Library for Perl
#!/usr/bin/env perl
package LWP::Authen::OAuth2::Dancer;
our $VERSION = '0.1';
use Dancer ':syntax';
use LWP::Authen::OAuth2;
our $oauth2 = LWP::Authen::OAuth2->new(
client_id => '',
client_secret => '',
service_provider => 'Google',
use strict;
use warnings;
use DBI;
# connect
my $dbh = DBI->connect(
qw(DBI:mysql:mp3:host user pass),
{ RaiseError => 1 }
);
@jeffa
jeffa / rotate-spreadsheet.pl
Created August 29, 2013 14:23
Transpose Excel docs from "portrait" to "landscape."
use strict;
use warnings;
use Math::Matrix qw(transpose);
use Spreadsheet::ParseExcel::Simple;
use Spreadsheet::WriteExcel::Simple;
my $xls = Spreadsheet::ParseExcel::Simple->read('old.xls');
my @data;
for ($xls->sheets) {
while ($_->has_data) {