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 / truncate
Created October 10, 2022 22:02
@cassidoo's interview question from October 10, 2022
MONTASIO:~ andrewrich$ N=3
MONTASIO:~ andrewrich$ STR="never gonna give you up"
MONTASIO:~ andrewrich$ for word in $STR; do echo "${word:0:$N}"; done
nev
gon
giv
you
up
@smartwatermelon
smartwatermelon / passDoor.sh
Created October 17, 2022 18:31
@cassidoo's interview question from October 17, 2022
#!/usr/bin/env bash
set -eu -o pipefail
# initialize vars
allDoors=() # array
# check input
ARGC="$#"
if [[ "$ARGC" -ne 2 ]]; then
echo "Please enter two parameters: number of doors, and number of passes."
@smartwatermelon
smartwatermelon / countSelfChars.sh
Created April 3, 2023 18:28
@cassidoo's interview question from April 2, 2023
#!/usr/bin/env bash
set -eu -o pipefail
# Define function to convert a number to English words
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 )
local num=$1
@smartwatermelon
smartwatermelon / removeZeroes.sh
Created May 3, 2023 01:14
@cassidoo's interview question from April 30, 2023
#!/usr/bin/env bash
set -eu -o pipefail
removeZeroes () {
IFS=" " read -ra array <<< "$@"
declare -a ltrim=("")
declare -a rtrim=("")
tmp=""
length="${#array[@]}"
@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"
@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 / 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 / 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 / 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 / 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.