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 <[email protected]>
#
# 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 <[email protected]>
#
# 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 / macos-modifier-keys-dec-map.json
Last active October 25, 2024 01:28
macOS Modifier Keys Decimal Values Map
{
"65536": [
"alphashift"
],
"131072": [
"shift"
],
"196608": [
"alphashift",
"shift"
@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 / ventura_messages.m
Created February 3, 2023 01:09
Query the attributedBody column in the updated macOS Ventura Messages database
//
// ventura_messages.m
// macOS Ventura Messages DB Query Example
//
// Created by Stephan Casas on 2/2/23.
//
#import <Foundation/Foundation.h>
@implementation NSData (NSDataExtended)
@stephancasas
stephancasas / toggle-ventura-sidecar.jxa.js
Last active November 12, 2024 11:19
Toggle sidecar or screen mirroring from Control Center in macOS Ventura
#!/usr/bin/env osascript -l JavaScript
/**
* -----------------------------------------------------------------------------
* Activate Sidecar/Screen Mirroring from Control Center
* -----------------------------------------------------------------------------
*
* Created on February 17, 2023 by Stephan Casas
* Updated on May 18, 2023 by Stephan Casas
*
@stephancasas
stephancasas / AdvancedToolbarWindow.swift
Last active September 22, 2024 12:55
A SwiftUI-compatible window for macOS with advanced toolbar configurability.
//
// AdvancedToolbarWindow.swift
//
// Created by Stephan Casas on 3/17/23.
//
import SwiftUI;
import AppKit;
class AdvancedToolbarWindow<MainContent: View, ToolbarContent: View, TitleToolbarContent: View>: NSWindow, NSToolbarDelegate {
@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.