Skip to content

Instantly share code, notes, and snippets.

View Restricted.rakumod
use uniname-words;
constant $stdin-text = qq:to/EOH/;
I ♥ Raku!
1 22 333 4444 55555 6565656
3.14159265358979323846264338327950288419716939937510582097494459
A line with the number 42.
We may need some "quotes".
A backslash \\
would be nice too.
View Restricted.rakumod
use uniname-words;
constant $stdin-text = qq:to/EOH/;
I ♥ Raku!
1 22 333 4444 55555 6565656
3.14159265358979323846264338327950288419716939937510582097494459
A line with the number 42.
We may need some "quotes".
A backslash \\
would be nice too.
View gist:c69612be47e078d090467bf3972fc3f2
sub limit-rate(Supply $in, $per-seconds = 1 --> Supply:D) {
my $out = Supplier::Preserving.new;
start react whenever $in -> \value {
$out.emit: value;
sleep(1 / $per-seconds);
}
$out.Supply;
}
View keymap.raku
use v6.d;
constant @keymap = (0x1b, 0x5b, 0x31, 0x31, 0x7e) => 'F1', (0x61,) => 'a', (0x0a,) => 'ENTER';
use Term::ReadKey;
react {
whenever key-pressed( :!echo ) {
state @stack;
@stack.push: .ord;
# .ord.fmt('%02x').put; # uncomment to discover new keycodes
View nncal.raku
multi sub MAIN(Bool :$S, Bool :$three) {
constant @months = <January February March April May June July August September October November December>;
my @week-days = $S ?? <Su Mo Tu We Th Fr Sa> !! <Mo Tu We Th Fr Sa Su>;
my &start-week-day = $S ?? { .[0].day-of-week % 7 } !! { .[0].day-of-week - 1 }
my $month-offset = $three ?? -1 !! 0;
loop {
$_ = now.Date.truncated-to('month');
$_ = .earlier(:month(1)) if $three;
@gfldex
gfldex / foo.txt
Created September 29, 2022 22:54
View foo.txt
ub exclude(@a, $elems) {
say (0..^$elems).grep: * !~~ @a
}
my @a = 1..10;
@a[&exclude.assuming(2..3)].say;
View Restricted.rakumod
use uniname-words;
constant $stdin-text = qq:to/EOH/;
I ♥ Raku!
1 22 333 4444 55555 6565656
3.14159265358979323846264338327950288419716939937510582097494459
A line with the number 42.
We may need some "quotes".
A backslash \\
would be nice too.
View coerce-subsets.raku
use v6.*;
class Type is Int { }
subset Even of Type where * %% 2;
Type.^add_method('COERCE', my method COERCE(|) {
my Even $retval = 42
});
sub foo(Even() $_) { .&dd }
foo ‘answer’;
View spinner.raku
use v6.d;
# my @loop = |("\x1F550" .. "\x1F55B") xx *;
# react whenever Supply.interval(0.1) {
# state $it = @loop.iterator;
# print "\b\b" ~ $it.pull-one;
# }
sub progress-bar($max, $width = 10) {
View did-you-know.raku
# Did you know, you can use the method `.none` (and friends) of `Any` in a method call chain?
my \fib = 1, 1, * + * … ∞;
say so fib[^10].none.is-prime;
say so fib[^10].any.is-prime;
say so fib[5..9].one.is-prime;
# A `Junction` is a parallel value that whats to collaps into a single `Bool`. Any method call to a definite `Junction` will be forwarded to its members, coerced to `Bool` and collapsed with the `Junction`-type. The above `any`-form is equivalent to: