Skip to content

Instantly share code, notes, and snippets.

View briandfoy's full-sized avatar

brian d foy briandfoy

View GitHub Profile
@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 );
@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 / 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 / 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 / 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 / scotus_nominations.csv
Last active October 7, 2018 20:38
Supreme Court nomination history
Nominee President To Replace Nominated to Chief Nomination Date Voice Roll Call No. Yay Nay Difference Action Action Date Delay
Brett Kavanaugh Trump Kennedy Jul 10, 2018 223 50 48 2 Confirmed Oct 6, 2018 88
Neil M. Gorsuch Trump Scalia Feb 1, 2017 111 54 45 9 Confirmed Apr 7, 2017 65
Merrick B. Garland Obama Scalia Mar 16, 2016 No action
Elena Kagan Obama Stevens May 10, 2010 229 63 37 26 Confirmed Aug 5, 2010 87
Sonia Sotomayor Obama Souter Jun 1, 2009 262 68 31 37 Confirmed Aug 6, 2009 66
Samuel A. Alito, Jr. Bush O'Connor Nov 10, 2005 2 58 42 16 Confirmed Jan 31, 2006 82
Harriet Miers Bush O'Connor Oct 7, 2005 Withdrawn Oct 28, 2005 21
John G. Roberts, Jr. Bush Rehnquist x Sep 6, 2005 245 78 22 56 Confirmed Sep 29, 2005 23
John G. Roberts, Jr. Bush O'Connor Jul 29, 2005 Withdrawn Sep 6, 2005 39
@briandfoy
briandfoy / usps_track.pl
Created November 18, 2018 02:32
Get the tracking info for a single USPS shipment
#!/Users/brian/bin/perls/perl-latest
use v5.26;
use utf8;
use strict;
use warnings;
use lib qw(/Users/brian/Dev/business-us-usps-webtools/lib);
use Business::US::USPS::WebTools::TrackConfirm;
use Term::ANSIColor;
@briandfoy
briandfoy / tumblr.pl
Created November 18, 2018 02:39
Mirror the stuff in various tumblr pages
#!/Users/brian/bin/perls/perl-latest
use v5.28;
use utf8;
use open qw(:std :utf8);
use strict;
use warnings;
use feature qw(signatures);
no warnings qw(experimental::signatures);
use IO::Interactive qw(interactive);
@briandfoy
briandfoy / fizzbin-bits.pl
Last active January 9, 2019 21:12
Another FizzBin without an if
use v5.24;
my $n = $ARGV[0] // 35;
my $count = 0;
while($count <= $n) {
state $a = [ \$count, \'Fizz', \'Bin', \'FizzBin' ];
say $a->[ (810092048>>((2*(++$count-1))%30)) & 0b11 ]->$*;
}
@briandfoy
briandfoy / merge_files.py
Last active January 27, 2019 03:19
Merge multiple files
#!/usr/local/bin/python3
import heapq
import os
import sys
class MergeFiles:
"""
Given a list of files, output their numbers in sorted order.