Skip to content

Instantly share code, notes, and snippets.

@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:
@unphased
unphased / osxvpnrouting.markdown
Created March 25, 2020 08:19 — forked from taldanzig/osxvpnrouting.markdown
Routing tips for VPNs on OS X

Routing tips for VPNs on OS X

When VPNs Just Work™, they're a fantastic way of allowing access to a private network from remote locations. When they don't work it can be an experience in frustration. I've had situations where I can connect to a VPN from my Mac, but various networking situations cause routing conflicts. Here are a couple of cases and how I've been able to get around them.

Specific cases

Case 1: conflicting additional routes.

In this example the VPN we are connecting to has a subnet that does not conflict with our local IP, but has additional routes that conflict in some way with our local network's routing. In my example the remote subnet is 10.0.x.0/24, my local subnet is 10.0.y.0/24, and the conflicting route is 10.0.0.0/8. Without the later route, I can't access all hosts on the VPN without manually adding the route after connecting to the VPN:

@unphased
unphased / discord.sh
Created May 19, 2017 21:23
A command line (shell) tool for grokking git merge conflicts
#!/bin/bash
# set -x
# PS4='{$LINENO}+'
if [ -t 1 ]; then
# echo "in terminal"
RED=""
RESET=""
BLUE=""
YELLOW=""
function mapObj(obj, cb) {
var mappedObject = null;
var mappedArray = Object.keys(obj).map(function(e, i, a) {
var mapped = cb(e, obj[e], i);
if (mappedObject !== false && Array.isArray(mapped) && mapped.length === 2) {
if (!mappedObject) {
mappedObject = { };
}
mappedObject[mapped[0]] = mapped[1];
// always do the work of normal array mapping, I guess
; This script has a special filename and path because it is automatically
; launched when you run the program directly. Also, any text file whose
; name ends in .ahk is associated with the program, which means that it
; can be launched simply by double-clicking it. You can have as many .ahk
; files as you want, located in any folder. You can also run more than
; one ahk file simultaneously and each will get its own tray icon.
Menu, MyMenu, Add, 4K @30, MenuHandler4K30
Menu, MyMenu, Add, 4K @60, MenuHandler4K
Menu, MyMenu, Add

I use tmux splits (panes). Inside one of these panes there's a Vim process, and it has its own splits (windows).

In Vim I have key bindings C-h/j/k/l set to switch windows in the given direction. (Vim default mappings for windows switching are the same, but prefixed with C-W.) I'd like to use the same keystrokes for switching tmux panes.

An extra goal that I've solved with a dirty hack is to toggle between last active panes with C-\.

Here's how it should work: