Skip to content

Instantly share code, notes, and snippets.

@vi
vi / cgls
Last active August 16, 2026 10:14
A script to list cgroup v2 hierarchy
#!/usr/bin/env python3
"""
cgls - list cgroup v2 hierarchy with task counts and resource tags.
Usage: cgls [ROOT]
ROOT defaults to /sys/fs/cgroup. Output is a tree of cgroups, each annotated
with the number of direct tasks and tags indicating active resource constraints
or states.
@vi
vi / interesting_crates.md
Last active August 8, 2026 06:35
List of crates that improves or experiments with Rust, but may be hard to find

Let's list here crates that enhance Rust as a language.

It not "batteries" like in stdx, but Rust-specific crates for workarounds for various missing features and experimental ideals from non-accepted/postponed RFCs, or just hacky tricks.

The list is supposed to contain (mostly) crates that are internal to Rust, not ones for making Rust deal with "external world" like other languages bindings, file formats, protocols and so on.

Primary focus should be on crates that are not easy to find by conventional means (e.g. no algorithm name, format or protocol to search for).

Note that quality of the listed crates may vary from proof-of-concept to stable-and-widely-used.

@vi
vi / rust_wine.md
Last active September 15, 2025 06:47
Using Rust in Wine as a sort of cross-compiler

Cross-compiling Rust from Linux to Windows using Wine

🔴 Note: this article is obsolete. This cross-compilation direction may just work out of the box. 🔴

0. Ensure Rust works on Host

Let's create a dummy project for a test.

$ cargo new test
@vi
vi / hextobin.c
Created August 25, 2017 15:10
Hex string to byte buffer in C
// Based on https://stackoverflow.com/a/23898449/266720
void tallymarker_hextobin(const char * str, uint8_t * bytes, size_t blen)
{
uint8_t pos;
uint8_t idx0;
uint8_t idx1;
// mapping of ASCII characters to hex values
const uint8_t hashmap[] =
{
@vi
vi / cnf_mapping.diff
Created July 9, 2025 20:26
Patch for MiniSat+ to also output mapping from OPB to CNF variables when using -cnf option
--- PbSolver.C.orig 2025-07-09 22:25:44.393796385 +0200
+++ PbSolver.C 2025-07-09 22:24:07.817685378 +0200
@@ -535,10 +535,22 @@
addConstr(goal_ps, goal_Cs, opt_goal, -1),
convertPbs(false);
- if (opt_cnf != NULL)
- reportf("Exporting CNF to: \b%s\b\n", opt_cnf),
- sat_solver.exportCnf(opt_cnf),
+ if (opt_cnf != NULL) {
@vi
vi / no_new_privs.c
Created July 25, 2015 22:16
Do prctl(PR_SET_NO_NEW_PRIVS) and exec
// Pre-built static i386 version: http://vi-server.org/pub/no_new_privs
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <sys/prctl.h>
int main(int argc, char* argv[])
{
if (argc == 1 || !strcmp(argv[1], "--help")) {
@vi
vi / pbcopy_html.swift
Created June 24, 2023 23:32
Command line tool, like `xclip -in -t text/html` for Mac. For preparing content for Google Docs/Sheets.
#!/usr/bin/env swift
// Based on https://github.com/chbrown/macos-pasteboard/issues/8#issuecomment-906537204
import Cocoa
import Foundation
let pasteboard: NSPasteboard = .general
let dataTypeName : String = "public.html"
@vi
vi / dnsmanageweb.rs
Last active December 15, 2024 08:43
Simple web portal to update dynamic DNS records
#!/usr/bin/env run-cargo-script
//! ```cargo
//! [package]
//! name = "dnsmanageweb"
//! version = "0.1.0"
//! authors = ["Vitaly _Vi Shukela <vi0oss@gmail.com>"]
//! edition = "2018"
//!
//! [dependencies]
//! rouille = {version="3.0.0", default-features=false}
#!/bin/bash
# Warning: it garbes binary files, use only for text
if [[ -z "$1" || "$1" == "--help" ]]; then
echo "Ouput content of the file being appended to to stdout, continue outputting as more data appears in the file, exit when no processes write to the file for a while."
echo "Usage: cat_and_follow file | something"
exit 1
fi
@vi
vi / cgroup_memory_pressure_monitor.c
Created July 19, 2015 22:51
Simple command-line tool use cgroup's memory.pressure_level
#include <sys/eventfd.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
// Implemented by Vitaly "_Vi" Shukela in 2015, License=MIT.