Skip to content

Instantly share code, notes, and snippets.

View colomon's full-sized avatar

Solomon Foster colomon

View GitHub Profile
@colomon
colomon / code.pl
Created April 13, 2013 16:58 — forked from masak/code.pl
say qq:to/END/;
Line 1
{foo}
Line 4
END
sub foo { " Line 2\nLine 3" }
@colomon
colomon / modmap
Last active December 17, 2015 04:18 — forked from TimToady/modmap
sub modmap (Int $x is copy, @rads) {
gather {
while $x and @rads {
my $rad = @rads.shift;
take $x % $rad;
$x div= $rad;
}
take $x if $x;
}
}
@colomon
colomon / gist:5678473
Last active December 17, 2015 21:59 — forked from pmichaud/gist:5678418
sub msb(Int $self) {
return Nil if $self == 0;
return 0 if $self == -1;
my $msb = 0;
my $x = $self;
$x = ($x + 1) * -2 if $x < 0; # handle negative conversions
while $x > 0xff { $msb += 8; $x +>= 8; }
if $x > 0x0f { $msb += 4; $x +>= 4; }
if $x +& 0x8 { $msb += 3; }
elsif $x +& 0x4 { $msb += 2; }
@colomon
colomon / fringe.p6
Created January 21, 2014 13:29 — forked from grondilu/fringe.p6
proto fringe($) { gather { {*} } }
multi fringe (Pair $node) { take fringe $_ for $node.kv }
multi fringe (Any $leaf) { take $leaf }
sub samefringe ($a, $b) { fringe($a) eqv fringe($b) }
my $a = 1 => 2 => 3 => 4 => 5 => 6 => 7 => 8;
my $b = 1 => (( 2 => 3 ) => (4 => (5 => ((6 => 7) => 8))));
my $c = (((1 => 2) => 3) => 4) => 5 => 6 => 7 => 8;