Skip to content

Instantly share code, notes, and snippets.

View smartwatermelon's full-sized avatar
🏠
Working from home permanently

Andrew Rich smartwatermelon

🏠
Working from home permanently
View GitHub Profile
@smartwatermelon
smartwatermelon / calculateIngredients
Last active April 21, 2025 23:37
@cassidoo's interview question from April 20, 2025, in Bash
# one-liner in Bash
$ target=3; for i in "flour:200" "sugar:100" "eggs:2"; do echo "${i%%:*}:$(( ${i##*:} * target ))"; done
flour:600
sugar:300
eggs:6
@smartwatermelon
smartwatermelon / permute.sh
Created January 6, 2025 19:52
@cassidoo's interview question from January 5, 2025, in Bash
#!/usr/bin/env bash
set -eu -o pipefail
# Generate all permutations of a given string
# Usage: permutate "string"
permutate() {
local string=$1
local prefix=${2:-}
local result=()
local len=${#string}
@smartwatermelon
smartwatermelon / newYearsDay
Last active January 2, 2025 22:01
@cassidoo's interview question from December 30, 2024, in Bash
$ newYearsDay(){ date -v "${1:-$(date +"%Y")}y" -v 01m -v 01d +"%A"; }
$ newYearsDay 2025
Wednesday
$ newYearsDay 2024
Monday
$ newYearsDay # default value is current year
Wednesday
@smartwatermelon
smartwatermelon / transmission.conf
Last active November 17, 2024 00:08
nginx config to make Transmission accept https connections from internal network without password prompt
server {
listen 443 ssl;
server_name YOUR_TRANSMISSION_HOST_NAME;
ssl_certificate /usr/local/etc/nginx/ssl/nginx.crt;
ssl_certificate_key /usr/local/etc/nginx/ssl/nginx.key;
# you should create a self-signed cert:
# sudo mkdir -p /usr/local/etc/nginx/ssl
# sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /usr/local/etc/nginx/ssl/nginx.key -out /usr/local/etc/nginx/ssl/nginx.crt
@smartwatermelon
smartwatermelon / murder-vpcs.sh
Created July 25, 2024 02:19
Murder Your VPCs
#!/bin/bash -ex
# Do you have VPCs or other AWS network resources you just can't get rid of?
# Circular dependencies, ownership issues?
# This script will do its very best to murderize them for you. If it can't,
# it will tell you what permissions need to be added (assuming you can add
# permission polices to your AWS CLI user) or dependencies need to be manually
# deleted (e.g. route tables, ENIs, etc).
# Good luck.
@smartwatermelon
smartwatermelon / countAndSay.sh
Last active August 29, 2023 23:33
@cassidoo's interview question from August 28, 2023
#!/usr/bin/env bash
set -eu -o pipefail
# Define function to convert a number to English words
# this function is lifted from my countSelfChars solution from April 2, 2023:
# https://gist.github.com/smartwatermelon/ab9b5886128e9120b1ad3deebb2f320f
function num_to_words {
local ones=( '' one two three four five six seven eight nine )
local tens=( '' '' twenty thirty forty fifty sixty seventy eighty ninety )
local specials=( ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen )
@smartwatermelon
smartwatermelon / numGuess.sh
Created August 24, 2023 23:45
@cassidoo's interview question from August 20, 2023
#!/usr/bin/env bash
set -eu -o pipefail
TRIES=0
NUM="${RANDOM}" # 0-32767
read -p "Your guess: " GUESS
(( TRIES+=1 ))
while [ $GUESS -ne $NUM ]; do
if [ $GUESS -lt $NUM ]; then
echo "guess higher!"
@smartwatermelon
smartwatermelon / faultyKeeb.sh
Last active August 19, 2023 23:02
@cassidoo's interview question from August 13, 2023
#!/usr/bin/env bash
set -eu -o pipefail
isVowel(){
CHAR=${1:0:1}
if [[ "$CHAR" == *[AaEeIiOoUu]* ]]; then
echo 0
else
echo 1
fi
@smartwatermelon
smartwatermelon / reversedSquares.sh
Created July 3, 2023 18:34
@cassidoo's interview question from July 2, 2023
#!/usr/bin/env bash
set -eu -o pipefail
isPerfect() {
NUM=$1
SQRT=$( bc -l <<< "sqrt ($NUM)" )
INT_SQRT=$( cut -d '.' -f 1 <<< "$SQRT" )
SQ_INT_SQRT=$( bc -l <<< "$INT_SQRT ^ 2" )
test $NUM -eq $SQ_INT_SQRT; echo $?
}
@smartwatermelon
smartwatermelon / trimArray.sh
Created June 16, 2023 15:52
@cassidoo's interview question from June 11, 2023
#!/usr/bin/env bash
set -eu -o pipefail
trimArray () {
arrayName=$1[@]
n=$2
m=$3
array=("${!arrayName}")
echo -e "begin:\t[${array[@]}], $n, $m"