Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
#
# Script to demonstrate capturing the exit status of a sub shell command while assigning the output to a local variable
test() {
local inline_declaration_and_definition=$(exit 3)
echo $? # output: 0
local separate_declaration_and_definition
separate_declaration_and_definition=$(exit 3)
echo $? # output: 3
@odellt
odellt / split-string-into-array.sh
Created November 1, 2019 10:21
Splits a comma delimited string into an array
#!/bin/bash
#
# Script to split a string based on the delimiter
input_string=$1
IFS=$2 read -ra string_split <<< "$input_string"
#Print the split string
for i in "${string_split[@]}"
do
@odellt
odellt / strip-all-whitespace.sh
Created November 1, 2019 10:20
Strips all whitespace from an input string
#!/bin/bash
#
# Script to strip all whitespace characters from a string
input_string=$1
trimmed_input_string="$(echo -e "${input_string}" | tr -d '[:space:]')"
echo "|${trimmed_input_string}|"
@odellt
odellt / gist:68537f3c744bda1a097ed9c6b52af64b
Last active October 31, 2019 14:54 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
@odellt
odellt / .bash_aliases
Created October 16, 2019 13:50 — forked from vratiu/.bash_aliases
Git shell coloring
# Customize BASH PS1 prompt to show current GIT repository and branch.
# by Mike Stewart - http://MediaDoneRight.com
# SETUP CONSTANTS
# Bunch-o-predefined colors. Makes reading code easier than escape sequences.
# I don't remember where I found this. o_O
# Reset
Color_Off="\[\033[0m\]" # Text Reset
#!/usr/bin/env bash
usage="Usage: $(basename "$0") region stack-name [aws-cli-opts]
where:
region - the AWS region
stack-name - the stack name
aws-cli-opts - extra options passed directly to create-stack/update-stack
"
@odellt
odellt / Nodejs-Require-Module-Resolution.md
Created September 25, 2019 12:15
Description of how Nodejs handles files and directories with the same name

Nodejs Require Module Resolution

// ./main.js
require('./example-module').whoami();

// ./example-module.js
module.exports.whoami = () => console.log(`Hello, I'm a file`);
// Output: ./example-module.js
@odellt
odellt / defaultFunctionArgumentExample.js
Last active September 25, 2019 12:09
Demonstration of default arguments in a function
function speak(phrase = 'Hello World!') {
console.log(phrase);
}
speak();
// Output: Hello World!
speak(undefined);
// Output: Hello World!
@odellt
odellt / GitHelpers.sh
Last active November 23, 2021 11:04
Helper commands for git
# Command to call git status -s on all repositories in a directory
find . -maxdepth 1 -mindepth 1 -type d -exec sh -c '(echo {} && cd {} && git status | sed "s/[(][^)]*[)]//" | sed '/^[[:space:]]*$/d' && echo)' \;
# Command to delete local branches that have been merged, except special branches
git branch --merged | egrep -v "(^\*|master|production|other-special-branch)" | xargs git branch -d
# Command to pull a pull request locally
git pull origin pull/[PR_ID]/head
# Commands to delete all tags local and remote
@odellt
odellt / DockerHelpers.sh
Last active January 6, 2020 10:58
Helper commands for docker management
#! bin/sh
# Docker Helpers
# List all containers by ID
docker ps -aq
# Stops all docker containers
docker stop $(docker ps -aq)
# Remove all containers