Skip to content

Instantly share code, notes, and snippets.

@dogbert17
dogbert17 / gist:ac2e37814987267451d3a04cfdad324a
Created May 28, 2016 14:48
Attempt to document method 'of' in class Hash
=head2 method of
Defined as:
method of
Usage:
Hash.of
@dogbert17
dogbert17 / gist:aee462bdb51ef1d71caf3915e449c3b3
Last active May 29, 2016 15:05
Attempt to document method default in class Array
=head2 method default
Defined as:
method default
Usage:
Array.default
@dogbert17
dogbert17 / gist:ca88f9827116cbc8db3b5c92096123c4
Last active May 30, 2016 17:16
Attempt to document method print-nl in class IO::Handle
=head2 method print-nl
method print-nl(IO::Handle:D: --> True)
Writes a newline to the filehandle. The newline marker defaults
to C<\n> unless another marker has been specified in the call to
L<open>.
my $fh = open 'path/to/file', :w, nl-out => "\r\n";
$fh.print("some text");
@dogbert17
dogbert17 / gist:b3f0aae68415e28903cd6c92d3bc40c2
Last active June 3, 2016 14:45
Attempt to document Mu.does
=head2 routine does
method does(Mu $type) returns Bool:D
Returns True if and only if the invocant conforms to type C<$type>.
my $d = Date.new('2016-06-03');
say $d.does(Dateish); # True (Date does role Dateish)
say $d.does(Any); # True (Date is a subclass of Any)
say $d.does(DateTime); # False (Date is not a subclass of DateTime)
=head2 routine categorize
Defined as:
multi sub categorize(&mapper, *@values) returns Hash:D
multi method categorize(List:D: &mapper) returns Hash:D
Usage:
categorize MAPPER, LIST
@dogbert17
dogbert17 / gist:1762f03949c76c8bb0d171725acfc73d
Created June 7, 2016 21:43
Attempt to document Baggy.kxxv
=head2 method kxxv
Defined as:
method kxxv(Baggy:D:) returns List:D
Returns a list of the keys of the invocant, with each key multiplied by its
weight. Note that C<kxxv> only works for C<Baggy> types which have integer
weights, i.e. L<Bag> and L<BagHash>.
@dogbert17
dogbert17 / gist:d7822b6db5daa88a372c835727bf0729
Last active June 9, 2016 14:45
SEGV with HEAD or whatever camelia is running after 55 sec on my machine
# This is Rakudo version 2016.05-79-g2095ed6 built on MoarVM version 2016.05-17-g6075599 implementing Perl 6.c.
# What is the value of the first triangle number to have over five hundred divisors?
use v6;
my $numFactors = 500;
my $sum = 0;
for (1...*) -> $term {
$sum += $term;
my $factors = (1..floor(sqrt($sum))).grep(-> $x { $sum % $x == 0} ).elems * 2;
$factors-- if floor(sqrt($sum)) == sqrt($sum);
@dogbert17
dogbert17 / gist:bedd7295290dd9490a521970aad85e64
Created June 9, 2016 15:31
SEGV under perl6-valgrind-m
dogbert@dogbert-VirtualBox ~ $ time perl6-valgrind-m euler-12.pl6
================================================================================================
This is Rakudo Perl 6 running in valgrind, a tool for debugging and profiling programs.
Running a program in valgrind usually takes *a lot* more time than running it directly,
so please be patient.
This Rakudo version is 2016.05.79.g.2095.ed.6 built on MoarVM version 2016.05.17.g.6075599,
running on ubuntu (14.04.3.LTS.Trusty.Tahr) / linux (3.19.0.32.generic)
------------------------------------------------------------------------------------------------
==7688== Memcheck, a memory error detector
==7688== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
@dogbert17
dogbert17 / gist:d6bc80230a7832f50202b76ca7a27c4a
Created June 10, 2016 13:45
Attempt to document Baggy.elems
=head2 method elems
Defined as:
method elems(Baggy:D:) returns Int:D
Returns the number of elements in the C<Baggy> object without
taking the individual elements weight into account.
my $breakfast = bag <eggs spam spam spam>;
@dogbert17
dogbert17 / gist:acbbd419534b528ca29bfacf4402ac81
Created June 10, 2016 18:24
Attempt to document Baggy.keys
=head2 method keys
Defined as:
method keys(Baggy:D:) returns List:D
Returns a list of all keys in the C<Baggy> object without taking
their individual weights into account as opposed to L<kxxv|#method kxxv>.
my $breakfast = bag <eggs spam spam spam>;