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
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
}
}
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 / 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;
use nqp;
my $html;
my $proc = run "wget", "-o", "/dev/null", "-O", "-", "https://www.fimfiction.net/bookshelf/149291/", :out;
$html = $proc.out.slurp-rest;
say "html is " ~ $html.chars ~ " chars";
nqp::force_gc;
say "/proc/$*PID/statm".IO.lines[0].split(/\s/)[5] * 4096 / 1024
@AlexDaniel
AlexDaniel / mustache-hyper.pl6
Last active August 20, 2017 16:43 — forked from scmorrison/mustache-hyper.pl6
Perl 6 - Template::Mustache.render dies with hyper
#!/usr/bin/env perl6
use lib ‘data/all-modules/softmoth/p6-Template-Mustache’;
use v6;
#use v6.d.PREVIEW;
use Template::Mustache;
my $html = q:to/EOF/;
<html>
{{> head }}
@AlexDaniel
AlexDaniel / rc-authors.p6
Last active February 26, 2018 23:10
Reliably works on 2017.11. reliably fails on 2017.12 and later.
use lib ‘data/all-modules/github/sergot/datetime-parse/lib’;
use lib ‘data/all-modules/github/perl6/Perl6-MIME-Base64/lib’;
use lib ‘data/all-modules/github/perl6-community-modules/uri/lib’;
use lib ‘data/all-modules/github/supernovus/perl6-http-status/lib’;
use lib ‘data/all-modules/github/sergot/http-useragent/lib’;
use lib ‘data/all-modules/github/sergot/perl6-encode/lib’;
use lib ‘data/all-modules/github/perlpilot/p6-File-Temp/lib’;
use lib ‘data/all-modules/github/labster/p6-file-directory-tree/lib’;
use lib ‘data/all-modules/cpan/TIMOTIMO/JSON-Fast/lib’;
use lib ‘data/all-modules/github/perl6-community-modules/uri/lib’;
@AlexDaniel
AlexDaniel / query
Created June 25, 2018 22:57 — forked from Whateverable/query
greppable6
\<\-\>
@AlexDaniel
AlexDaniel / query
Last active July 13, 2018 12:17 — forked from Whateverable/query
greppable6
if[^{]+=(?!=)[^{]+\{
use v6;
my Int @cache is default(0);
my $sum89 = 0;
for (1..567) -> $i {
@cache[$i] = calc-chain($i);
}
for (1..400_000) -> $i {
@AlexDaniel
AlexDaniel / foo.p6
Last active September 5, 2018 20:29 — forked from bazzaar/gist:914a5c3e6fd69e45de7ecce9d16e360b
for loop with .lines
#use Slang::Tuxic;
#use Text::CSV;
#use File::Find;
my $csv_line = ‘foo’; # Text::CSV.new (eol => "\n");
my $cols = 49;
my @IO-object-list = < a b c >; #find(:dir</home/user1/documents/animals>, :type<file>, :name(/armadillos_201<[4..8]>.*\.csv/));
for @IO-object-list -> $IO-object {