Skip to content

Instantly share code, notes, and snippets.

$ ./pxcr --help
pxcr - Probabilistic XOR Error Correction
Copyright (C) 2017, 2018 Christian Thaeter <ct.pxcr@pipapo.org>
usage:
pxcr <mode> [options..]
pxcr --help [topic]
modes are:
--create - create redundancy files
@cehteh
cehteh / rust_segv_handler.rs
Created April 12, 2022 12:13
make rust panic on segv, print backtrace when RUST_BACKTRACE=1
fn init_segv_handler() {
use libc::*;
unsafe extern "C" fn handler(signum: c_int) {
let mut sigs = std::mem::MaybeUninit::uninit();
sigemptyset(sigs.as_mut_ptr());
sigaddset(sigs.as_mut_ptr(), signum);
sigprocmask(SIG_UNBLOCK, sigs.as_ptr(), std::ptr::null_mut());
panic!("SEGV!");
}
unsafe {
@cehteh
cehteh / path_normalize.rs
Created July 2, 2021 22:24
normalize paths in rust including components that do not exist yet
trait PathNormalize {
fn normalize(&self) -> PathBuf;
}
impl PathNormalize for Path {
fn normalize(&self) -> PathBuf {
use std::path::Component::*;
let mut normalized = PathBuf::new();
for component in self.components() {
match component {
@cehteh
cehteh / cargo-errors
Last active May 27, 2021 19:06
rust cargo show only errors
#!/bin/bash
shift
cmd="${1:-build}"
shift
if [[ "$TERM" = "dumb" ]]; then
fmt=json
else
fmt=json-diagnostic-rendered-ansi
fi
@cehteh
cehteh / main.rs
Created April 21, 2021 09:16
Rust FD copy test
use std::ffi::{CStr, CString};
use std::time::Duration;
use std::thread;
unsafe fn copy_fd(fd: libc::c_int) -> libc::c_int {
let dot = CString::new(".").unwrap();
libc::openat(fd, dot.as_ptr(), libc::O_DIRECTORY)
}
fn main() {
source ssh-cron-agent
RSTORE_LIMIT_PERCENT=94
RSTORE_LIMIT_INODES=94
RSTORE_TRIES=2
rstore_cleanup rootserver styx charon rpi dionysos ..... and so on
+ .vaultbackup-pre.rsync
dir-merge /.backup-pre.rsync
+ backup-pre.rsync
dir-merge /backup-pre.rsync
merge fullsystem.rsync
-C
- .hg
+ .backup.rsync
dir-merge /.backup.rsync
+ backup.rsync
cd ~/backups
if rstore_idle rpi && rstore_last_older_than rpi 1 days; then
source global.rstore
rstore_backup rpi root@rpi.pipapo.org:/ --fake-super -m --rsync-path="ionice -c 3 nice -n 15 rsync"
fi
#include <stdint.h>
#include <stdlib.h>
#include <stddef.h>
#define TMP_ALLOCA_MAX 4000 // should be fairly smaller than pagesize
#if defined __GNUC__ || defined __clang__ || defined __IBM__ALIGNOF__
# define mem_alignof __alignof__
#else
#define mem_alignof(type) offsetof(struct { char a_; type member; }, member)
@cehteh
cehteh / gist:871467d2965d6d2f4e10ffc9191d3f2a
Last active October 28, 2020 17:03
establish sudo wrapers for some commands
sudo_funcs=(apt /etc/cron.daily/autokernel)
for func in "${sudo_funcs[@]}"; do
name="${func##*/}"
source <(cat <<<"function $name () { sudo -- $func \"\$@\"; }")
done