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
# 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 |
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 | |
# Generate all permutations of a given string | |
# Usage: permutate "string" | |
permutate() { | |
local string=$1 | |
local prefix=${2:-} | |
local result=() | |
local len=${#string} |
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
$ 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 |
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
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 |
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. |
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
#!/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 | |
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 | |
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 | |
trimArray () { | |
arrayName=$1[@] | |
n=$2 | |
m=$3 | |
array=("${!arrayName}") | |
echo -e "begin:\t[${array[@]}], $n, $m" |
NewerOlder