Skip to content

Instantly share code, notes, and snippets.

Avatar

ab5tract ab5tract

  • Amsterdam, Netherlands
View GitHub Profile
View bigint-timetrial.p6
use v6;
sub bigpackids(int @ids) {
my $ret = 0;
my $c = 0;
while $c++ < +@ids {
$ret = $ret +| (1 +< (@ids[$c] - 1));
}
return $ret;
View gist:d730a845a3915f7abdcf
#!/usr/bin/env perl6
use v6;
sub MAIN($dir) {
my $handler-supplier = Supplier.new;
my $handler-supply = $handler-supplier.Supply;
my %seen;
my $dispatch-promise = start {
say "Watching out on '$dir'";
@ab5tract
ab5tract / sha1.p6
Last active Dec 11, 2015 — forked from cognominal/sha1.p6
sha1 hash
View sha1.p6
subset Sha1 of Str where *.chars == 40 and m:i/<[A..Z 0..9]>/;
class Sha1H does Associative {
has $!sha1;
has %!h{Sha1(Str)};
method AT-KEY($_) { %!h{ .lc } };
method ASSIGN-KEY($_, $v) { %!h{ .lc } = $v }
}
class Sha1Str is Str {
View Grid.pm6
unit class Grid;
#use Terminal::Print::Commands;
#
#constant T = Terminal::Print::Commands;
has @.grid;
has $!character-supply;
has $!control-supply;
View gist:18b95160763bf901c74e
module Chance {
my @faces = '⚀', '⚁', '⚂', '⚃', '⚄', '⚅';
sub term:<¿>() is export(:golf) { @faces.roll }
sub chance() is export { ¿ }
}
import Chance;
say chance;
View bag.patch
commit d96dccd1737ed4ab7e5cf293a178f7d28aa1e1f1
Author: ab5tract <john.haltiwanger@gmail.com>
Date: Sat Aug 29 11:41:11 2015 +0200
Coercion from Set.list (via Any) is bonkers
diff --git a/src/core/Setty.pm b/src/core/Setty.pm
index e86b44d..4e491e0 100644
--- a/src/core/Setty.pm
+++ b/src/core/Setty.pm
@ab5tract
ab5tract / benchmark-for.p6
Last active Aug 29, 2015
for-vs-while-int-vs-Int
View benchmark-for.p6
my $begin = DateTime.now;
say "Beginning at $begin";
my int @range = 0..^400;
my $count = 0;
for @range -> int $i {
for @range -> int $j {
for @range -> int $k {
@ab5tract
ab5tract / sereal-test.p6
Last active Aug 29, 2015
Sereal::Pool::Perl5
View sereal-test.p6
use v6;
use Inline::Perl5;
class Sereal::Encoder::Perl5 {
has Inline::Perl5 $!p5;
has $!encoder;
submethod BUILD() {
$!p5 := Inline::Perl5.new;
View overlaps-with.p6
#!/usr/bin/env perl6
use Test;
sub overlaps-with( $r1, $r2 ) {
$r1.min ~~ $r2 and $r1.max ~~ $r2 or $r2.min ~~ $r1 and $r2.max ~~ $r1
or ( $r1.min == $r2.min and ($r1.max <= $r2.max or $r2.max <= $r1.max) )
or ( $r2.min < $r1.min < $r2.max <= $r1.max )
or ( $r1.min < $r2.min < $r1.max <= $r2.max );
}
View overlaps-with.p6
use Test;
sub overlaps-with( $r1, $r2 ) {
$r1.min ~~ $r2 and $r1.max ~~ $r2 or $r2.min ~~ $r1 and $r2.max ~~ $r1
or ( $r1.min == $r2.min and ($r1.max <= $r2.max or $r2.max <= $r1.max) )
or ( $r2.min < $r1.min < $r2.max <= $r1.max )
or ( $r1.min < $r2.min < $r1.max <= $r2.max );
}
my @range-tests = (