Should you – as i did – wonder why WordPress renders a bucket of inline CSS into the HTML output (such as --wp--preset--font-size--normal in <html> or --wp--preset--color--white in <body>): This is done to accomodate frontend editing with Gutenberg. If you – as i do – are not using Gutenberg frontend editing, then the following PHP code can be included in the functions.php of a custom theme or the php file of a custom plugin. Sorry, Gutenberg folks – no means no. 🙂
Updated Common Prefix Notation Transformation
21. August 2022 in Programmierung.
This is an update to my previous article on determining the common prefixes of a set of strings (passed a sequence of lines) and printing them in common prefix notation (CPN). The problem of reconstructing strings from the original input that are complete prefixes of other input strings is addressed.
The code is now in a Git repository:
Gitlab-Projekt trieReleases: v2.0Find Files by Size given in Bytes
27. August 2022 in Administration, GNU/Linux, Programmierung.
Some examples:
Find files in current directory that have a size of 400 bytes or more:
sfind -min 400
Find files in /etc that have a size of 50 kilobytes (1 kilobyte = 1024 bytes) or more:
sfind -dir /etc -min 50k
Find files in /var with size between 100 and 500 megabytes, suppress warnings, print sizes in human-readable format:
sfind -dir /var -min 100m -max 500m -quiet -human
Note: Yes, i know, Oracle distributes a tool that is also called „sfind“, but anyway …
Print XDG Desktop Definition for Application
21. August 2022 in Administration, GNU/Linux.
For an application given by „application name“ or „executable name“, output the corresponding .desktop file, if any:
find_desktop() {
local IFS=":"
local xdg_data_dirs=${XDG_DATA_DIRS:-/usr/local/share:/usr/share}
local search=$1
for i in $xdg_data_dirs ; do
a="$i/applications"
[ -d $a ] && for d in "$a"/*.desktop ; do
grep -q -e "^Name=.*$search" -e "^Exec=.*$search" "$d" && {
echo "# $d:"
grep -Ev '^(Comment|GenericName|Keywords|Name\[)' "$d"
}
done
done
}
Try it:
find_desktop gnome-terminal
Transforming Sets of Strings to their Common Prefix Notation
19. Januar 2023 in Programmierung.
Update Aug 20 2022:
-
- There is an update to this article that fixes a known issue.
- There is also a Git repository containing a reference implementation.
Any two strings s1, s2 have a common prefix cp, which is the string of characters that s1 and s2 have in common up from the start. If s1, s2 have no such common characters, cp is the empty string. Let s̅1, s̅2 be the remainders or suffixes of s1 and s2 if cp is removed from them. Then, the common prefix notation (CPN) of s1, s2 – in short, cpn(s1,s2) – shall be:
cpn(s1,s2) := cp{s̅1,s̅2}
Given the definition above, for any given CPN of a set of strings s1, s2, …, sn, the CPN of the set extended by an additional string sn+1 is defined as follows:
Case 1: If the suffix of sn+1 with cp removed, s̅n+1, has no nonempty common prefix with any of the suffixes s̅1, s̅2, …, s̅n:
cpn(s1,s2,…,sn+1) := cp{s̅1,s̅2,…,s̅n+1}
Case 2: Otherwise, since the first characters of s̅1, s̅2, …, s̅n are distinct, there can only be one element s̅m that has a nonempty common prefix with s̅n+1. Given s̅m to be that element:
cpn(s1,s2,…,sn+1) := cp{s̅1,s̅2,…,cpn(s̅m,s̅n+1),…,s̅n}
Examples:
cpn("a", "b") = "{a,b}"
cpn("aa", "ab") = "a{a,b}"
cpn("aa", "ab", "abc", "abd") = "a{a,b{c,d}}"
cpn("a", "ab", "abc") = "{a{b{c}}}"
Note: For the sake of reasoning, strings containing the CPN’s reserved characters {, } and , shall be considered invalid input. In a practical implementation, a syntax for „escaping“ these reserved characters should be available.
Given a set of strings, one per line, on standard input, the following Python program prints the CPN of these strings on standard output: http://tk-sls.de/ref/trie1.py
Try the examples:
./trie1.py << EOF
a
b
EOF
./trie1.py << EOF
aa
ab
EOF
./trie1.py << EOF
aa
ab
abc
abd
EOF
The following example renders the wrong output, because a trie does not actually store the common prefix (this is what a suffix tree would accomplish), it just stores different prefix paths, and a, ab and abc have no different prefix paths, it’s just a degenerate tree a → b → c:
./trie1.py << EOF
a
ab
abc
EOF
So my guess is, i must implement one of these fancy suffix tree algorithms to get it done right. (see the update instead) 🙂
In the meantime, try this:
find /etc -type d | ./trie1.py
🙂
Pinguin-Patenschaft
31. Dezember 2021 in Sonstiges.
Mein Arbeitgeber, B1 Systems GmbH hat in meinem Namen eine Patenschaft für einen afrikanischen Pinguin gesponsert. 🙂
Pi-KVM Hat v3
31. Dezember 2021 in Administration, GNU/Linux, Technik.
Ich freue mich, zu den Glücklichen zu gehören, die den Pi-KVM Hat v3 mit passendem Stahlgehäuse ergattert haben (https://pikvm.org/). Das Warten hat sich gelohnt.
CentOS/8 Stream on libvirt/KVM with Kickstart and virt-install
22. Januar 2023 in Administration, GNU/Linux, Technik.
This article describes using Kickstart to automate the CentOS installer and virt-install to automate the creation of a VM.
The following setup is assumed:
- There is a libvirt hypervisor called virthost.
- ssh to virthost as „root“ is possible.