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 / 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
}
@rcmlz
rcmlz / calculator-the-game.raku
Created January 30, 2024 13:50
Implementing simple BFS in Raku for an App called Calculator-The-Game
use MONKEY-SEE-NO-EVAL;
class Node {
has $.value;
has @.operations = [];
}
sub calculate(Int $start-value, Int $target-value, Int $max-steps, @possible-operators --> List) {
my @queue = [ Node.new(value => $start-value), ];
{
"linux": {
"green": [
"App::Mi6",
"App::Prove6",
"App::Workflows::Github",
"Benchmark",
"DOM::Tiny",
"Data::Summarizers",
"Grammar::Common",
@rcmlz
rcmlz / shapes-class-demo.raku
Last active October 24, 2023 09:15
Class, Subclass, Role Demo of Raku - interestingly a Role can be attached to a Class as well as to an Instance of Class
class Client {
has @.pairs-of-shapes;
method intersect-all {
gather {
for @!pairs-of-shapes -> ($s1, $s2) {
take $s1.intersect($s2)
}
}
}
@rcmlz
rcmlz / pre-post-condition-demo.raku
Last active October 20, 2023 19:24
PRE and POST condition check by compiler/runtime
class A {
has @.list of Int = [];
has Str $.id;
method m(Int $a, Str $b --> Array of Int) {
PRE { $a > 0 }
POST { $a ∈ @!list and $!id eq $b }
@!list.push: $a;
$!id = $b;