Skip to content

Instantly share code, notes, and snippets.

@ftk
ftk / win2lin.cpp
Last active February 3, 2019 14:52
Wrapper for windows subsystem for linux: run ubuntu applications from windows
// Wrapper for windows subsystem for linux (Bash on Ubuntu on Windows)
// It allows running native ubuntu applications from Windows
// 1. Compile (on windows, the command below is for mingw-gcc):
// g++ -O3 -flto -fwhole-program -fvisibility=hidden -fno-exceptions -fno-rtti -s win2lin.cpp -o win2lin.exe
// 2. make a copy for each program
// for i in git python perl; do cp win2lin.exe ${i}.exe; done
// 3. put directory with exes in windows PATH
// 4. example (from cmd.exe):
// cat "c:\test 1.txt"
// will be translated to: bash -c "exec cat \"/mnt/c/test 1.txt\""
@ftk
ftk / Makefile
Last active July 27, 2024 12:16
libspnav example controlling mouse using spaceball (uinput)
CFLAGS ?= -O3 -flto
simple_uinput: proto.h spnav_config.h spnav.h proto.c spnav.c simple.c
$(CC) $(CFLAGS) -o $@ $^
spnav_config.h:
touch $@
proto.h spnav.h proto.c spnav.c:
curl -L -O --compressed --url "https://github.com/FreeSpacenav/libspnav/raw/master/src/{proto.c,proto.h,spnav.c,spnav.h}"
@ftk
ftk / Cargo.toml
Last active October 17, 2025 14:31
http mitm proxy. Simple http proxy to modify Range: http headers. Can be used to speed up youtube in mpv
# To generate mitm cert and key:
# openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -passout pass:"third-wheel" -subj "/C=US/ST=private/L=province/O=city/CN=hostname.example.com"
# see: https://github.com/campbellC/third-wheel
[package]
name = "http-ytproxy"
version = "0.1.0"
edition = "2021"
@ftk
ftk / mpv-playlist-kdialog.lua
Last active June 5, 2024 15:32
open mpv playlist in kdialog or zenity (default: Ctrl+L)
-- ==UserScript==
-- @name mpv-playlist-kdialog
-- @version 0.1
-- @description Display mpv playlist and select playlist entry in KDE's kdialog or Gnome's zenity.
-- @author ftk
-- @license 0BSD
-- @downloadURL https://gist.githubusercontent.com/ftk/5e26656a2ec9a6cb0fef46918f741d0a/raw/mpv-playlist-kdialog.lua
-- ==/UserScript==
local options = {
-- window dimensions
@ftk
ftk / notification-watch.sh
Last active October 10, 2024 13:27
check for one-time codes coming as notifications via KDE connect and copy them to clipboard
#!/usr/bin/env bash
# check for one-time codes coming as notifications via KDE connect and copy them to clipboard
# requirements: qdbus(qt-tools), dbus-monitor, kde-connect, klipper
# the script must be run in user session
set -euo pipefail
shopt -s lastpipe
if [[ $# -eq 0 ]]
then
@ftk
ftk / awg-mkconfig.sh
Last active December 20, 2024 12:49
Simple AmneziaWG config generator. AmneziaWG is a wireguard fork with obfuscated headers. Example usage: env num_peers=3 bash ./awg-mkconfig.sh 1.2.3.4 ens3
#!/usr/bin/env bash
## Simple config generator for AmneziaWG server and clients (1 client by default) with random headers.
## It will generate files wg0s.conf, wg0c2.conf, ...
## wg0s.conf must be placed in /etc/amnezia/amneziawg/ on the server, other files must be distributed to clients.
## Usage: ./awg-mkconfig.sh [remote ip] [remote wan iface] (remote ssh name - optional)
## To get remote interface run "ip address show" on the server. Usually it starts with "ens".
## Environment variables:
## num_peers=2 - increase to generate configs for more than 1 client
## port - defaults to random port from 1024 to 33792
## subnet=10.100.0 - first 3 octets for awg interface
@ftk
ftk / rutracker.py
Created August 18, 2025 08:18
Script that checks for torrent updates on rutracker.org, from qBitTorrent torrent list
#!/usr/bin/env -S uv run
# /// script
# dependencies = [
# "beautifulsoup4>=4.12.3",
# "bencodepy>=0.9.5",
# "requests>=2.32.3",
# ]
# ///
import sqlite3
import re
@ftk
ftk / screenshot_llm.sh
Created August 18, 2025 08:24
Launch spectacle in capture region mode and send the catpured screenshot to openai-compatible endpoint to OCR and possibly translate
#!/usr/bin/env bash
## Launch spectacle in capture region mode and send the catpured screenshot to openai-compatible endpoint to OCR and possibly translate
## Example usage: bind 'notify-send img "$(./screenshot_llm.sh 2>&1)"' to a hotkey
## Environment variables to set: OPENAI_API_KEY, optionally: OPENAI_API_BASE, OPENAI_MODEL, PROMPT
set -euo pipefail
[[ $# -ge 1 && $1 == --help ]] && exec sed -n 's/^## //p' -- "$0"
[[ $# -ge 1 && ( $1 == --verbose || $1 == -v ) ]] && set -x
@ftk
ftk / llm.sh
Created August 20, 2025 11:00
Simple script to call OpenAI compatible endpoint with specified messages
#!/bin/bash
## Calls OpenAI v1 chat compatible endpoint with specified messages. Each passed argument is 1 message.
## Environment variables to set: OPENAI_API_KEY, optionally: OPENAI_API_BASE, OPENAI_MODEL, PROMPT
## Please note that your API key would be visible in curl aguments in the process list.
##
## Usage: ./llm.sh [-v] [-s "system prompt"] "message 1"...
## Example: ./llm.sh "count the number of lines in:" "$(cat file.txt)"
## --verbose|-v: debug the LLM call, prints input and output
set -euo pipefail