Skip to content

Instantly share code, notes, and snippets.

View labster's full-sized avatar

Brent Laabs labster

View GitHub Profile
@labster
labster / hashsub
Created March 4, 2013 00:28
syntax error with sub in the middle + hash access
my %bar;
sub foo {
1;
}
%bar<z> = 'quux';
@labster
labster / IO::Path proposal
Created March 28, 2013 22:08
new spec for IO::Path
=head2 IO::Path
class IO::Path is Cool does IO::FileTest { }
Holds a path of a file or directory. The path is generally divided
into three parts, the I<volume>, I<directory> and I<base name>.
On Windows, the volume is a drive letter like C<C:>, or a UNC network volume
like C<\\share\>. On UNIX-based systems, the volume part is empty.
class Foo {
method baz ($a, $b?) {
if ! defined $b || $b eq '' {
$b = $*CWD;
}
say $a, $b;
}
}
my role IO::FileTestable { }
my class IO::Handle does IO::FileTestable { }
class IO is IO::Handle { ; }
my class IO::Path is Cool does IO::FileTestable {
#also does IO::FileTestable;
}
@labster
labster / gist:5496330
Last active December 16, 2015 20:59
JAPH 1
use v6;
print $("reHTona tsuj".flip.tclc, Mu.^methods.grep(/p.**2l$/).tclc, "hacker\n");
@labster
labster / ROMAN.p6
Created May 1, 2013 17:03
ROMAN numeral
use v6;
use Lingua::Number;
my &to_roman = &roman-numeral;
use Test;
is to_roman(3), "III", "3 gets converted to III";
@labster
labster / GOLF.p6
Created May 1, 2013 18:30
readable golf
use v6;
sub uq(*@vals) { so @vals.bag.values.all == 1 }
sub rowN($n, *@vals) {
return say "[{@vals.join(',')}]" if $n > 8;
for 1..8 -> $new {
my @vnew = @vals, $new;
my ($i1, $i2) = 0, 0;
next if !uq(@vnew)
or !uq(@vnew.map: { $_ - ++$i1 })
or !uq(@vnew.map: { $_ + ++$i2 });
@labster
labster / ONELINER
Last active December 16, 2015 21:09
Oneliners
program 1
perl6 -n -e '.split(" ")[2].say' 1.txt
program 2
perl6 -e 'say [+] $*ARGFILES.lines' 2.txt
program 3
perl6 -n -e 'say $_, "\n"' 3.txt
program 4
#!/usr/bin/perl
use 5.10.0;
use strict;
use warnings;
my $MAX_LINES = 100_000;
my @FIELDS = (7, 8, 9, 14, 17, 18, 19, 25, 30, 31, 35, 36, 37, 43, 44, 46, 47, 50, 52, 55, 62, 63, 66, 67, 68, 75, 76, 77, 81);
sub nextfilename {
#!/usr/bin/perl
use 5.10.0;
use strict;
use warnings;
use Tie::File;
my $MAX_LINES = 100_000;
my @FIELDS = (7, 8, 9, 14, 17, 18, 19, 25, 30, 31, 35, 36, 37, 43, 44, 46, 47, 50, 52, 55, 62, 63, 66, 67, 68, 75, 76, 77, 81);