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 $id = 1; | |
my %customer = ( | |
$id++ => { :name('aa') :age(9) }, | |
$id++ => { :name('bb') :age(22) }, | |
$id++ => { :name('cc') :age(11) }, | |
); | |
say 'Sorted by age, descending:'; | |
say "ID# {.key}) Name: {.value<name>}, Age: {.value<age>}" | |
for %customer.sort( -*.value<age> ); |
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 soft; | |
my @log; | |
sub loggit (*@args) { | |
my $return = try { callwith(|@args) }; | |
#say &?ROUTINE.name; # Off by one call frame | |
#say (&::CALLER::&?ROUTINE).name; # just plain wrong | |
#.say for Backtrace.new.list; # the wrapped sub name doesn't appear in the backtrace |
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 $actions = Moedict::Actions.new(); | |
my @objects; | |
my @data = .lines # or whatever | |
(^@data).hyper.map: { | |
@objects[$_] = Moedict.parse(@data[$_], :actions($actions)) or die "$!"; | |
} |
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
# Characters are expensive, and the accountants tell me we can’t hand them out | |
# willy-nilly anymore. Given a string x and a character y, how many times does y | |
# occur in x? | |
put "\nMultiplicity"; | |
sub Multiplicity (Str $a, Str $b) { $a.comb.Bag{$b} } | |
for < fhqwhgads h mississippi s life . > | |
-> $a, $b { put "$a, $b: ", Multiplicity $a, $b } |
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
# Implementing a fixed bit, nominally unsigned Integer class | |
# Major bummer; can not instantiate usefully in a $ sigiled scalar | |
class Fixed-Int { | |
has $!var handles <FETCH Str Numeric> = 0; | |
has $!bits; | |
has $!mask; | |
submethod BUILD (Int :bits(:$bit)) { $!bits = $bit; $!mask = 2**$!bits - 1 } |
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; | |
use SDL2::Raw; | |
my int ($w, $h) = 320, 240; | |
SDL_Init(VIDEO); | |
my SDL_Window $window = SDL_CreateWindow( | |
"White Noise - Raku", | |
SDL_WINDOWPOS_CENTERED_MASK, SDL_WINDOWPOS_CENTERED_MASK, |
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
multi expand-tree ( Bag $tree ) { | |
bag(bag(bag()) (+) $tree) (+) | |
[(+)] ( | |
$tree.keys ==> map { | |
$^a.&expand-tree.map: * (+) ( $tree (-) bag($^a) ) | |
} | |
); | |
} | |
multi expand-trees ( Bag $trees ) { |
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
// ==UserScript== | |
// @name Language links | |
// @description Adds language parameters to category links on Rosettacode.org | |
// @author thundergnat | |
// @namespace mailto:[email protected] | |
// @version 0.8 | |
// @updateURL https://gist.github.com/thundergnat/c5a86a6d5e0018ac67bdea3fc48786a0#file-language_links-user-js | |
// @downloadURL https://gist.github.com/thundergnat/c5a86a6d5e0018ac67bdea3fc48786a0#file-language_links-user-js | |
// @match *://rosettacode.org/wiki/Category* | |
// @icon https://www.google.com/s2/favicons?domain=www.rosettacode.org |
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
// ==UserScript== | |
// @name Toggle syntax highlighting | |
// @namespace http://tampermonkey.net/ | |
// @version 0.2 | |
// @description toggle syntax highlighting on task pages | |
// @author thundergnat | |
// @match *://rosettacode.org/wiki/* | |
// @icon https://www.google.com/s2/favicons?domain=rosettacode.org | |
// @grant none |
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 %*SUB-MAIN-OPTS = :named-anywhere; | |
use Text::Sorensen :sorensen; | |
use JSON::Fast; | |
my $hashfile = './Sorenson-chars.json'; | |
unit sub MAIN ( $phrase, $head = 10, :$ge = 0.5 ); | |
my %out; |