Skip to content

Instantly share code, notes, and snippets.

View lizmat's full-sized avatar
💭
Functioning within parameters

Elizabeth Mattijsen lizmat

💭
Functioning within parameters
View GitHub Profile
@lizmat
lizmat / gist:11404980
Created April 29, 2014 16:15
Duration primitives
sub term:<1sec>() { Duration.new(1) }
sub term:<1second>() { Duration.new(1) }
sub term:<1min>() { Duration.new(60) }
sub term:<1minute>() { Duration.new(60) }
sub term:<1hour>() { Duration.new( 60 * 60 ) }
sub term:<1day>() { Duration.new( 24 * 60 * 60 ) }
sub term:<1week>() { Duration.new( 7 * 24 * 60 * 60 ) }
sub postfix:<secs>($secs) { Duration.new($secs) }
sub postfix:<seconds>($seconds) { Duration.new($seconds) }
@lizmat
lizmat / Proxy huh????
Last active August 29, 2015 14:01
Can someone explain why FETCH is called *EIGHT* times ???
class A is Hash {
method at_key(A:D $hash: $k) {
Proxy.new(
FETCH => {
say "in FETCH with $k";
$hash.exists_key($k) ?? $hash{$k} !! Int;
},
STORE => -> $old, $new {
if $new > 0 {
$hash{$k} = $new;
@lizmat
lizmat / gist:80b8c5b3a02f8a742c0c
Created May 12, 2014 23:34
diff for making BagHash<unknown_key>-- return Int rather than 0
diff --git a/src/core/BagHash.pm b/src/core/BagHash.pm
index 21a35b8..960ea99 100644
--- a/src/core/BagHash.pm
+++ b/src/core/BagHash.pm
@@ -1,39 +1,31 @@
-my class BagHash does Baggy {
+my class BagValue is Int {
+ has $!hash;
+ has $!key;
+
@lizmat
lizmat / gist:48b2c6e3a246eb9f0e25
Last active August 29, 2015 14:01
using signal to have a loop iteration finish
for ^Inf -> $job {
last if state $x;
state $tap = signal(SIGINT).tap( {
say "\b\bwaiting for job #$job to be done";
$x = True;
} );
LAST { $tap.close }
my $working = 5.rand;
say "job #$job for {$working.fmt('%.2f')} seconds";
@lizmat
lizmat / gist:2bbcb4f8799f689da1ff
Created June 16, 2014 13:31
reliable jvm fail for S04-phasers/in-loop.t
$ perl6-j t/spec/S04-phasers/in-loop.rakudo.jvm
1..3
Exception in thread "main" org.perl6.nqp.runtime.UnwindException
at org.perl6.nqp.runtime.ThreadContext.<init>(ThreadContext.java:119)
at org.perl6.nqp.runtime.GlobalContext.getCurrentThreadContext(GlobalContext.java:324)
at org.perl6.nqp.runtime.GlobalContext.<init>(GlobalContext.java:239)
at org.perl6.nqp.runtime.CompilationUnit.enterFromMain(CompilationUnit.java:56)
at perl6.main(gen/jvm/main.nqp)
# t/spec/foo.t
use Test;
plan 1;
#?rakudo todo 'huh?'
throws_like( { die }, X::Comp);
=============================
@lizmat
lizmat / gist:72dc142c2aac6b402b64
Created August 1, 2014 10:50
current rakudo spectest failures on parrot
t/spec/S02-literals/radix.rakudo.parrot (Wstat: 0 Tests: 7 Failed: 0)
Parse errors: Bad plan. You planned 135 tests but ran 7.
t/spec/S02-magicals/DISTRO.rakudo.parrot (Wstat: 0 Tests: 24 Failed: 0)
Parse errors: Bad plan. You planned 28 tests but ran 24.
t/spec/S02-magicals/KERNEL.rakudo.parrot (Wstat: 256 Tests: 32 Failed: 1)
Failed test: 29
Non-zero exit status: 1
t/spec/S02-magicals/VM.rakudo.parrot (Wstat: 0 Tests: 29 Failed: 0)
Parse errors: Bad plan. You planned 32 tests but ran 29.
t/spec/S02-names/is_cached.t (Wstat: 512 Tests: 38 Failed: 2)
@lizmat
lizmat / gist:65d9e44743dffca1157c
Created August 4, 2014 09:42
Exporting dynamic variables delayed until runtime?
# ./Foo.pm
my sub EXPORT(*@a) {
say "in EXPORT";
( '$*FOO' => ++state $ ).hash;
}
============== works as expected
$ perl6 -I. -e 'use Foo; say $*FOO; { use Foo; say $*FOO }; say $*FOO'
in EXPORT
@lizmat
lizmat / gist:4f31120e7ca6bbebc16d
Created September 15, 2014 21:37
diff for adding CCLASS_CRLF
diff --git a/docs/ops.markdown b/docs/ops.markdown
index 30554c7..a71c968 100755
--- a/docs/ops.markdown
+++ b/docs/ops.markdown
@@ -1685,6 +1685,7 @@ constants below can be used in nqp as (e.g.) `nqp::const::CCLASS_ANY`.
* CCLASS_ALPHANUMERIC
* CCLASS_NEWLINE
* CCLASS_WORD
+ * CCLASS_CRLF
@lizmat
lizmat / gist:ab00347d5cc44a23c65b
Created October 20, 2014 21:55
take problems on JVM
sub ROLLPICKGRABN( # N times
$self, $count, @pairs is rw, :$keep
) is hidden_from_backtrace {
my Int $total = $self.total;
my Int $rand;
my Int $seen;
my int $todo = ($keep ?? $count !! ($total min $count)) + 1;
gather {
while $todo = $todo - 1 {