Skip to content

Instantly share code, notes, and snippets.

@lucs
lucs / format.raku.memo
Created April 23, 2025 17:09
Can I haz reformatted?
This:
say ('baz 42 k9 foo' ~~ m:g/ \d+ /).raku
prints this:
(Match.new(:orig("baz 42 k9 foo"), :from(4), :pos(6)), Match.new(:orig("baz 42 k9 foo"), :from(8), :pos(9)))
Is there some tool that exists to reformat strings like that to something like this?:
@lucs
lucs / twin-primes-to-8.raku
Created February 27, 2025 20:22
An amusing twin primes property.
# 2025-02-27.Thu [Coke] shows this on IRC:
#
# If you take twin primes starting with 5, multiply them together,
# then add the digits together iteratively until you're left with a
# single digit... it's 8.
sub aa ($a) {
my $s = [+] $a.comb;
$s.comb.elems > 1 ?? aa($s) !! $s
}
@lucs
lucs / repl-nums.raku
Created September 21, 2024 00:43
Replacing numbers
my $orig-text = Q:to/EoT/
My number is 4, and another 3.2
and 8 again, and also 7
6 and 0.9
EoT
;
my @repl-nums = (6.5, 3, 5, 8.1, 2, 0);
my $want-text = Q:to/EoT/
@lucs
lucs / zef-IO_String.txt
Created May 22, 2024 16:14
Problem with zef obtaining IO::String
I'm upgrading my Rakudo from moar-2023.02 to
moar-2024.04. I'm having problems obtaining the
IO::String distribution. raku.land proposes:
P6C: IO::String:ver<0.1.1>
ZEF: IO::String:ver<0.2.0>:auth<zef:jjmerelo>
Now, in a shell having moar-2024.04 active, please
observe:
@lucs
lucs / discord-ansi.txt
Last active October 4, 2023 15:12
Discord-pastable text using ANSI highlighting codes.
```ansi
Resetting to normal color and style is done by inserting ``⟨esc⟩[0m``.
Basic colors, foreground and background (meh):
 30 Black  40 Black 
 31 Red  41 Red 
 32 Green  42 Green 
 33 Yellow  43 Yellow 
 34 Blue  44 Blue 
 35 Magenta  45 Magenta 
@lucs
lucs / eg-snips.raku
Created September 9, 2023 17:39
Example snippets to use with snipraku.raku
# --------------------------------------------------------------------
# ID: misc79 unicode
for ^2**20 -> $u {
my $c = chr $u;
my $n = uniname $c;
printf "$c U-%X %s\n", $u, $n if $n ~~ /'SNOW'/;
}
# --------------------------------------------------------------------
@lucs
lucs / snipraku
Last active September 10, 2023 07:09
To launch snipraku.raku with proper envvars
#!/bin/bash
# ⦃▸ snipraku b rx14⦄
snipraku.raku \
/home/lucs/prj/t/raku/bin/snips.raku \
/tmp/snips-raku \
$*
@lucs
lucs / snipraku.raku
Last active September 10, 2023 07:22
Use Code::Snippets to manage Raku snippets
#!/usr/bin/env raku
=begin pod
=head1 NAME
snipraku - Extract and run Raku snippets.
=head1 SYNOPSIS
@lucs
lucs / markdown-test.rakumod
Last active May 1, 2023 00:26
⌊raku --doc=Markdown ⋯⌉ produces some improper Markdown
=begin pod
⌊raku --doc=Markdown ⟨this file⟩⌉ produces
improper Markdown for the beginning here;
Indented
Baz
Indented
Foo
@lucs
lucs / try-leave.raku
Created March 26, 2023 14:41
Control a LEAVE block's execution
I want a LEAVE block to run after a sub has completed,
but only if some condition is True.
# --------------------------------------------------------------------
# Start from this.
sub foo1 {
LEAVE {⋯}