Skip to content

Instantly share code, notes, and snippets.

@unphased
unphased / git-undo
Created May 2, 2025 03:49
Undo n recent commits, or to a specified hash. Easy terminal ux to specify drop or revert (revert will make the undo show in history as a new commit, drop drops those commits)
#!/bin/bash
set -e
# Check for uncommitted changes
if ! git diff --quiet HEAD --; then
echo "Error: Uncommitted changes detected in the working directory or index." >&2
echo "Please commit or stash your changes before running git-undo." >&2
exit 1
fi
@unphased
unphased / bat-lf-previewer.sh
Created April 15, 2025 13:56
bat-lf-previewer-final
#!/bin/bash
# lf Previewer Script with Caching for Performance
#
# Design Goals:
# 1. Fast Scrolling: Avoid re-running expensive generation (like bat) on every scroll.
# 2. Caching: Generate full preview content once per file version, store it.
# 3. Cache Invalidation: Use file modification time (mtime) in cache keys to automatically
# handle file changes.
# 4. Large File Handling: For text-based files, only process the head and tail lines for faster generation.
# 5. File Type Handling: Support various types (text, json, binary, compressed).
@unphased
unphased / bat-lf-previewer
Created April 12, 2025 15:24
bat lf previewer including scroll functionality (snapshot)
#!/bin/bash
# lf Previewer Script with Caching for Performance
#
# Design Goals:
# 1. Fast Scrolling: Avoid re-running expensive generation (like bat) on every scroll.
# 2. Caching: Generate full preview content once per file version, store it.
# 3. Cache Invalidation: Use file modification time (mtime) in cache keys to automatically
# handle file changes.
# 4. Large File Handling: For text-based files, only process the head and tail lines for faster generation.
# 5. File Type Handling: Support various types (text, json, binary, compressed).
@unphased
unphased / gist:81ea09e9ca9b1af749e8134665f49843
Created December 19, 2024 00:11
karabiner elements tweak for my mouse based tab switching macros on Logitech mice in macos
{
"description": "Adapt PC based automations I make in mice (right-ctrl pageup and right-ctrl pagedown) into the corresponding macos tab cycling shortcuts",
"manipulators": [
{
"from": {
"key_code": "page_up",
"modifiers": {
"mandatory": ["right_control"],
"optional": ["any"]
}
@unphased
unphased / replicate.sh
Created December 16, 2024 06:15
replicate
#!/bin/bash
set -e
LOGFILE="$HOME/replicate.log"
exec >> "$LOGFILE"
exec 2>&1
echo "Replicate script started at $(date) for $1 -> $2"
@unphased
unphased / ansihtml.ts
Created April 14, 2024 10:06
ANSI escape sequence to HTML, for illustrative purposes
export const htmlEscape = (str) => {
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
};
export const convertAnsiHtml = (ansi: string) => {
const html_a: string[] = [];
const cleaned_a: string[] = [];
const index_a: number[][] = []; // start locations of escape sequences
const len_a: number[][] = []; // lengths of escape sequences. use these to reconstruct modifications done based on math on cleaned string for raw input (or html) string.
ansi.split('\n').forEach((line) => {
@unphased
unphased / civit_dl
Last active March 21, 2024 18:13
civitai download script
#!/bin/bash
for i in "$@"; do
# Forcibly obtain filename via returned header truncated plain get
FILENAME=$(curl -s -H "Authorization: Bearer $(cat ~/civitai_apikey.txt)" -i -L --range '0-1' "$i" | grep -a Content-Disposition | sed -n 's/.*filename=["]*\([^"]*\)["]*.*/\1/p')
if [ -f "$FILENAME" ]; then
echo "!!!! File $FILENAME already exists. Continuing via -L -C - -O \$filename:"
curl -L -C - -o $FILENAME --retry 4 -H "Authorization: Bearer $(cat ~/civitai_apikey.txt)" "$i"
else
@unphased
unphased / core_nvim_tweaks.md
Last active March 13, 2024 17:35
(Neo-)Vim enhanced navigation

My vim/nvim secret sauce

Here is an overview of some of the core customizations I have built for my own vim/nvim setup over the years. Sometimes I try to explain and share to friends and people online, but it's very difficult to summarize what they are, so I am collecting an overview and code snippets of the current state of my tweaks at the time of writing, here. You can find my full and up to date vim config at my dotfiles repo

Along the way whenever I describe workflows in vim I will highlight the count of keystrokes. In a sort of pragmatic vim golf fashion many of my tweaks are made with an eye toward reducing the number of keystrokes required to achieve a given common task.

Enhanced dot: A search and repeat synergy

@unphased
unphased / clipboard_usage.md
Last active March 11, 2022 00:08
Copying content out of tmux/vim in terminal

This gist is written to address challenges related to copying data out of buffers that you may encounter when using tools in the terminal, in particular in dealing with modern versions of tmux and vim. Care is taken to use these tools with their configuration that is provided out of the box.

Couple of notes:

  • All of this applies across Linux and macOS.
  • Note that the "copied to clipboard" notification you will see in demos below is being generated by the Clipboard Indicator GNOME extension tool. It is useful to demonstrate as it happens when content is successfully preserved into our system clipboard. It also offers very useful clipboard history management, although many other apps can be used for the same purpose. For example, on macOS, I prefer to use the clipboard manager that is built into BetterTouchTool.

Let us proceed!

Outside tmux (plain terminal)

Click+drag to select content. Your terminal emulator will either implicitly g

@unphased
unphased / boxstarter.ps1
Created December 27, 2020 07:42 — forked from jessfraz/boxstarter.ps1
Boxstarter Commands for a new Windows box.
# Description: Boxstarter Script
# Author: Jess Frazelle <[email protected]>
# Last Updated: 2017-09-11
#
# Install boxstarter:
# . { iwr -useb http://boxstarter.org/bootstrapper.ps1 } | iex; get-boxstarter -Force
#
# You might need to set: Set-ExecutionPolicy RemoteSigned
#
# Run this boxstarter by calling the following from an **elevated** command-prompt: