Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env perl
use 5.14.1;
use warnings;
package API {
use Moose::Role;
requires qw/store/;
}
# For some reason, this was raising hell after adding
# use namespace::autoclean;
my $percent_captions = sub {
my @left = @_[ 0 .. $#_ - 1 ];
my @right = @_[ 1 .. $#_ ];
return "< $_[0]%", pairwise {"$a to $b%"} @left, @right;
};
my @pcts = ( 1, 5, 10, 25, 50, 75, 100 );
my @pct_captions = $percent_captions->(@pcts);

Keybase proof

I hereby claim:

  • I am semifor on github.
  • I am semifor (https://keybase.io/semifor) on keybase.
  • I have a public key whose fingerprint is 2DFB 3643 FA94 E02F 0A68 DA27 D32B C82B 2740 B9FD

To claim this, I am signing this object:

#!/usr/bin/env/perl
use 5.12.1;
use warnings;
use List::Util qw/sum/;
my $customers = [ 10, 20, 30, 40, ];
my $churned = [ 2, 4, 3, 9, ];
my $churn_rate = 30 * sum(@$churned) / sum(@$customers);
#!/usr/bin/perl
use strict;
use warnings FATAL => qw( all );
use Net::Twitter::Lite::WithAPIv1_1;
use Lingua::EN::Inflect qw(NO NUMWORDS);
use HTML::Entities qw(encode_entities_numeric);
use Try::Tiny;
use lib '../files/lib';
#!/usr/bin/env perl
use 5.12.1;
use warnings;
eval { die 'hard' };
if ( @$ ) {
say 'land softly';
}
@semifor
semifor / closure.md
Last active December 16, 2015 08:39

Javascript does not have block scope. It has function scope. So, it behaves much differently than perl and other languages with block scope.

E.g., this simple perl program creates then invokes an array of closures:

my @closures;

for ( 1 .. 3 ) {
@semifor
semifor / gist:5401066
Created April 17, 2013 01:21
Upgrading from legacy Lists API to REST list methods.
# The legacy Lists API identified lists a `user` and `list_id`, which were the list
# owners screen name and the list slug, respectively.
#
# The current list methods identify a list either by numeric ID (list_id => $list_id),
# or by the owning user's screen_name and slug { owner_screen_name => $name, slug => $slug },
# or owning user's user ID as slug { owner_id => $id, slug => $slug }.
#
# So, for the most part, it's an easy transition.
#
# E.g., lines 251-255
# Rate limit status example
my $r = $nt->rate_limit_status;
my $status_show_limit = $r->{resources}{'/statuses/show/:id'};
my $remaining = $status_show_limit->{remaining};
# Or, unpack limit, remaining and reset together:
my ( $limit, $remaining, $reset ) = @{$r->{resources}{statuses}{'/statuses/show/:id'}}{qw/limit remaining reset/};
#!/usr/bn/env perl
use 5.12.1;
use warnings;
package Foo {
use Devel::GlobalDestruction;
sub new { bless {}, ref $_[0] || $_[0] }
sub DESTROY {