Skip to content

Instantly share code, notes, and snippets.

View jonathanstowe's full-sized avatar

Jonathan Stowe jonathanstowe

View GitHub Profile
@jonathanstowe
jonathanstowe / gist:45c2e6fc60d0d770281d
Created June 16, 2015 21:36
Rule of 3 say it has to happen
#!perl6
role NativeAccessor[&get, &set] {
method CALL-ME(*@args) is rw {
my $self = @args[0];
Proxy.new(
FETCH => sub ($) {
&get($self);
},
STORE => sub ($, $val ) {
use NativeCall;
class Foo is repr("CStruct") {
method foo(Mu:U $type, Int $a ) {
my @buff := CArray[$type].new;
my $ctype = $type ~~ Num ?? Num !! Int;
@buff[$_] = $ctype(0) for ^(10 * $a);
}
}
@jonathanstowe
jonathanstowe / gist:40ae924c79342d3ac244
Created July 2, 2015 12:08
Async echo client example
await IO::Socket::Async.connect('localhost',3333).then( -> $p {
if $p.status == Kept {
my $conn = $p.result;
my $p2 = $conn.send('Hello, Perl 6');
my $p3 = Promise.new;
$conn.chars_supply.tap(-> $str { say $str; $p3.keep});
await $p3;
$conn.close;
}
});
Cannot call AUTOGEN(Audio::Encode::LameMP3: IntTypedCArray[int16], Int, :raw); none of these signatures match:
(Audio::Encode::LameMP3 $: @left, @right, *%_ --> Buf)
(Audio::Encode::LameMP3 $: @frames, *%_ --> Buf)
(Audio::Encode::LameMP3 $: @left, @right, :$raw!, *%_ --> RawEncode)
(Audio::Encode::LameMP3 $: @frames, :$raw!, *%_ --> RawEncode)
(Audio::Encode::LameMP3 $: IntTypedCArray[int16] $left, IntTypedCArray[int16] $right, Int $frames, *%_ --> Buf)
(Audio::Encode::LameMP3 $: IntTypedCArray[int16] $frames-in, Int $frames, *%_ --> Buf)
(Audio::Encode::LameMP3 $: IntTypedCArray[int16] $left, IntTypedCArray[int16] $right, Int $frames, :$raw!, *%_ --> RawEncode)
(Audio::Encode::LameMP3 $: IntTypedCArray[int16] $frames-in, Int $frames, :$raw!, *%_ --> RawEncode)
in sub MAIN at examples/streamfile-encode:37
@jonathanstowe
jonathanstowe / gist:a76c110ef81f0a218824
Created July 22, 2015 07:46
Apparent precompilation bug in Lock
The below only happens when the module containing the OO::MOnitors "monitor" is pre-compiled: 28 of OO/Monitors.pm is in a catch, 25 is $!.lock
Cannot invoke this object (REPR: Null, cs = 0)
at lib/OO/Monitors.pm:28 (/home/jonathan/.rakudobrew/moar-nom/install/share/perl6/site/lib/OO/Monitors.pm.moarvm::11)
from <unknown>:1 (/home/jonathan/.rakudobrew/moar-nom/install/share/perl6/site/lib/OO/Monitors.pm.moarvm::18)
from lib/OO/Monitors.pm:25 (/home/jonathan/.rakudobrew/moar-nom/install/share/perl6/site/lib/OO/Monitors.pm.moarvm::53)
from src/gen/m-Metamodel.nqp:3560 (/home/jonathan/.rakudobrew/moar-nom/install/share/nqp/lib/Perl6/Metamodel.moarvm:enter:28)
from src/gen/m-CORE.setting:4763 (/home/jonathan/.rakudobrew/moar-nom/install/share/perl6/runtime/CORE.setting.moarvm:CALL-ME:60)
from src/gen/m-BOOTSTRAP.nqp:2752 (/home/jonathan/.rakudobrew/moar-nom/install/share/nqp/lib/Perl6/BOOTSTRAP.moarvm::93)
from lib/Audio/Libshout.pm:697 (/home/jonathan/.rakudobrew/moar-nom/install/share/perl6/si
role Singleton {
my $instance;
method new(|c) {
if not $instance.defined {
$instance = self.bless(|c);
}
$instance;
}
}
@jonathanstowe
jonathanstowe / gist:7bba0a218023b9caa5b9
Created August 17, 2015 13:43
add_multi_method has me confused
role MetamodelX::StaticHOW {
method add_method(Mu \type, $name, $code) {
say "adding $name with { $code.gist }";
nextsame;
}
method add_multi_method(Mu \type, $name, $code) {
say "adding multi $name with { $code.gist }";
nextsame;
}
}
#!perl6
use Term::ReadKey:from<Perl5>;
ReadMode(4);
loop {
my $a = ReadKey(0);
if $a.defined {
use v6;
await IO::Socket::Async.connect('localhost',3333).then( -> $p {
if $p.status {
given $p.result {
.print('Hello, Perl 6');
react {
whenever .chars-supply() -> $v {
$v.say;
done;
#!/usr/bin/env perl6
use v6;
use NCurses;
constant numstars = 100;
constant screen-x = 80;
constant screen-y = 24;
constant max-speed = 4;