Skip to content

Instantly share code, notes, and snippets.

@baztian
baztian / update-github-deb.sh
Last active April 4, 2024 19:17
Update a debian package that's available as a download/realease on github
#!/bin/bash
set -e
# Check if sufficient arguments are provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <github-repo> <package-name>"
exit 1
fi
@baztian
baztian / xdospeech.py
Created February 19, 2024 13:04
Speech recognition and insert at cursor position
#!/usr/bin/env python3
import subprocess
import sys
import speech_recognition as sr
def get_audio_text(language=None):
language = language or "en-US"
recognizer = sr.Recognizer()
with sr.Microphone() as source:
print("Say something:")
@baztian
baztian / _aws-sso.sh
Last active April 16, 2024 21:17
Allows selecting an aws profile and logs into the account via sso
#!/bin/sh
PROFILE="$1"
if [ -z "$PROFILE" ]; then
PROFILE=$(aws-list-sso-profiles|fzf)
if [ -z "$PROFILE" ]; then
echo No profile selected. Exiting. > /dev/stderr
return
fi
fi
@baztian
baztian / sqs-send-completion.bash
Last active February 27, 2023 15:56
Interactive AWS SQS command line tool
#!/usr/bin/env bash
_sqs_send_completions()
{
local cur=${COMP_WORDS[COMP_CWORD]}
# Don't consider colon (from url) as word break
_get_comp_words_by_ref -n : cur
COMPREPLY=( $( compgen -W "$(aws sqs list-queues --query 'QueueUrls' --output text)" -- $cur ) )
__ltrim_colon_completions "$cur"
}
@baztian
baztian / merge-prs.sh
Last active January 12, 2023 16:49
Command line tool to handle merging of GitHub pull requests
#!/bin/bash
write_main_undo() {
echo git checkout $main_branch >> "$UNDO_FILE"
echo git reset --hard "${main_remote%%/*}" >> "$UNDO_FILE"
echo "Undo instructions written to $UNDO_FILE"
}
if [ -z "$1" ]
then
@baztian
baztian / get_repos.sh
Last active February 2, 2022 21:09 — forked from xalvarez/get_repos.sh
Clone and fork a team's first 100 GitHub repos. Then, add remotes for all potential forks.
#!/usr/bin/env bash
# Clone and fork a team's first 100 GitHub repos. Then, add remotes for all potential forks.
#
# Requires:
# - git: https://git-scm.com/downloads
# - github-cli: https://github.com/cli/cli
# - jq: https://stedolan.github.io/jq/download/
#
# The first time you run this script or use gh for the first time in your system
@baztian
baztian / ansible-play-role-local
Last active December 1, 2021 14:28
Execute ansible role
#!/bin/sh
set -e
if [ $# -lt 1 ]; then
echo "Executes a ansible role on localhost" > /dev/stderr
echo "Usage $(basename $0) ROLENAME [additional ansible-playbook options]" > /dev/stderr
echo "Example: $(basename $0) baztian.keepass -K -b" > /dev/stderr
exit 1
fi
#!/bin/sh
# Source: https://stackoverflow.com/a/28776166/1960601
sourced=0
if [ -n "$ZSH_VERSION" ]; then
case $ZSH_EVAL_CONTEXT in *:file) sourced=1;; esac
elif [ -n "$KSH_VERSION" ]; then
[ "$(cd -- "$(dirname -- "$0")" && pwd -P)/$(basename -- "$0")" != "$(cd -- "$(dirname -- "${.sh.file}")" && pwd -P)/$(basename -- "${.sh.file}")" ] && sourced=1
elif [ -n "$BASH_VERSION" ]; then
(return 0 2>/dev/null) && sourced=1
@baztian
baztian / sqs-copy.sh
Created May 12, 2021 14:08
Create a shell template to copy from one AWS SQS queue to another
#!/usr/bin/env bash
choose_queue()
{
title=$1
queues=$(aws sqs list-queues --query 'QueueUrls' --output text|tr '\t' '\n')
i=1
items=""
items=$(echo -e "$queues"|sed -e 's#.*/##g' | while read p; do echo "$i $p" && i=$((i+1));done)
TMPFILE=$(mktemp)
# lircrc file for squeezelite
begin
button = KEY_PLAYPAUSE
repeat = 0
prog = squeezelite
config = pause
end