Skip to content

Instantly share code, notes, and snippets.

@JanChec
JanChec / setup_sink.sh
Last active August 6, 2018 18:31
Setup system wide DSP sink for Chord Mojo
#!/bin/bash -eu
pacmd list-sinks > /dev/null || pulseaudio -D
pacmd unload-module module-ladspa-sink || true
DEVICE_NAME=$(pacmd list-sinks | grep name: | egrep -o '<[^<>]+Chord[^<>]+>' | egrep -o '[^<>]+')
echo "Setting up PulseAudio to route into: $DEVICE_NAME..."
pacmd load-module module-ladspa-sink sink_name=dsp master=$DEVICE_NAME plugin=ladspa_dsp label=ladspa_dsp
echo "Done."
pacmd set-default-sink dsp
@JanChec
JanChec / print_calls.py
Last active December 12, 2018 15:51
Python - print function calls - decorator and metaclass
# Python textual debugging tool
# A function wrapper to display PID, stack-size indented function name and arguments when it's called.
# Also display similar message when function ends.
# Example output for three wrapped class methods (skips `self` when displaying class method arguments):
21906 P300GuiPeer.send_blink
(blink_id=-1, blink_time=1544627502.9847314)
21906 P300GuiPeer.create_message
(blink_id=-1, blink_time=1544627502.9847314)
@JanChec
JanChec / raw2curl.py
Created August 13, 2019 11:10
Convert raw HTTP request to CURL format (useful for https requests, use nc otherwise)
#!/usr/bin/env python3
import email
import io
import sys
def run():
request_text = sys.stdin.read()
request_line, headers_raw = request_text.strip().split('\n', 1)
@JanChec
JanChec / pbf.py
Created February 9, 2020 16:22
PotPlayer bookmarks file (.pbf) - Python classess for reading/writing
"""
PotPlayer Bookmark File (.pbf)
"""
from dataclasses import dataclass
import datetime
import pathlib
import re
import typing
@JanChec
JanChec / .bashrc_part.sh
Created March 5, 2020 15:02
Set Tmux window name to currently running command
# modified from: https://superuser.com/a/175802/221425
export LAST_COMMAND=''
preexec () { :; }
preexec_invoke_exec () {
[ -n "$COMP_LINE" ] && return # do nothing if completing
[ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return # don't cause a preexec for $PROMPT_COMMAND
local this_command=`HISTTIMEFORMAT= history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//"`;
if [ "$this_command" != '' ]; then
if [ "$LAST_COMMAND" != "$this_command" ]; then
@JanChec
JanChec / clipboard.py
Created January 12, 2023 17:39
Windows 11 pasting from clipboard in Python - unicode text and files
import pathlib
from typing import List
import win32clipboard
def paste() -> str | List[pathlib.Path]:
try:
win32clipboard.OpenClipboard()
try:
@JanChec
JanChec / Shallow clipboard.ahk
Last active April 30, 2023 14:45
Windows 11 - AutoHotkey - Shallow copy on selection and shallow paste on middle click
; This is a shallow clipboard version of:
; https://www.autohotkey.com/board/topic/44064-copy-on-select-implementation/#entry274436
cos_mousedrag_treshold := 20 ; pixels
cos_copied_text := ""
#IfWinNotActive ahk_class ConsoleWindowClass
~lButton::
MouseGetPos, cos_mousedrag_x, cos_mousedrag_y