Skip to content

Instantly share code, notes, and snippets.

Avatar

Moritz Lenz moritz

View GitHub Profile
@moritz
moritz / pdf-autosplit
Created Apr 15, 2022
pdf-autosplit, for splitting a PDF based on annotations (chapters).
View pdf-autosplit
#!/usr/bin/env raku
# Written in Raku, former Perl6: https://raku.org/
sub page-numbers-from-chapters($filename) {
my $proc = run :out, 'pdftk', $filename, 'dump_data_utf8';
my %bookmark;
my @borders;
sub handle-bookmark() {
if %bookmark && (%bookmark<BookmarkLevel> // 0) == 1 {
@borders.push(%bookmark<BookmarkPageNumber>);
@moritz
moritz / recalcitrant
Created Apr 4, 2022
Python: dynamically load a script (without .py) extension and mock things in it
View recalcitrant
#!/usr/bin/env python3
# scrript being tested. Goal: patch out getpid
from os import getpid
def double_pid():
return 2 * getpid()
if __name__ == '__main__':
print(double_pid())
@moritz
moritz / mol.txt
Last active Sep 25, 2021
Fallen London: Khanate Memory of Light Grind
View mol.txt
Number of samples: 346
Total : 1739
Average : 5.03 ± 0.27
Error : 5.38%
1 ( 4 ): xxxx
2 ( 19 ): xxxxxxxxxxxxxxxxxxx
3 ( 38 ): xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
4 ( 65 ): xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
5 ( 93 ): xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
6 ( 59 ): xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
@moritz
moritz / lib-noris-StableRandom.pm
Created Jul 21, 2021
Generate "random" but stable names for pseudonymification
View lib-noris-StableRandom.pm
package noris::StableRandom;
use 5.024;
use strict;
use warnings;
use utf8;
# note: we use a separate random number generator
# because we need stable "random"ness based on the database IDs,
# and don't want to confuse any of the libraries we use
@moritz
moritz / expression.raku
Created Dec 19, 2020
Advent of Code day 18 solultion in Raku #rakulang
View expression.raku
grammar Expression {
token integer { \d+ }
proto token operator { <*> }
token operator:sym<+> { <sym> }
token operator:sym<*> { <sym> }
rule term { <integer> | <parens> }
rule parens { '(' ~ ')' <expression> }
rule expression { <term> + % <operator> }
token TOP { <.ws> <expression> }
}
@moritz
moritz / fooo
Created Jul 30, 2020
Raku Match.gist output
View fooo
$ ./rakudo-m -e ' for ("a1a2a3a4a5" ~~ m:g/(a \d)/) { say "match {$++}: ", $_}'
match 0: 「a1」
0 => 「a1」
match 0: 「a2」
0 => 「a2」
match 0: 「a3」
0 => 「a3」
match 0: 「a4」
0 => 「a4」
match 0: 「a5」
@moritz
moritz / inverse-regex.p6
Last active Aug 31, 2020
Generate shortest strings that match a regex
View inverse-regex.p6
use v6;
role Generator {
method shortest() { ... }
}
class Literal does Generator {
has Str $.atom is required;
method shortest() { return $.atom.list }
}
@moritz
moritz / ergebnis.txt
Created Mar 20, 2020
Wörterhäufigkeit WirVsCorona Hackathon
View ergebnis.txt
6264 und
5642 die
3657 wie
3427 der
3416 können
3051 in
2498 zu
2482 werden
2353 wir
2349 von
@moritz
moritz / error.log
Created Aug 25, 2019
Moar build failure
View error.log
compiling src/jit/compile.o
compiling src/jit/dump.o
Precompiling templates from src/jit/core_templates.expr
"pairkeys" is not exported by the List::Util module
"pairvalues" is not exported by the List::Util module
"pairgrep" is not exported by the List::Util module
Can't continue after import errors at tools/expr-template-compiler.pl line 9.
BEGIN failed--compilation aborted at tools/expr-template-compiler.pl line 9.
Makefile:675: recipe for target 'src/jit/core_templates.h' failed
make: *** [src/jit/core_templates.h] Error 255
@moritz
moritz / interleaving.pod6
Created Dec 18, 2018
Perl 6 phase interleaving
View interleaving.pod6
Perl 6 first compiles code, and then runs it.
The C<BEGIN> phaser interleaves a run time phase into the
compilation phase, that is, the code inside the C<BEGIN>
phaser is first compiled, then run, and then the rest of the
compilation continues.
In the hypothetical code example
A;