Skip to content

Instantly share code, notes, and snippets.

View stephancasas's full-sized avatar

Stephan Casas stephancasas

View GitHub Profile
@stephancasas
stephancasas / straycat.sh
Last active September 29, 2022 19:51
straycat.sh — a minimal HTTP server script for netcat.
#!/bin/sh
# ------------------------------------------------------------------------------
# Straycat.sh HTTP Server (straycat)
# ------------------------------------------------------------------------------
#
# Author:
# Stephan Casas <stephancasas@icloud.com>
#
# Description:
@stephancasas
stephancasas / losecontrol.sh
Last active October 1, 2022 00:58
losecontrol.sh — remove control characters from the logged output of a screen session
#!/bin/sh
# ---------------------------------------------------------------------------- #
# losecontrol.sh
# ---------------------------------------------------------------------------- #
#
# Author:
# Stephan Casas <stephancasas@icloud.com>
#
# Description:
@stephancasas
stephancasas / tmux-send-keys-controls.md
Last active October 2, 2022 15:08
A list of special control sequences you can send to tmux via the send-keys command.

Tmux Send-keys Prefixed Controls

When using the tmux send-keys command, these sequences can be used to control the cursor position or perform other special operations.

This reference is based on my own observations in tmux on Alpine Linux, as I could not find an actual reference for these.

Sequence Description
C-; Send literal "C-"
C-A Move cursor to home
@stephancasas
stephancasas / dterm.sh
Created November 19, 2022 16:25
Connect to an existing Docker container and start an interactive shell (terminal / tty).
dterm() {
# args as `[PROJECT_NAME] [SERVICE_NAME]` or `[CONTAINER_NAME]`
[ -z "$2" ] && CONTAINER_BASE_NAME="$1" || CONTAINER_BASE_NAME="${1}_${2}"
CONTAINER_NAME=$(docker ps --format "{{.Names}}" | grep ^${CONTAINER_BASE_NAME})
if [ $(printf "$CONTAINER_NAME" | wc -l) -gt 1 ]; then
echo "\e[1;31m[!] Multiple container names match \"$CONTAINER_BASE_NAME.\""
echo ">>> If project, add specificity as \`dockertty [PROJECT_NAME] [SERVICE_NAME]\`.\e[0m"
return
@stephancasas
stephancasas / rewire.js
Created December 31, 2022 20:41
A fault-tolerant Livewire $wire.entangle() alternative for AlpineJS
/**
* -----------------------------------------------------------------------------
* $rewire -- A Livewire $wire.entangle() alternative for AlpineJS
* -----------------------------------------------------------------------------
*
* $rewire provides the same functionality as the stock $wire Alpine magic, but
* adds consideration for implementations where Livewire may conditionally
* remove markup referencing undefined properties.
*
* It does this by using a regular expression pattern to check that the Livewire
@stephancasas
stephancasas / skip-forward-45.jxa.js
Created March 29, 2023 17:23
Pocket Casts AppleScript Automation
#!/usr/bin/env osascript -l JavaScript
/**
* ------------------------------------------------------------------------------
* Pocket Casts Automation / Skip Forward
* ------------------------------------------------------------------------------
*
* Skip forward 45 seconds in Pocket Casts for Mac
*
* Note: the window must be open. It may be *hidden*, but it must be open.
@stephancasas
stephancasas / residecar.jxa.js
Created April 3, 2023 21:12
Restart the macOS Sidecar session being hosted by avconferenced
#!/usr/bin/env osascript -l JavaScript
const App = Application.currentApplication();
App.includeStandardAdditions = true;
const BINARY = '/usr/libexec/avconferenced';
function run(_) {
const avconferenced = App.doShellScript(
`ps -A | grep '${BINARY}' | awk '{print $1,$4}'`,
@stephancasas
stephancasas / fast-user-switch.jxa.js
Created April 18, 2023 19:56
JXA macOS Automation: Fast User Switching
#!/usr/bin/env osascript -l JavaScript
const USER = 'stephan';
function run() {
const ControlCenterPID =
$.NSRunningApplication.runningApplicationsWithBundleIdentifier(
'com.apple.controlcenter',
).firstObject.processIdentifier;
@stephancasas
stephancasas / bulk-rename-eml.jxa.js
Last active April 22, 2023 15:59
AppleScript: Bulk-rename export EML messages
#!/usr/bin/env osascript -l JavaScript
const App = Application.currentApplication();
App.includeStandardAdditions = true;
function run(_) {
// Prompt for folder selection.
const dir = `${App.chooseFolder({
withPrompt: 'Select the folder containing your exported messages...',
})}`;
@stephancasas
stephancasas / axnotifications.swift
Created May 10, 2023 13:02
Attach-to/Observe Every (Documeted) AXNotification
/// Where `axApplication` is an instance of an AXUIElement application and `self` is the receiving notification class.
AXObserverAddNotification(observer, axApplication, kAXMainWindowChangedNotification as CFString,
UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque()));
AXObserverAddNotification(observer, axApplication, kAXFocusedWindowChangedNotification as CFString,
UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque()));
AXObserverAddNotification(observer, axApplication, kAXFocusedUIElementChangedNotification as CFString,
UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque()));
AXObserverAddNotification(observer, axApplication, kAXApplicationActivatedNotification as CFString,
UnsafeMutableRawPointer(Unmanaged.passUnretained(self).toOpaque()));