Skip to content

Instantly share code, notes, and snippets.

View AlexDaniel's full-sized avatar

Aleks-Daniel Jakimenko-Aleksejev AlexDaniel

  • Tallinn, Estonia
View GitHub Profile
@AlexDaniel
AlexDaniel / test.pl6
Last active July 8, 2017 15:51 — forked from dogbert17/test.pl6
Fails when run normally but works with MVM_SPESH_DISABLE=1
use nqp;
{
constant $read-file = "README.md".IO;
$read-file.IO.r;
for ^1000 {
my $p = Proc::Async.new( | «/bin/cat $read-file» );
my $output = '';
$p.stdout.tap: -> $s { $output ~= $s; };
await $p.start;
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@AlexDaniel
AlexDaniel / #! perl6
Last active September 3, 2016 02:38
Shebangs in different perl 6 modules (read “|” as “/”)
path-iterator
@AlexDaniel
AlexDaniel / doc.perl6_checklink
Last active July 26, 2020 12:04
doc.perl6.org broken links
multi sub infix:<+>(Unit $x, Unit $y) {
if (not $x.isSameUnit($y)) {die "Units do not match.";}
return Unit.new(magnitude => $x.magnitude + $y.magnitude, units => $x.units);
}
my $a = Units::Unit.new(magnitude => 1.2, units => ("m" => 1));
my $b = Units::Unit.new(magnitude => 5.0, units => ("m" => 1));
say $a + $b;
@AlexDaniel
AlexDaniel / primes.p6
Created May 4, 2016 13:07
Pointless benchmark
#!/usr/bin/env perl6
sub get_primes(int $n) {
return () if $n < 2;
return (2) if $n == 2;
my int @s = ();
loop (my int $i = 3; $i <= $n; $i+=2) {
@s.push($i);
}
my class a {
has @.b;
method get-flat { @!b.map(|*.get-flat); }
method p {
say 'A: ', WHAT $.get-flat;
# why doesn't this loop act like D: below?
for self.get-flat() -> $c {
say 'B: ', $c.perl
}
}
@AlexDaniel
AlexDaniel / splits.md
Last active February 17, 2016 16:52
Array splits

Is there a cute Perl 6 way to take an array (say ‘a’..‘d’) and get all head/tail partitions of it (e.g. (<a>, <b c d>), (<a b>, <c d>), (<a b c>, <d>))?

Sure! Pick one:

my @a = a..e; say (@a[^$_, $_..*] for 1..^@a);
my @b = a..e; say (1..^@b).map: {@b[^$_, $_..*]};
my @c = a..e; say (@c.rotor($_, ∞, :partial) for 1..^@c);
my @z = a..e; say @z[0..*-2].keys.map: {@z[0..$_, $_^..*]}; # same as b
my @d = a..e; say (1..^@d).map: {@d.rotor: $_, ∞, :partial};