Skip to content

Instantly share code, notes, and snippets.

@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 {⋯}
@lucs
lucs / some.raku
Last active February 21, 2023 17:07
Renaming an exported sub
# --------------------------------------------------------------------
#`(
I have 「A.rakumod」 which exports two multi variations of
subroutine 「orig」. I would like the user to be able to do for
example 「use A 'mine'」, so that they can invoke the exported subs
with some other arbitrary name instead.
)
# --------------------------------------------------------------------
# First, failing, attempt
@lucs
lucs / mainusage.memo
Last active December 11, 2022 14:46
Raku: ♪ USAGE() in a module, yeah ♪
As explained in this talk by lizmat,
<https://www.youtube.com/watch?v=VoxWnNJ0gTI&t=8440s>, to speed up the
launch time of a Raku script, one can write all of its MAIN logic in a
module, make sure sub MAIN is exported, and create a script that
simply "use"s the module (the talk is more general and worth
watching). The launch time speedup will occur once the program has
been run at least once, since its modules will have been precompiled,
as opposed to the script itself.
But what if we want to have a custom USAGE() function? We can write
@lucs
lucs / vim-exec-highlighted.memo
Last active December 11, 2022 14:45
Vim: execute the text that is visually highlighted.
" --------------------------------------------------------------------
" Execute the text that is visually highlighted. This is very practical
" when wanting to try out stuff one may want to put in their .vimrc file
" or something.
function! ExecHighlighted () range
" Grab the highlighted text: save the contents of an arbitrary
" register, yank the highlighted text to it, copy the register
" contents to a local variable, and restore the register
@lucs
lucs / vim-toggle-C_style-comments.memo
Last active December 11, 2022 14:48
Vim: Toggle 「/*⋯*/」 style one line comments.
" --------------------------------------------------------------------
" Toggle 「/*⋯*/」 style one line comments.
nnoremap <silent> <Plug>CStyleOneLine
\ ^:if search('/\*.*\*/', 'c', line(".")) != 0<cr>
\ :.s,/\* *\(.\{-}\) *\*/,\1,g<cr>
\ :else<cr>
\ :.s,\(\s*\)\(.*\)\(\s*\),\1/\* \2 \*/\3,g<cr>
\ :endif<cr>
\ :noh<cr>