Fast Perl Dependency Isolation

I gave a presentation at OpenWest about Perl dependency isolation using perlbrew and plenv + carton:

2015-06-01    
Line, Load, Neutral, Ground

I re-learned some electrical terms today that may be useful later when working with GFCI circuits.

  • Line (usually black, also known as “hot”): comes in from the electrical panel
  • Load (usually black, sometimes red): is a continuation of line and goes out to downstream devices. Non-GFCI circuits will not have a load.
  • Neutral (usually white): completes the AC circuit and carries excess current to ground
  • Ground (bare): carries any inadvertent current away from the circuit in case of a fault

The catchphrase is “line in, load out”.

2015-05-17    
Perl Hash Reference Partial Copy

Given a multi-level deep hash reference:

my $conf = {
    bucket => {
        list => {
            h    => 'help me',
            _sub => sub { say "something" }
        }
    },
    file => {
        upload => {
            h    => 'help me too',
            _sub => sub { say "else" }
        }
    }
};

We want to remove all of the _sub keys and put them in a separate hash reference with the same structure. This does that:

2015-03-28    
Perl Dependency Isolation

I gave a talk about Perl dependency isolation at Salt Lake Perl Mongers.

2015-01-14    
Devel::Cover Notes

Some notes for using Devel::Cover.

Gathering coverage

CPAN::Reporter doesn’t have a build step, so we prove -l; we also don’t want to cover the world, so we set -inc=lib:

HARNESS_PERL_SWITCHES=-MDevel::Cover=-inc=lib prove -l

or:

PERL5OPT=-MDevel::Cover prove t/some-test.t

This will run the prove utility and turn on code coverage.

Selecting only one file to cover

cover -select=lib/Some/Module.pm

You may add multiple -select options.

Ignoring files to cover

cover -ignore_re=^/var/core_lib -ignore=/usr/bin/prove
2015-01-14    
Hashing to an 8-bit Integer

I needed to come up with a way to spread out chunks of a subnet among a handful of users, so I came up with this routine:

sub hash256 {
    my $str  = shift;
    my $hmac = hmac_sha256($str);
    my $val  = unpack "L*" => $hmac;
    my $hash = $val % 256;

    return $hash;
}

Used:

for my $str ( qw/scott paul mark jayce rvd james/ ) {
    say sprintf "%-15s %d" => $str, hash256($str);
}

Now the result of my $hash = hash256('joe') can be used as, say, the third octet in a cidr: 192.168.$hash.0/24.

2014-12-16    
tmux Notes

scroll mode

tmux has a scroll mode where you can use page up/page down and arrows to scroll the buffer back. To enter scroll mode, C-b <page up>. To get out of scroll mode, <Esc>. Also C-b [ turns on scroll mode.

sharing

Poor man’s screen sharing:

$ tmux -S /tmp/tmux-shared new-session -s session-name
(detach)
$ chmod 777 /tmp/tmux-shared
(attach)

Person 2 attaches:

$ tmux -S /tmp/tmux-shared attach-session -s session-name
2014-12-15    
Functional Programming with Perl

I gave a talk about functional programming with Perl at Salt Lake Perl Mongers.

2014-11-19    
procmail Notes

I don’t mess with procmail much anymore, but maybe these will be useful to someone.

Split a mailbox into separate files for each message:

$ formail -s sh -c 'cat - > foo.$FILENO' < klez.file

Resend a mailbox (foo) through a set of filters (rc.test):

$ formail -s procmail ./rc.test < foo

Move the last 10 messages from folder foo and put them in folder bar:

$ MSGS=`egrep '^From ' foo | wc -l`
$ formail +`expr $MSGS - 10` -s < foo > bar

Check which recipes triggered most often (based on a verbose log format):

2014-10-26    
Asynchronous Programming Patterns in Perl

I gave a talk about asynchronous programming patterns in Perl at Salt Lake Perl Mongers. This presentation ultimately landed me a new job—thank you to SLC.pm!

non-blocking

2014-10-15