Skip to content

Instantly share code, notes, and snippets.

@sdkks
sdkks / README.md
Created October 18, 2023 02:26 — forked from pdanford/README.md
Launching iTerm2 from macOS Finder

Launching iTerm2 from macOS Finder

(Based on info from Peter Downs' gitub but with modified behavior to open a new terminal window for each invocation instead of reusing an already open window.)

The following three ways to launch an iTerm2 window from Finder have been tested on iTerm2 version 3+ running on macOS Mojave+.

pdanford - April 2020


@sdkks
sdkks / git-commit-push.sh
Created February 5, 2023 12:03
Write a multiline git commit message and push directly
c(){
# Stage only modified files
# This ignores new/untracked files
git add -u .
# Use CTRL+D to end commit message
local COMMIT_MSG=$(cat)
if [[ -z "$COMMIT_MSG" ]]; then
return
@sdkks
sdkks / xargs-example.sh
Created February 1, 2023 07:46
Export variables and functions to use with xargs in parallel mode
#!/usr/bin/env bash
# Bash strict mode
# Error on undefined variable: -u
# Exit on ERR: -e
# Functions inherit ERR traps: -E
# Exit on pipe failures: -o pipefail
set -eEuo pipefail
# Directory of this script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
@sdkks
sdkks / userChrome.css
Created January 31, 2023 13:55
Customize Firefox Toolbar Layout with userChrome.css
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); /* only needed once */
/* Placing the config file */
/* Go to about:support address, find Profile folder, open it */
/* Create an empty directory named `chrome` in that */
/* Add this file in that directory with name userChrome.css */
/* Activating the configuration */
/* Go to address about:config, then set => toolkit.legacyUserProfileCustomizations.stylesheets: true */
@sdkks
sdkks / backup_neovim.zsh
Created January 24, 2023 14:31
Backup Vim Plugin State for "Plug"
# vim:set ft=sh:
backup_neovim(){
/usr/local/bin/nvim -S $DOTFILES/vim/plug_snapshot.vim
}
restore_neovim(){
/usr/local/bin/nvim -S $DOTFILES/vim/nvim.lock
}
@sdkks
sdkks / myscript.py
Last active February 23, 2022 14:55
Stop AWS instances with matching tags
#!/usr/bin/env python3
# Assumes you have Python 3 and boto3 installed in your [virtual]env
# Assumes we are taking positional parameters (this script could be longer with argparse)
# Assumes you have AWS_PROFILE and AWS_DEFAULT_REGION set and credentials are valid and not expired at ~/.aws/credentials
import boto3
import json
from sys import argv, exit
if len(argv) != 3:
@sdkks
sdkks / README.md
Last active March 5, 2024 06:17
How to SSH to Kubernetes Pod with SSH ProxyCommand using socat

Requirements

  1. socat
  2. kubectl with proper ~/.kube/config that can connect to your cluster
  3. Working knowledge of kubectl client
  4. OpenSSH client

How does it work?

  1. kubectl does port forwarding to sshd port of your pod. I'm using pm2 process managed to keep my services alive in my workstation container. If you have only sshd, easiest to use is dropbear
  2. ProxyCommand of OpenSSH client uses socat to redirect two way fd - to forwarded port of kubectl
  3. Voila! You are in
@sdkks
sdkks / README.md
Last active September 22, 2018 05:08
Windows how to copy paste like Mac OSX terminal using Alt instead of CMD in Linux Terminal Emulators with AHK AutoHotKey

HOW TO

Why

Copy Paste (CTRL+C) command doesn't work for Linux terminals as CTRL+C is used for SIGINT signal to stop/interrupt works on Linux shell.

Prerequisites

You are on Windows but need to have Linux shell like bash or zsh and using one of popular terminal emulators

Steps

  1. Download and Install AHK (AutoHotKey) // https://autohotkey.com/
  2. Put copy-paste.ahk anywhere in your machine and double click after saving it.
  3. Voila, now Alt + C (same position as CMD + C) will work just like Macbook on most of Linux Terminal emulators on Windows (tested with Cmder, MinTTY, Hyper.JS)
@sdkks
sdkks / .profile.ps1
Last active September 15, 2018 08:00
How to use Hyper.JS with PowerShell to Connect to your Kubernetes (K8S) Workstation Terminal
Set-PSReadlineOption -EditMode Emacs
$env:KUBECONFIG="c:\Users\<your path to special kubeconfig for your gke/eks/aks cluster>\kube-config"
kubectl get pod | Select-String "ws-" | Select-String "Running" | %{ "$_".split(" ")[0]} | %{kubectl exec -ti $_ -- su - said}
@sdkks
sdkks / .vacuum-nodes.sh
Created July 14, 2018 15:40
Vacuum journalctl of nodes in your inventory
#!/usr/bin/env bash
exitCode(){
case $1 in
0)
echo "Completed with success"
;;
*)
echo "Exited with failure: $1"
;;