Skip to content

Instantly share code, notes, and snippets.

View Util's full-sized avatar

Bruce Gray Util

View GitHub Profile
# Trying for a simpler version of https://gist.github.com/gfldex/e28992d7d85451ed669e7942f0b27e30 ,
# because it gets down to the Iterator level, and also evaluates its condition twice for every value.
# All of these versions use the L1 record-matching logic I learned way back in
# the RPG language (where it was built into the language itself as L1,L2...L9 and MR indicators).
# Evaluates its condition N+1 times
sub batch2 (@list, &cluster) {
return lazy gather {
@Util
Util / gist:2d6a03a76021e5da4074574da8e3e78e
Created June 10, 2021 16:43
Raku docs - Guide to Sorting - for public comment during TPRC conference BoF
=begin pod :kind("Language") :subkind("Language") :category("tutorial")
=TITLE Sorting
=SUBTITLE Guide to sorting in Raku
=head1 Quick solutions to common tasks
Simple sorts of list of values:
=begin code
#!env perl6
use v6;
$*ERR.print("Benchmark ", 'Miltiplier', ": ");
my $stime = now;
my $max_l = 20_000;
say :$max_l.perl;
my @l = 1..$max_l; # Hmmm. 2x here increases runtime by 4x
my $n;
for (^100) { # OK 10x here increases runtime by 10x
@Util
Util / hyper_benchmark.p6
Created February 11, 2016 13:51
Perl 6 benchmark for Atlanta.pm to play with on new massive multicore server
use v6;
# 2016-02-09 <bruce.gray@acm.org>
my $length = @*ARGS.shift;
say "Length = $length";
my @x = 1..$length;
my @y = @x.reverse;
@Util
Util / cdr_no_outer_hash.pl
Created October 14, 2013 17:25
CDR parser without outer hash to group records. Tested, working code.
# I think that this algorithm for handling the gzip'ed output files
# will be more efficient in speed, and vastly better in memory.
use Modern::Perl;
my $divider = 65000;
my ( $fileDate, $fileMinute ) = unpack 'x6 a8 x1 a4', $ARGV[0];
sub format_a_records_file_counter { return sprintf '%02d', $_[0] }
@Util
Util / cdr_parser.p6
Created October 14, 2013 01:25
Refactoring, commentary, and alternate Perl 6 version of Woody2143's https://gist.github.com/Woody2143/6925004 .
# Just to show off the clarity of Perl 6.
# Code is untested! (Ran out of time.)
my @keys = <
callingNumber calledNumber numberBeforeTranslations dialedNumber
genericAddressParam ingressProtocol egressProtocol callDirection
ingressTgidName egressTgidName
>;
my @tnFields = @keys[0..4];
@Util
Util / gist:6358078
Created August 27, 2013 19:41
Rosella setup
# This is what I did to get it Rosella working:
mkdir ~/new_rosella_dir
cd ~/new_rosella_dir
git clone https://github.com/Whiteknight/Rosella.git
cd Rosella/
# Correct this for your Parrot path
PATH=$PATH:~/Perl/Parrot/Git/Parrot/parrot
# Only needed on Mac OS X
export DYLD_LIBRARY_PATH=~/Perl/Parrot/Git/Parrot/parrot/blib/lib
make
@Util
Util / Notes
Last active December 19, 2015 01:58 — forked from Woody2143/Schwartzian.pl
A reply to the original (prefork) version.
1. Spelling corrected: Schwartzian transform
2. No need to use parens around \d{8}.
3. I like ST better, but GRT is faster for large lists:
http://www.perlmonks.org/?node_id=145659
4. Need to warn or die to show bad data when regex fails.
5. Perl 6 automatically does ST for you:
my @sorted = @files.sort({ / SWITCH _ \d**8 _ (\d**6) / or die; $0; });
@Util
Util / scott_irc_02.pl
Created April 6, 2012 14:08
Example of Moose classes in the same single script as the mainline code.
# Yes, you can put Moose classes in the same source file as your mainline code, rather than doing the CPAN-standard of one class per module.
# However, you must place the class definitions above the uses of the classes.
package Point;
use Moose;
has 'x' => ( isa => 'Int', is => 'rw' );
has 'y' => ( isa => 'Int', is => 'rw' );
__PACKAGE__->meta->make_immutable;
@Util
Util / z_table.pl
Created March 9, 2012 19:06
Create Z table for statistics
#!perl
use strict;
use warnings;
# This code duplicates "Appendix B The Standard Normal Table"
# from a book used by Alexis in 2012 statistics class.
# 2012-03-09 <bruce.gray@acm.org>
# Wrote program in Perl 6, then converted to Perl 5.
use constant SQRT_2PI => sqrt( 8 * atan2(1,1) );