This file contains 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
#!/usr/bin/env perl6 | |
use v6; | |
use Term::termios; | |
use NativeCall; | |
class FILE is repr('CPointer') { | |
sub fdopen(Int, Str) returns FILE is native { * } | |
method new(Int $fd) { | |
fdopen($fd, "r"); | |
} |
This file contains 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
#!perl6 | |
use Audio::PortMIDI; | |
sub MAIN(Int :$samplerate = 44100, Int :$frequency = 440, Int :$channel = 9, Int :$device = 3, Int :$bpm = 120, :$part) { | |
my $event-type = NoteOn; | |
my $pm = Audio::PortMIDI.new; | |
my $stream = $pm.open-output($device, 32); |
This file contains 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
role Bop[::Zub] { | |
has Zub $.bap; | |
}; | |
role Foo[::Bap] { | |
has Bap $.bop; | |
}; | |
my $f = Str; | |
my $d = class {} but Bop.^parameterize($f); |
This file contains 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 HTTP::Server::Tiny; | |
my $s = supply { | |
whenever Supply.interval(1) { | |
emit("data: { DateTime.now }\r\n\r\n".encode); | |
} | |
} | |
sub app(%env) { | |
return 200, [ Cache-Control => 'must-revalidate, no-cache',Content-Type => 'text/plain; charset=utf-8, text/event-stream' ], $s; |
This file contains 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
role Zub[::T] { | |
proto method CALL-ME(|c) { * } | |
multi method CALL-ME(Mu:D $self) { | |
} | |
multi method CALL-ME(Mu:D $self, T $i) { | |
} | |
} | |
multi sub trait_mod:<is> (Method $m, :$foo!) is export { | |
$m does Zub[Int]; | |
} |
This file contains 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
#!perl6 | |
use NativeCall; | |
my $samplerate = 44100; | |
my $frequency = 440; | |
sub gen-sin(Int $sample-rate, Int $frequency) { | |
gather { | |
loop { |
This file contains 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 Foo { | |
has Promise $.promise = Promise.new; | |
has Str $.name = ('a' .. 'z').pick(8).join(''); | |
} | |
class Container { | |
has Foo %.foos; | |
method add-foo(Foo $f) { | |
say "adding { $f.name }"; |
This file contains 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; | |
class Timeval is repr('CStruct') { | |
has int64 $.seconds; | |
has int64 $.microseconds; | |
} | |
sub select(int64, Pointer, Pointer, Pointer, Timeval) is native { * } | |
my $tv = Timeval.new(seconds => 10, microseconds => 0); |
This file contains 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 @dists; | |
for $*REPO.repo-chain -> $r { | |
if $r.can('prefix') { | |
if $r.prefix.child('dist').e { | |
for $r.prefix.child('dist').dir -> $d { | |
my $dist-data = from-json($d.slurp); | |
push @dists, Distribution.new(|$dist-data); | |
} | |
} | |
} |
This file contains 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; | |
my sub _index_buf(Blob $input, Blob $sub) { | |
my $end-pos = 0; | |
while $end-pos < $input.bytes { | |
if $sub eq $input.subbuf($end-pos, $sub.bytes) { | |
return $end-pos; | |
} | |
$end-pos++; | |
} |