Skip to content

Instantly share code, notes, and snippets.

View m-bartlett's full-sized avatar
⛓️

M B m-bartlett

⛓️
View GitHub Profile
@m-bartlett
m-bartlett / README.md
Last active January 19, 2024 22:35
git-like filesystem snapshotting utility which hashes file contents for uniqueness and hardlinks unchanged files to existing hashed files to avoid redundancy

SnapSHAt

This tool uses the existing Python standard library as of 3.11, no external dependencies are needed.

Note

When I was initially began writing this tool I was using SHA256 to compute file hashes but later found empirically that BLAKE2 was considerably faster, and since filesystems can easily exceed millions of files to hash it was a significant speedup to change the hashing algorithm. However, I still feel this pun encapsulates the essence of the tool and couldn't think of a better name.

Features

  • Stores unique file contents in a "blob cache" where the content files are renamed after the hash of their contents (this is similar to how git stores files).
  • Hardlinks files to these hashed blobs. The usefulness of this comes with subsequent snapshots, where presumably the majority of your filesystem is unchanged. Unchanged files will produce the same hash, and therefore can be hardlinked once again to the same blob which reuses the storage in the blob instead of creating a redundant copy o
@m-bartlett
m-bartlett / 0b.bin
Last active February 12, 2024 07:26
Dell XPS 15 9510 / Dell Precision 5560 ELAN touchpad firmware updates (might fix touchpad input lag)
@m-bartlett
m-bartlett / sway-get-window-props
Created May 8, 2023 18:00
Get IPC window properties from clicking on a window in the sway window manager (swaywm). Requires slurp.
#!/usr/bin/env python
import i3ipc
import subprocess
import json
def node_contains_point(node, x, y):
"""Determine if the given point (x,y) is contained by the given node's boundary"""
r = node.rect
return all((x > r.x,
x < (r.x + r.width),
@m-bartlett
m-bartlett / i3dropdown
Last active January 4, 2023 08:53
i3wm native split container guake-like dropdown terminal. The container drops down in animated steps using i3 move commands. In theory this could be extended to make any application dropdown summonable.
#!/usr/bin/env python3
import i3ipc
from time import sleep
DROPDOWN_IDENTIFIER = "dropdown"
DROPDOWN_CHILD_IDENTIFIER = "dropdownchild"
INITIAL_TERMINAL_QUANTITY = 3
TERMINAL_COMMAND = f"terminal -n {DROPDOWN_CHILD_IDENTIFIER}"
HEIGHT_PERCENTAGE = 39
FRAME_STEP = 20
@m-bartlett
m-bartlett / README.md
Last active December 27, 2022 05:50
Generate animated frames of a hyperbolic tree of life.

Hyperbolic Tree of Life Cycle

Generate animated frames of a hyperbolic tree of life. See the --help output for info on using ffmpeg to also generate a video file from the resulting rendered frames.

@m-bartlett
m-bartlett / youtube-playlist
Created August 2, 2022 05:46
Convert a list of YouTube URLs to a single playlist. Open a single tab to watch all the videos instead of opening each video manually.
#!/usr/bin/env bash
# Usage:
# Multiple args: $ youtube-playlist https://youtu.be/############ https://youtu.be/############ ...
# Single delimited arg: $ youtube-playlist 'https://youtu.be/############ https://youtu.be/############ ...'
youtube-playlist() {
local urls=( $(IFS=$'\n'; <<<"$*" grep -o 'v=.*' | cut -f 2 -d=) )
local comma_separated="$(IFS=,; echo "${urls[*]}")"
@m-bartlett
m-bartlett / password_input_with_asterisks.py
Created June 17, 2022 17:40
Python one-filer password input with obscured character echoing for input visual feedback, avoids needing any external dependencies
import sys
import termios
import atexit
def password_input(prompt="Enter password: "):
fd = sys.stdin.fileno()
iflag, oflag, cflag, lflag, ispeed, ospeed, cc = termios.tcgetattr(fd)
def _restore_tty():
termios.tcsetattr(fd, termios.TCSANOW, [iflag,oflag,cflag,lflag|termios.ECHO|termios.ICANON,ispeed,ospeed,cc])
atexit.register(_restore_tty) # restore tty on unexpected exit
@m-bartlett
m-bartlett / click-nm-applet.sh
Created May 17, 2022 19:56
A script to automatically click the nm-applet tray icon so activating the menu can be bound to a keyboard shortcut (requires xdotool)
#!/usr/bin/env bash
declare $(xdotool getmouselocation --shell)
declare _X=$X _Y=$Y
declare $(xdotool getwindowgeometry --shell $(xdotool search --class nm-applet | tail -1))
xdotool \
mousemove $X $Y \
mousemove_relative 7 7 \
click 1 \
mousemove $_X $_Y
@m-bartlett
m-bartlett / gh-md-ToC-generator.js
Last active March 21, 2022 16:10
Generate a markdown Table of Contents by visiting the README page of the repo and pasting this javascript into the browser developer console
// Copied and minified from https://gist.github.com/JamieMason/c43e7ee1d078fc63e7c0f15746845c2e
console.log([].map.call(document.querySelectorAll('.anchor'), function(el) {var indents = ' '.repeat(parseFloat(el.parentNode.nodeName.charAt(1)) - 1);var label = el.parentNode.innerText;var link = el.getAttribute('href');return `${indents}* [${label}](${link})`}).join('\n'))
@m-bartlett
m-bartlett / fetchchan.sh
Created January 23, 2022 01:33
Download all images in 4chan thread(s)
#!/usr/bin/bash
# Usage: fetchchan https://boards.4chan.org/{board}/thread/{thread_id} [...]
# or fetchchan -U in a directory housing a previous fetchchan to download only new images since last fetch
if [[ "$1" == "-U" ]]; then
urls="$(find . -name .url -type f -exec cat {} \;)"
set -- $urls
fi