This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eu -o pipefail | |
removeZeroes () { | |
IFS=" " read -ra array <<< "$@" | |
declare -a ltrim=("") | |
declare -a rtrim=("") | |
tmp="" | |
length="${#array[@]}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eu -o pipefail | |
trimArray () { | |
arrayName=$1[@] | |
n=$2 | |
m=$3 | |
array=("${!arrayName}") | |
echo -e "begin:\t[${array[@]}], $n, $m" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 $? | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eu -o pipefail | |
isVowel(){ | |
CHAR=${1:0:1} | |
if [[ "$CHAR" == *[AaEeIiOoUu]* ]]; then | |
echo 0 | |
else | |
echo 1 | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. |