Skip to content

Instantly share code, notes, and snippets.

View dmaestro's full-sized avatar

dmaestro

  • Traverse City, MI USA
View GitHub Profile
@dmaestro
dmaestro / 8queens.pl
Created October 12, 2017 23:28
Fundamental Solutions to Eight Queens Problem
use v6;
constant size := 8;
my @corners = map { $_[0] * size + $_[1] }, ((0, size-1) X (0, size-1));
our class Square is Int {
has Int $!piece;
method new (|) {
Metamodel::Primitives.rebless(
@dmaestro
dmaestro / unquote_via_eval.pm
Created January 3, 2018 15:24
Rakudo* 2017.10 failure
#!/usr/bin/env perl6
use v6;
use MONKEY-SEE-NO-EVAL;
# "project_gbclient_t_controller_signup_process_purchase_validation_07-wordpress_blog_title_t"
my @raw-names = $*IN.lines.grep({ / ^ '"' <[ \w - ]>+ '"' $ / })».EVAL;
.say for @raw-names;
# cat 185_valid_test_names.txt | MVM_SPESH_DISABLE= bin/unquote_via_eval.p6 | wc -l
# 108 [ non-repeatable count ]
# cat 185_valid_test_names.txt | MVM_SPESH_DISABLE=1 bin/unquote_via_eval.p6 | wc -l
@dmaestro
dmaestro / TestD.pm6
Created September 9, 2018 21:44
Delegation fails with "Cannot invoke this object" when this package is used
unit package TestD;
role R {
method foo( --> Int ) { ... }
}
class C {
has R $.delegate
handles *
is required;
@dmaestro
dmaestro / CodePointComparison.txt
Created March 19, 2019 02:57
Example of processing codepoint sequences in Perl 6
doug$ cat z2.pl6
use v6;
my $s = "Zoé";
.chr.print for |$s.NFC, 10;
.chr.print for |$s.NFD, 10;
doug$ perl6 z2.pl6
Zoé
Zoé
perl6 z2.pl6 | perl6 -e '$*IN.encoding(<utf8>); my $z1 = $*IN.get; my $z2 = $*IN.get; say $z1 eq $z2'
True
@dmaestro
dmaestro / z-length_negative_assertion.t
Created March 24, 2019 12:29
Test for rakudo/rakudo issue #2791
use v6;
grammar Chord {
rule TOP { <key> \S* }
regex bare-key { <key> <!before \S > }
regex bare-key-one { <key> [ <!before \S > | $ ] }
regex bare-key-two { <key> <!before <:!Space> > }
token natural-note { <[ A..G ]> }
token accidental { <[ \# b ]> }
regex key { <natural-note> <accidental>? }
@dmaestro
dmaestro / Latin-1-bytes-and-perl-6.txt
Created April 6, 2019 21:07
Question by Eric Lindblad about perl 6 and terminal encoding
doug@ender:~/study$ perl6 -e 'say "Hôtel"'
Hô¿½xF4tel
doug@ender:~/study$ perl6 -e 'say "Hôtel".chars'
5
doug@ender:~/study$ perl6 -e 'say "Hôtel"' | od -Ax -t x1
000000 48 f4 8f bf bd 78 46 34 74 65 6c 0a
00000c
doug@ender:~/study$ perl6 -e 'utf8.new(0xF4, 0x8f, 0xbf, 0xbd).Str.ord.&{ "%x".sprintf($_) }.say'
10fffd
doug@ender:~/study$ perl6 -e 'utf8.new(0xF4, 0x8f, 0xbf, 0xbd).Str.uniname.say'