Skip to content

Instantly share code, notes, and snippets.

View ninlith's full-sized avatar

Okko Hartikainen ninlith

View GitHub Profile
@ninlith
ninlith / syncstat
Last active January 9, 2023 15:19
Syncthing status
#!/usr/bin/env python3
"""Syncthing status."""
# https://nelsonslog.wordpress.com/2021/10/01/syncthing-status-from-the-command-line/
# https://svn.blender.org/svnroot/bf-blender/trunk/blender/build_files/scons/tools/bcolors.py
# https://docs.syncthing.net/dev/rest.html
import json
import re
HISTSIZE=1000000
HISTFILESIZE=1000000
HISTCONTROL=ignoreboth
shopt -s histappend
shopt -s histreedit
shopt -s histverify
PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
PATH=$PATH:~/bin
PATH=$PATH:~/.local/bin
@ninlith
ninlith / mitm.sh
Last active January 1, 2024 11:21
Local transparent man-in-the-middle proxy setup
#!/usr/bin/env bash
# -*- indent-tabs-mode: nil; tab-width: 4 -*-
command=${@:-"mitmproxy --mode transparent --showhost --set block_global=false"}
if [ ! -f "/etc/ssl/certs/mitmproxyuser.pem" ]; then
sudo apt --yes install inotify-tools mitmproxy nftables
sudo useradd --create-home mitmproxyuser
grep --max-count 1 "mitmproxy-ca-cert.pem" < <( \
sudo inotifywait -mrq -e close_write --format "%f" \
@ninlith
ninlith / calculate
Last active February 8, 2021 06:48
External calculation for Gedit
#!/usr/bin/env python3
# [Gedit Tool]
# Name=Calculate
# Input=selection
# Output=replace-selection
# Applicability=always
# Save-files=nothing
# Shortcut=<Primary><Alt>c
# Languages=
@ninlith
ninlith / build.txt
Last active February 8, 2024 21:27
Hybrid UEFI/BIOS multiboot USB drive
# Hybrid UEFI/BIOS multiboot USB drive
# Install required packages
sudo apt install gdisk grub2-common grub-efi-amd64-bin grub-pc-bin qemu-system
# Create an empty disk image
target_size=3.6G # $(lsblk -b --output SIZE -n -d /dev/sdX) for drive size
qemu-img create -f raw boottitikku.img "$target_size"
# Create a GUID Partition Table (GPT)
@ninlith
ninlith / mouse-bind.sh
Created November 12, 2019 21:45
A hackish way to bind extra mouse buttons under Wayland.
#!/usr/bin/env bash
# -*- indent-tabs-mode: nil; tab-width: 4 -*-
#
# An ugly way to bind extra mouse buttons under GNOME/Wayland or otherwise.
#
# Prerequisites:
#
# Effectively unbind extra mouse buttons by modifying udev/hwdb rules:
# 1. Identify scancodes:
# sudo evemu-record /dev/input/by-path/*event-mouse \
@ninlith
ninlith / namespaced-openvpn.sh
Created November 6, 2019 15:53
Transfers OpenVPN tunnel interface to a network namespace as its only non-localhost interface.
#!/usr/bin/env bash
# Transfers VPN tunnel interface to a network namespace as its only
# non-localhost interface.
#
# Based on <https://github.com/slingamn/namespaced-openvpn>.
sudo ip netns add protected
sudo ip netns exec protected ip link set lo up
sudo openvpn "$@" --ifconfig-noexec --route-noexec --script-security 2\
@ninlith
ninlith / tablet_mode.py
Last active November 13, 2021 18:08
Tablet mode (disable keyboard etc.) for a Crouton chroot
#!/usr/bin/env python3
# -*- indent-tabs-mode: nil; tab-width: 4 -*-
"""Enable/disable tablet mode in a Crouton chroot based on lid angle."""
import argparse
import logging
import logging.config
import math
import os