Skip to content

Instantly share code, notes, and snippets.

View bojidar-bg's full-sized avatar

Bojidar Marinov bojidar-bg

View GitHub Profile
@bojidar-bg
bojidar-bg / Bin.i
Last active September 23, 2023 19:10
Binary type with addition and multiplication for interaction nets, https://inet.run/playground/
// Example usage:
// let bsix = b0(b1(b1(bend())))
// let nseven = add1(add1(add1(add1(add1(add1(add1(zero())))))))
// let bseven = ntob(nseven)
// eval @inspect(bmul(bsix, bseven)) // -> takes 75 steps; doing the same with Nat mul takes 123 steps
// Type defitinion
type Bin
@bojidar-bg
bojidar-bg / Connection.i
Last active December 29, 2023 13:47
Virtual machine interaction net bootstrap for https://inet.run/playground/
require "./SymbolMap.i" // Diamond imports don't work
// import { List, null } from "./List.i"
// import { del, delOut, dup, dupOut } from "./Generic.i"
type Edge
type Connection
node pos(
edge: Edge,
@bojidar-bg
bojidar-bg / unsilence.sh
Last active March 15, 2024 14:33
Unsilence w/ MLT
#!/usr/bin/env bash
set -e
if [ "$#" -ne 4 ]; then
echo "Usage: $0 source-file silencedetect-args speedup-factor output-file"
echo " E.g.: $0 file.mkv n=-35dB:d=0.25 2.5 file.mlt"
exit 1;
fi
@bojidar-bg
bojidar-bg / layout-switcher.snip.sh
Created April 11, 2024 07:50
Change keyboard layout programatically and reload - kwin_wayland
# Go to Colemak
kwriteconfig6 --file kxkbrc --group Layout --key Model pc104awide
kwriteconfig6 --file kxkbrc --group Layout --key LayoutList us,bg
kwriteconfig6 --file kxkbrc --group Layout --key Options grp:alt_shift_toggle,grp:win_space_toggle,caps:backspace,lv3:ralt_switch_multikey,compose:menu
kwriteconfig6 --file kxkbrc --group Layout --key VariantList cmk_ed_dh,colemak_dh
dbus-send --session --type=signal --reply-timeout=100 --dest=org.kde.keyboard /Layouts org.kde.keyboard.reloadConfig
# Back to QWERTY
@bojidar-bg
bojidar-bg / focus.py
Created July 1, 2024 18:25
Script enabling do-not-disturb mode for a random amount of time
#!/usr/bin/python
import sys
import argparse
import dbus
import random
import time
import signal
def seconds(s):
@bojidar-bg
bojidar-bg / procedural-worm.py
Created July 25, 2024 09:34
Procedurally-animated worm in Python
# A simple program which shows a procedurally-animated worm that can be moved around by clicking on the screen.
# References: https://mcsp.wartburg.edu/zelle/python/graphics/graphics/graphref.html, https://tkdocs.com/shipman/index-2.html
from random import random
from math import sqrt
from graphics import * # https://mcsp.wartburg.edu/zelle/python/graphics.py
class FollowerCircle(Circle):
"""
@bojidar-bg
bojidar-bg / specialization.rs
Last active March 13, 2025 17:23
Example of Rust specialization used for specializing structs ala C++
#![feature(specialization)]
// feature(specialization) is still unstable as per https://github.com/rust-lang/rust/issues/31844>, but min_specialization is not enough for what we want to do, unless we use dyn.
struct VecOrBitset<T: MaybeSpecializedOn> {
inner: T::VecOrBitsetType
}
impl<T: MaybeSpecializedOn> VecOrBitset<T> {
fn new(x: impl IntoIterator<Item = T>) -> Self {