This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Graph { | |
has array[int] %!repr{Int}; | |
has int $.elems; | |
submethod BUILD(Str:D :$input) { | |
# Adjacenyc matrix | |
($!elems, my $edges) = $_[0].Int, $_[1..*] given $input.lines; | |
%!repr = 1..$!elems Z=> array[int].new(0 xx $!elems) xx $!elems; | |
for $edges».split(' ')».Int.flat -> @e { | |
my int ($x, $y) = @e[0..1]; | |
++%!repr{$x}[$y - 1]; ++%!repr{$y}[$x - 1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $text = open 'test.txt'; | |
constant CHUNK_SIZE = 5; | |
constant Vowels = <a e i o u A E I O U>.Set; | |
constant Consonants = <B C D F G H J K L M N P Q R S T V W X Y Z b c d f g h j k l m n p q r s t v w x y z>.Set; | |
sub channeled { | |
my ($read, $parsed) = Channel.new xx 2; | |
reader($text, $read); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my IO::Path $headers = | |
$*CWD.child('vendor').child('fluidsynth').child('fluidsynth').child('include').child('fluidsynth'); | |
my Str:D $synth-header = $headers.child('synth.h').slurp; | |
my %types = | |
char_star => 'Str', | |
constchar_star => 'Blob', | |
constint_star => 'Pointer[int64]', | |
constdouble_star => 'Pointer[num64]', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# No need for new/BUILD if you accept a longer instantiation | |
class FuzzyNum { | |
has Num $.i; | |
method gist { $!i.gist } | |
}; | |
# Must be multi, otherwise overwrites all + operators | |
multi sub infix:<+>(FuzzyNum $a, FuzzyNum $b) { | |
FuzzyNum.new(i => $a.i + $b.i + rand ** rand) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use HTML::MyHTML | |
# basic init | |
my HTML::MyHTML $parser .= new; | |
# gather some html | |
my $website = qx{curl -s http://www.example.com}; | |
# parse html | |
$parser.parse($website); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pm6 --argument-names name --description="A Perl 6 module scaffolder" | |
set path "$HOME/github/$name" | |
git init -q -- $path | |
mkdir -- "$path/lib"; and touch -- "$path/lib/$name.pm6" | |
mkdir -- "$path/t"; and mkdir -- "$path/eg" | |
echo ".precomp" > "$path/.gitignore" | |
echo "# $name" > "$path/README.md" | |
echo "{ | |
\"name\" : \"$name\", | |
\"version\" : \"0.1.0\", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub prime-reaction(@ (Int $a, Int $b)) { | |
$a > $b && $a %% $b ?? [($a div $b), $b] !! [$a, $b] | |
} | |
my @molecules = 2..101; | |
sub mix-and-react(@mols is raw) { | |
my @mixed = (@mols.pick: *).rotor(2); | |
@mols = @mixed.map(&prime-reaction).flat; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
use Net::Curl::NativeCall; | |
constant RTURL = 'https://rt.perl.org/REST/1.0/'; | |
my Hash @tickets; | |
with curl_easy_init() { | |
my Str $body; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
use Net::Curl::NativeCall; | |
with curl_easy_init() { | |
# curl_easy_setopt($_, CURLOPT_COOKIESESSION, +True); | |
my Str $body; | |
my $login = 'user=guest&pass=guest'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use NativeCall; | |
use Net::Curl::NativeCall; | |
use Email::Simple; | |
constant EmailPassword = %*ENV<P6BUG_EMAIL_PW>; | |
constant FROM = '[email protected]'; | |
constant TO = '[email protected]'; | |
constant CC = '[email protected]'; | |
constant Email = Email::Simple.new( | |
[['To', TO], ['FROM', FROM], ['CC', CC], ['Subject', 'Testing']], |