Skip to content

Instantly share code, notes, and snippets.

View mana-z's full-sized avatar

Martin "Mana" Zalabak mana-z

  • Prague
View GitHub Profile
To limit to 20% of 1 CPU
$ podman run --cpu-quota=20000 <IMAGE> # shares of --cpu-period, default 100000
$ systemd-run --user --scope -u your-scope-name.scope -p CPUQuota='20%' <CMD>
Manually:
1) create a directory (new cgroup) in /sys/fs/cgroup
- ideally under some existing cgroup if applicable
- directory might differ: see `mount|grep cgroup2` - you can mount it by yourself if it's missing
2) write "cpu" to underlying cgroup.controllers (all higher cgroups must have that as well)
3) write "20000 100000" into cpu.max (it's share and granularity)
@mana-z
mana-z / compl_examples.sh
Created June 9, 2021 11:51
Bash completion templates/examples with annotations
#!/bin/bash
# some useful notes
# - -F does not work in compgen, so does many of -o args
# - docs about competion: `info bash`, last three chapters of "Command Line Editing"
# - bash-completions helpers are not very well documented
# - -G is useless, somehow it does not trigger filling the command line, use -A file -X "!<glob>"
# example/template using bash-completion helpers
# Assigned variable by _init_completion.
# cur Current argument.
@mana-z
mana-z / terminalneeded.sh
Created February 9, 2021 14:26
sourcable bash script to spawn terminal for the script when needed. Works only for scripts w/o arguments
#!/bin/bash
# substitute the default terminal for one of your choosing
[[ -z $TERMINAL ]] && TERMINAL=alacritty
# if there is an any parameter added, sleep after the evaluation
[[ -n $1 ]] && SUFFIX="; sleep 2"
if [[ ! -t 1 ]]; then
$TERMINAL -e sh -c "bash ${BASH_SOURCE[1]}${SUFFIX}"
exit 0
fi
@mana-z
mana-z / nostdexample.rs
Last active July 8, 2025 12:42
Usable Rust no_std hello world, working well with stable Rust
#![no_std]
#![no_main]
// requires:
// [profile.dev]
// panic = "abort"
// [profile.release]
// panic = "abort"
//
// [dependencies.libc]
// version = "0.2"
@mana-z
mana-z / readini.sh
Created October 25, 2019 08:00
shell script for reading ini files
#!/bin/sh
# This work is licensed under the Creative Commons Public Domain Mark 1.0 License. To view a copy of
# this license, visit http://creativecommons.org/publicdomain/mark/1.0/ or send a letter to Creative
# Commons, PO Box 1866, Mountain View, CA 94042, USA.
# usage ./readini.sh <file> <block> <key>
# returns a value of a key in ini file, or nothing if not found
if [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ]; then
echo "insufficient parameters" 1>&2