Skip to content

Instantly share code, notes, and snippets.

@vi
vi / cgroup_memory_pressure_monitor.c
Created Jul 19, 2015
Simple command-line tool use cgroup's memory.pressure_level
View cgroup_memory_pressure_monitor.c
#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.
@vi
vi / hextobin.c
Created Aug 25, 2017
Hex string to byte buffer in C
View hextobin.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 / split_by_silence.sh
Last active Apr 27, 2021
Using FFmpeg to split multimedia file into parts based on audio volume level
View split_by_silence.sh
#!/bin/bash
IN=$1
OUT=$2
true ${SD_PARAMS:="-55dB:d=0.3"};
true ${MIN_FRAGMENT_DURATION:="20"};
export MIN_FRAGMENT_DURATION
if [ -z "$OUT" ]; then
@vi
vi / tcpclose.crs
Created Aug 2, 2018
Rust Tokio fast TCP socket close handling
View tcpclose.crs
#!/usr/bin/env run-cargo-script
//! ```cargo
//! [dependencies]
//! tokio = "=0.1.7"
//! tokio-codec = "*"
//! tokio-io = "=0.1.7"
//! futures-cpupool = "*"
//! mio = "*"
//!
//! [replace]
@vi
vi / split_by_silence_kf.sh
Last active Mar 25, 2021
Video-enhanced split_by_silence.sh script.
View split_by_silence_kf.sh
#!/bin/bash
IN=$1
OUT=$2
true ${SD_PARAMS:="-55dB:d=0.3"};
true ${MIN_FRAGMENT_DURATION:="20"};
export MIN_FRAGMENT_DURATION
if [ -z "$OUT" ]; then
@vi
vi / simplevpn
Last active Mar 15, 2021
simplevpn: Simple IPsec and ipip[6] tunnel configuration for Linux using SSH for key exchange
View simplevpn
#!/bin/bash
# Setup encrypted IPv4 tunnel over IPv4 or IPv6 on two Linux nodes using SSH for tunnel setup.
# Requires only ipsec-tools, iproute2, ssh and necessry kernel modules locally and remotely.
# Warning: it flushes IPsec settings both locally and remotely.
# Don't use with other IPsec tunnnels.
# Sample usage:
# simplevpn -6 fc::1 fc::2 ssh -T root@fc::2
@vi
vi / reedsolomon.c
Created Sep 16, 2012
Simple command-line Reed-Solomon encoding and decoding tool
View reedsolomon.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ecc.h"
/* Reed-solomon command-line tool by Vitaly "_Vi" Shukela; 2012 */
/*
Usage:
1. Download http://sourceforge.net/projects/rscode/
@vi
vi / vethify.c
Created Oct 19, 2013
Copy packets between two network network interfaces (for workarounds)
View vethify.c
/* vethify - multiplex packets between two ethernet interfaces
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
@vi
vi / mvimg_mpv
Created Aug 11, 2019
Shell script to play Google Motion Photos with mpv from command line
View mvimg_mpv
#!/bin/bash
if [[ -z "$1" || "$1" == --help || "$1" == "-?" ]]; then
echo "Usage: mvimg_play MVIMG_20190806_183324.jpg [other files]"
echo "Plays Google's Motion Photo using mpv. Depends on exiftool, mktemp, bash and mpv."
exit 0
fi
FOUND=0
ARGS=()
@vi
vi / rust_wine.md
Last active Jun 15, 2020
Using Rust in Wine as a sort of cross-compiler
View rust_wine.md

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