Skip to content

Instantly share code, notes, and snippets.

View rcmlz's full-sized avatar
💭
I may be slow to respond.

rcmlz

💭
I may be slow to respond.
View GitHub Profile
@rcmlz
rcmlz / sort-characters.raku
Created August 22, 2025 08:21
Sorting unicode characters in Raku
use Test;
my @input = <a ä b c A Ä Ö S T>;
my @expected = <A Ä Ö S T a ä b c>;
is-deeply @input.sort(*.NFKD), @expected.List
#use String::Utils <nomark>;
#is-deeply @input.sort.sort(&nomark), @expected.List
@rcmlz
rcmlz / Transposing-List-Of-Tuples.raku
Created August 14, 2025 15:30
How to reverse zip operation in Raku
use Test;
#| reverse the zip operation
sub reverse-zip(@list-of-tuples) {
[Z] @list-of-tuples
}
my @l1 = 1, 2, 3;
my @l2 = <a b c>;
my @input = zip @l1, @l2;
@rcmlz
rcmlz / Raku-Plain-Hyper-Race-Benchmark-Test.raku
Last active August 14, 2025 07:53
Parallel Code Execution in Raku
#!/usr/bin/env raku
# Find out for what problems Hyper and Race performs fast compared to single thread execution
# Note: for real world benchmarking you might want to use some library from
# https://raku.land/?q=Benchmark
my @problems = 2**8, 2**16;
my @batch-sizes = 2**8, 2**16;
my @degrees = 2, 4;
@rcmlz
rcmlz / gist:c2b08e3ed72bda09fb0eab158b92518d
Last active December 3, 2024 18:56
Grammar for AOC 2024 Day 2 Task a
#!/usr/bin/env raku
use v6.d;
use Grammar::Debugger;
grammar G_24_02_a {
token TOP { <report>+ }
token report { ^^ <level>+ $$ }
token level { <value> <.ws> ** 0..1 }
token value { <digit> ** 1..2 }
}
@rcmlz
rcmlz / param-check.raku
Last active September 24, 2024 16:35
How to know which parameter was wrong when calling this script from command line?
#!/usr/bin/env raku
use v6.d;
use variables :D;
# call 1 ok : raku param-check.raku --folder=/tmp --number=10
# call 2 not ok: raku param-check.raku --folder=/tmp1 --number=10
# call 3 not ok: raku param-check.raku --folder=/tmp --number=1
# Problem: Usage message for call 2 and call 3 look identical
sub MAIN(Str :$folder where *.IO.d = $*PROGRAM.parent(1),
UInt :$number where * > 1 = 100) {
@rcmlz
rcmlz / raku_grammars.raku
Last active May 30, 2024 17:12
Exercism Crypto Square Task - using Grammars
grammar Splitter {
# as many times as possible size $m, then sizes $n, until entire string is consumed
token TOP ( $*m, $*n ) { [:!r <long>+] <short>+ } # no ratchet for <long>, needs to look backwards to make <short> match
token long { \w ** {$*m} }
token short { \w ** {$*n} }
}
my @tests = [
['thisisfun', 3, 3, <thi sis fun>, 'three times len 3'],
['thisisfunxx', 3, 2, <thi sis fun xx>, 'three times len 3, one time len 2'],

A sensible NixOS Xfce Configuration

NixOS provides good support for the Xfce desktop environment out-of-the-box, but the defaults are minimal. The files in this Gist provide a more complete experience, including a suite of basic software and plugins as well as an optional home-manager configuration for theming.

The key additions to the default Xfce provided by NixOS are:

  • Complete bluetooth / audio support with panel indicators and apps
  • LightDM with theme
  • Extra Xfce apps for calendaring, disk partitioning, etc.
  • Various quality-of-life improving non-essentials
unit module ZebraPuzzle;
enum Brand is export <Chesterfield Kools LuckyStrike OldGold Parliament>;
enum Color is export <Blue Green Ivory Red Yellow>;
enum Drink is export <Coffee Milk OrangeJuice Tea Water>;
enum Nationality is export <Englishman Japanese Norwegian Spaniard Ukrainian>;
enum Pet is export <Dog Fox Horse Snails Zebra>;
sub get-nationality ($subject) is export {
#There are five houses.
@rcmlz
rcmlz / daily-joke.raku
Last active February 28, 2024 10:53
This script is used to replace "fortune" in the bash command "fortune | cowsay | lolcat" - and is intended to be used at the start of a lecture.
#!/usr/bin/env raku
use WWW::OpenAI;
use WWW::MistralAI;
my $prompt = 'Tell a Computer Science joke suitable for high school students!';
#my $prompt = 'Create an Icebreaker tasks for high school students!';
if not (%*ENV<MISTRAL_API_KEY>:exists or %*ENV<OPENAI_API_KEY>:exists) {
note "loading API keys to ENV";
@rcmlz
rcmlz / solution.raku
Last active February 1, 2024 17:49
usage: echo "1\nd5" > test1.in; raku solution.raku < test1.in
#!/usr/bin/env raku
# https://codeforces.com/gym/104921/problem/A
constant @nums = 1..8;
constant @chars = 'a'..'h';
sub MAIN {
for lines.skip -> $task { # lines() without an invocant object defaults to $*IN.lines(), skip first line (number of testcases)
algo1($task).keys.join("\n").put
}