Skip to content

Instantly share code, notes, and snippets.

@ben-cohen
ben-cohen / clipper.py
Last active November 23, 2022 20:35
Linux/GTK X11 CLIPBOARD and PRIMARY clipboard sync
#!/usr/bin/python3
#
# Keep the X primary selection and the clipboard
# in sync. Polls regularly and, when one changes,
# it's copied to the other.
#
# To the extent possible under law, Alun Jones has waived all copyright and
# related or neighbouring rights to this work. This work is published from:
# United Kingdom.
#
@ben-cohen
ben-cohen / pipewinch
Last active November 4, 2024 20:15
Forward a terminal with window size changes across a unix domain socket
#!/usr/bin/python3
#
# pipewinch: Forward a terminal with window size changes across a unix
# domain socket.
#
# Usage:
# pipewinch <uds-action> <uds-path> exec ARGS...
# pipewinch <uds-action> <uds-path> term
# where uds-action is "listen" or "connect"
#
// window-size-changed.c: Demo program to handle window changed events
//
// Ben Cohen, July 2022.
//
#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
@ben-cohen
ben-cohen / idleterm.py
Created April 2, 2022 12:22
Open a Linux pty for another process to attach to
#!/usr/bin/python3
#
# idleterm.py: Open a pty so that a process from elsewhere - such as a gdb
# inferior - can attach to it and copy the IO between the pty and
# this process's stdin and stdout.
#
# This is a Python version of the idleterm program at
# https://stackoverflow.com/a/71314902/2319122
#
# Ben Cohen, April 2022.
#!/bin/bash
#
# tmux_pane_wait.sh: Launch an interactive process in a second tmux pane and
# wait for it to complete before continuing the script in the first pane.
#
# Ben Cohen, February 2022.
#
set -x
set -e
if [ -z "$TMUX" ]
@ben-cohen
ben-cohen / git_check_status.sh
Last active July 29, 2021 16:47
Check whether git is in a special state
#!/bin/bash
#
# git_check_status.sh: check whether git is in a special state
#
# Ben Cohen, July 2021
#
# This script returns failure if the current directory is a git worktree
# that is in a special state - merge, rebase, bisect or detached HEAD - or
# returns success if the worktree is in a normal state, or the current
# directory is not a git worktree.
@ben-cohen
ben-cohen / diffpdf.sh
Last active February 16, 2022 13:56 — forked from brechtm/diffpdf.sh
Page-by-page PDF diff tool
#!/bin/bash
# usage: diffpdf.sh file_1.pdf file_2.pdf
# requirements:
# - ImageMagick
# - Poppler's pdftoppm and pdfinfo tools (works with 0.18.4 and 0.41.0,
# fails with 0.42.0)
# (could be replaced with Ghostscript if speed is
# not important - see commented commands below)
@ben-cohen
ben-cohen / pagenumpics.tex
Created November 10, 2020 19:32
LaTeX document with image instead of page numbers
%
% A LaTeX document where images called img-1.jpg, img-2.jpg, ... are
% displayed in the corner of the page instead of a textual page number.
%
% Ben Cohen, November 2020
%
\documentclass{article}
\usepackage{lipsum}
\usepackage{graphicx}
@ben-cohen
ben-cohen / fontlist.sh
Created August 23, 2020 17:13
Use XeLaTeX to create a sampler for each of the fonts available to the local system
#!/bin/bash
#
# fontlist.sh: Create a XeLaTeX document giving samples for each of the fonts
# available to the local system from fc-list, and run XeLaTeX on it ignoring
# errors.
#
# Ben Cohen, August 2020.
#
OUTFILE=fontlist.tex
@ben-cohen
ben-cohen / frametest_unwind.py
Created June 15, 2019 19:18
GDB Python unwinder and frame decorator prototype
#
# GDB Python unwinder and frame decorator prototype
#
# This is a very basic demonstration for how to get GDB to unwind the
# "frametest" example crash in https://github.com/ben-cohen/corelibgen and
# apply a frame decorator to the backtrace.
#
# It needs a recent version of gdb and only works on i386 or x86_64.
# You need to manually fill in the PC value of the crash at "XXX" below!
#