Skip to content

Instantly share code, notes, and snippets.

View briandfoy's full-sized avatar

brian d foy briandfoy

View GitHub Profile
@briandfoy
briandfoy / gist:11c6fcedf5ef9d1fcee60b777c607dc5
Created September 26, 2018 23:50
Don't sort by average ratings
http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
sub ci_lower_bound ( $postive_ratings, $total_ratings, $confidence = 0.95 ) {
return 0 if $total_ratings == 0;
@briandfoy
briandfoy / mojo-file-parent
Created September 25, 2018 04:06
(Perl) (mojolicious) A failed idea to make it easier to resolve files
#!/Users/brian/bin/perls/perl-latest
use v5.26;
use utf8;
use strict;
use warnings;
use Mojo::File;
package Mojo::File::Role::parent {
@briandfoy
briandfoy / mojo-imgur.pl
Created September 24, 2018 21:32
(Perl) (mojolicious) scrape an imgur gallery
#!/Users/brian/bin/perls/perl-latest
use v5.26;
use utf8;
use strict;
use warnings;
use Mojo::File qw(path);
use Mojo::UserAgent;
use Mojo::Util qw(dumper);
@briandfoy
briandfoy / slow_stdin_
Last active September 7, 2018 13:54
Non-blocking read lines from a slow standard input (mojolicious) (perl)
#!/Users/brian/bin/perls/perl-latest
use v5.28;
use utf8;
use strict;
use warnings;
use feature qw(signatures);
no warnings qw(experimental::signatures);
# non-blocking stream reading of a slow standard input
# perl -pe '$|++; sleep 1' /etc/hosts | perl-latest read_slowly.pl
@briandfoy
briandfoy / mob_stadiums.ppl
Created July 18, 2018 14:53
Grab all the MLB stadium names
#!/Users/brian/bin/perls/perl-latest
use v5.28;
use Mojo::DOM;
use Mojo::UserAgent;
my $data = do { local $/; <DATA> };
my $url = 'http://m.mlb.com/teams/';
my $tx = Mojo::UserAgent->new->get( $url );
=pod
I'm experiencing an odd problem on macOS 10.13. I suspect it's
something to do with APFS (Encrypted). It looks like there's some
other magic when I try to rename a file to a name that already exists.
I could not reproduce this on FAT or HFS+ filesystems.
I've tried this with perls back to 5.12, all compiled with clang
(4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)).
@briandfoy
briandfoy / knuth_arrow.p6
Created January 12, 2018 06:11
Knuth Arrow custom operators in Perl 6
#!/Applications/Rakudo/bin/perl6
use Test;
multi infix:<↑> ( Int:D \n, Int:D \m --> Int:D )
is equiv(&infix:<**>)
is assoc<right>
{ n ** m }
proto infix:<↑↑> ( Int:D \n, Int:D \m --> Int:D )
@briandfoy
briandfoy / The Perl Bus factor
Created November 6, 2017 18:49
The Perl Bus factor
by brian d foy <[email protected]>
Klint Finley's article for <i>Wired<i>, <a href="https://www.wired.com/story/giving-open-source-projects-life-after-a-developers-death/">Giving Open-Source Projects Life After A Developer's Death</A>, discusses the trouble taking over Ruby projects when the lead developer dies. He interviewed Neil Bowers, one of the people who helps maintain the Comprehensive Perl Archive Network then mangles the information to make it seem like the Neil by himself sometimes finds volunteers to take over projects if he feels like it at the time.
But the PAUSE (Perl Authors Upload Server) admins do much more than that. We've had an official policy around it for years. I remember the first time we had to deal with this. Over a decade ago <a href="http://archive.oreilly.com/pub/post/perl_loses_contributor_and_col.html">Iain Truskett, an important Perl developer, passed away</a>. Andy Lester took it upon himself to act as a executor of the developer's CPAN packages. He didn't want to mai
@briandfoy
briandfoy / make-ranks-and-suits.p6
Last active July 25, 2017 21:34
Perl 6 poker hand generator (but not scorer)
#!/Applications/Rakudo/bin/perl6
my $ranks = ( 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'A' );
my $suits = < ♣ ♡ ♠ ♢ >;
( @$ranks X @$suits )
==> map { [~] @$_ } \
==> my @cards;
;
@briandfoy
briandfoy / uri-wilensky-surprising-policy-effects.p6
Last active July 9, 2017 23:40
A Perl 6 version of Uri Wilensky's simulation
#!/Applications/Rakudo/bin/perl6
# http://www.decisionsciencenews.com/2017/06/19/counterintuitive-problem-everyone-room-keeps-giving-dollars-random-others-youll-never-guess-happens-next/
multi MAIN ( Int $players = 100, Int $dollars = 100, Int $max-rounds = 5000 ) {
my @array = {
wallet => $dollars, # the current money N has
received => 0, # the cumulative money received
'given' => 0, # the cumulative money given
} xx $players;
my &recipient = &donate-to.assuming( @array.elems );