Skip to content

Instantly share code, notes, and snippets.

@timo
timo / Raku-UserFaultFD-README.md
Last active February 18, 2025 01:03
UserfaultFD for Linux with Raku's NativeCall

UserfaultFD with #Rakulang

This Gist has a super hacky ugly implementation of a part of the UserfaultFD feature of the linux kernel (awkwardly) using raku's NativeCall. This could be much improved with a little bit of care.

Check this recording of what happens:

asciicast

you can see multiple worker threads (doods) trying to read from and write to a memory region that was initially write-protected and watched for access attempts by the UFFD thread.
The doods are stopped in their tracks when they first access some location, then the UFFD thread decides to let them continue after copying some data into the area and when they try to write to it, it just un-write-protects the page.

@timo
timo / peek.sh
Created October 9, 2024 19:45 — forked from jpenalbae/peek.sh
Record desktop area on linux using slop and ffmpeg
#!/bin/bash
# Video Quality
# The range of the CRF scale is 0–51, where 0 is lossless, 23 is the default,
# and 51 is worst quality possible. A lower value generally leads to higher
# quality, and a subjectively sane range is 17–28
QUALITY=28
# check if slop command exists
if ! command -v slop &> /dev/null
0x7ffff6f518b0 has 4 edges over 3 states; 0 small (0.00)
0x7ffff6f52388 has 237 edges over 95 states; 118 small (49.79)
0x7ffff6f523e0 has 230 edges over 97 states; 108 small (46.96)
0x7ffff6f526c8 has 10 edges over 6 states; 5 small (50.00)
0x7ffff6f529d0 has 5 edges over 3 states; 1 small (20.00)
Stage start : 0.000
0x7ffff6f5abc8 has 87 edges over 56 states; 43 small (49.43)
0x7ffff6f5b460 has 52 edges over 30 states; 20 small (38.46)
0x7ffff6f5b4b8 has 44 edges over 28 states; 18 small (40.91)
0x7ffff6f97168 has 5 edges over 3 states; 0 small (0.00)
@timo
timo / 01-output.txt
Last active July 18, 2020 23:45
a Seq's first .iterator call shall be recorded with backtrace to be outputted when .iterator is called a second time ("seq already had its iterator taken and got consumed" or whatever)
making patch
will create seq
seq has which Seq|66864704
0
first user:
0.5
1
1.5
second user:
iterator already taken for this seq:
@timo
timo / gist:6e8a259891326a16f0d62d4ae0d5d1fa
Created February 4, 2020 14:08
distribution of instruction counts in CORE.c.setting.moarvm (doesn't correspond directly to bytecode size in bytes)
grep -B1 "^ Frame_" /fileserver-data/new_stuff/work/core.c.setting.dump.txt | grep -A1 -- '^--' | grep -v '^--' | cut -b 1-6 | sort | uniq -c | sort -rn
1953 00007
1351 00004
389 00008
344 00034
330 00043
289 00017
262 00020
250 00040
235 00012
@timo
timo / Perl6-Github-Linkify.js
Last active February 16, 2025 20:59
linkify filename/line-number entries in github issues in a couple different formats
// ==UserScript==
// @name Raku-Github-Linkify
// @namespace https://github.com/timo/
// @version 0.3.5.3
// @description Turns paths to raku source (core setting, grammar, actions) and moarvm code to clickable links on github issue/PR pages as well as gists
// @downloadUrl https://gist.githubusercontent.com/timo/7cfe71a667bbdfa0dbd1510431da45a4/raw/Raku-Github-Linkify.js
// @homepageURL https://gist.github.com/timo/7cfe71a667bbdfa0dbd1510431da45a4
// @author Timo 'timotimo' Paulssen
// @match https://github.com/*/*/issues/*
// @match https://github.com/*/*/pull/*
@timo
timo / query
Created December 6, 2018 00:48 — forked from Whateverable/query
evalable6
my $l = Lock.new; my %h; for 1..10 { my $p = start { sleep rand; $l.protect: { say "-- ", $p.WHERE; say %h.elems; %h{$p.WHERE}:delete; say %h.elems } }; say "+", $p.WHERE; %h{$p.WHERE} = $p; }; await %h.values; note %h.elems
@timo
timo / currently-working.sql
Last active November 8, 2018 14:58
can i make the update part of this query use a "with recursive" expression?
-- for testing, completely reset highest_child_id columns
update calls set highest_child_id = NULL;
-- find rows where no other row has the row's id as its parent_id
-- those shall seed the progress with initial "highest child id"
-- values
with no_children as (select id from
(select c.id as id, count(children.id) as childcount
from calls c
left join calls children on c.id == children.parent_id
@timo
timo / HashyObject.p6
Created September 30, 2018 01:05
#perl6 use a hash as if it were an object
unit class HashyObject;
has %!storage;
submethod TWEAK(*%data) { %!storage = %data }
submethod FALLBACK($name, |c) is rw { %!storage{$name} };
method perl {
self.^name ~ ".new(" ~ %!storage.pairs.map(*.perl).join(", ") ~ ")"
@timo
timo / gist:b01c70e2f7ce4a40eddc19517e3aee87
Created September 26, 2018 21:29
hilarious-looking compilation result of allomorphs.pm6 &parse_win
BB 14 (0x7f030419cdf8):
line: 283 (pc 188)
Instructions:
[Annotation: Logged (bytecode offset 188)]
sp_getlex_o r6(20), lex(idx=0,outers=0,newval)
[Annotation: INS Deopt One (idx 8 -> pc 196; line 283)]
[Annotation: INS Deopt One (idx 9 -> pc 202; line 283)]
sp_guardconc r6(4), r6(20), sslot(1), litui32(196)
[Annotation: Logged (bytecode offset 354)]
sp_getlex_o r9(25), lex(idx=0,outers=0,newval)