Skip to content

Instantly share code, notes, and snippets.

View briandfoy's full-sized avatar

brian d foy briandfoy

View GitHub Profile
#!/Users/brian/bin/perls/perl5.22.0
use v5.22;
use feature qw(signatures);
no warnings qw(experimental::signatures);
package Tie::Scalar::Sub {
use parent qw(Tie::Scalar);
use Carp qw(croak);
@briandfoy
briandfoy / dos_globs.pl
Created February 22, 2016 21:44
DOS pattern matching, in Perl
#!perl
use strict;
use warnings;
=pod
Match 8.3 filenames in the DOS way, from Raymond Chen
https://blogs.msdn.microsoft.com/oldnewthing/20071217-00/?p=24143
websocket '/find' => sub ( $c ) {
state $loop = Mojo::IOLoop->singleton;
app->log->debug( "websocket for find" );
$c->inactivity_timeout( 50 );
my $id;
$c->on( message => sub ( $ws, $message ) {
my $json = decode_json( $message );
my $command = $json->{c};
#!/Users/brian/Dropbox/perl6s/rakudo-star-2016.10/bin/perl6
use v6;
# https://docs.perl6.org/language/unicode_texas#Other_acceptable_single_codepoints
# https://gist.github.com/briandfoy/619638701f38817387f3e5d22d6dab12
my %hash;
BEGIN { # Phasers on!
#!/Users/brian/bin/perls/perl5.24.0
use v5.24;
use feature qw(signatures);
no warnings qw(experimental::signatures);
use Data::Dumper;
use HTML::Entities;
use Mojo::UserAgent;
use open qw(:std :utf8);
@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 );
@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 / 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 / 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 )
=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)).