Skip to content

Instantly share code, notes, and snippets.

View apolopena's full-sized avatar
💭
We live to learn!

Apolo Pena apolopena

💭
We live to learn!
View GitHub Profile
@apolopena
apolopena / compare_version_numbers.sh
Last active March 27, 2021 00:46
Compares two version numbers: echos 1 if version number ($1) is less than version number ($2), echos 0 if version number ($1) is greater than or equal to version number ($2). Assumes the arguments will use the format of: <any # of digits>.<any # of digits>.<any # of digits>
# split_ver
# Description:
# splits a version number ($1) into three numbers delimited by a space
#
# Notes:
# Assumes the format of the version number will be:
# <any # of digits>.<any # of digits>.<any # of digits>
#
# Usage:
# split_ver 6.31.140
@apolopena
apolopena / change-pma-pws.sh
Last active March 20, 2021 23:15
Automagically change a set of passwords
#!/bin/bash
#
# change-pma-passwords.sh
#
# Description:
# changes passwords for phpmyadmin from the defaults in version control to the values set in .starter.env
# Author: Apolo Pena
#
# NOTE:
# This script should be always run at least once by the user as an mandatory additional layer of security
@apolopena
apolopena / get_env_value.sh
Last active March 20, 2021 23:07
Echos the value of key value pair in a file
#!/bin/bash
# get_env_value
# Description:
# Get the value of a key ($1) value pair as set in a env style file ($2)
# If no file ($2) argument is given then the file .starter.env will be used
#
# Exit codes:
# 3 --> File ($2 or the default .starter.env) does not exist
# 4 --> Variable ($1) does not exist in file ($2 or the default .starter.env)
# 5 --> Value for the variable ($2) was not set or contained only whitespace
@apolopena
apolopena / new-l8-starter
Created March 15, 2021 23:43
ZSH function that creates a new gitpod laravel8 starter repo from a the main branch of https://github.com/apolopena/gitpod-laravel8-starter
# Creates a new project from a branch of the repo https://github.com/apolopena/gitpod-laravel8-starter
# Assumes that you already have a blank repo created for this new project in your github account
# Assumes that you want to use https instead of ssh
# $1: new repo name to clone into and push to remote (the default branch will be called main)
# $2: GitHub username
# new repo name must match the name of the blank repo you have created in github for this project.
__new_repo_project_name="$1"; __github_username="$2"; mkdir "$__new_repo_project_name" && cd "$__new_repo_project_name" && git clone https://github.com/apolopena/gitpod-laravel8-starter.git . && rm -rf .git && git init && git add -A && git commit -m "initial commit built from https://github.com/apolopena/gitpod-laravel8-starter" && git remote add origin "https://github.com/$__github_username/$__new_repo_project_name.git" && git branch -m main && git push -u origin main
@apolopena
apolopena / new-l8-starter-from-branch
Created March 15, 2021 23:42
ZSH function that creates a new gitpod laravel8 starter repo from a specific branch of https://github.com/apolopena/gitpod-laravel8-starter
# Creates a new project from a branch of the repo https://github.com/apolopena/gitpod-laravel8-starter
# Assumes that you already have a blank repo for this project created in your github account
# Assumes that you want to use https instead of ssh
# $1: branch name to clone from
# $2: new repo name to clone into and push to remote (the default branch will be called main)
# new repo name must match the name of the blank repo you have created in github for this project.
# $3: GitHub username
__branch="$1"; __new_repo_project_name="$2"; __github_username="$3"; mkdir "$__new_repo_project_name" && cd "$__new_repo_project_name" && git clone https://github.com/apolopena/gitpod-laravel8-starter.git -b "$__branch" --single-branch . && rm -rf .git && git init && git add -A && git commit -m "initial commit built from the $__branch branch of https://github.com/apolopena/gitpod-laravel8-starter" && git remote add origin "https://github.com/$__github_username/$__new_repo_project_name.git" && git branch -m main && git pu
@apolopena
apolopena / git-delete-tag-or-branch-named-the-same.sh
Created January 28, 2021 08:55
git: deleting remote tags and branches that have the same name
# Scenario:
# When deleting a tag or a branch both have the same name v0.0.1a will result in the error:
# "dst refspec v0.0.1a matches more than one"
# Here is how to delete the branch
git push origin :heads/v0.0.1a
# Here is how to delete the tag
git push origin :tags/v0.0.1a
# @See https://git-scm.com/book/en/v2/Git-Basics-Tagging
# Offical docs @see https://git-scm.com/docs/git-tag
# Output a list of all tags
git tag
# Create a local (annotated) tag for the last commit where v1.4 is the tag name and "ver 1.4 stable" is the tag description
git tag -a v1.4 -m "ver 1.4 stable"
# Create local (annotated) tag from a previous commit where 9fceb02 is the checksum for that commit
@apolopena
apolopena / awk-linebreaks-to-newlines.sh
Created January 22, 2021 22:16
Convert a block of text to a one-liner
# convert line breaks to newline characters
$ awk -v ORS='\\n' '1' file
@apolopena
apolopena / bash-set-and-unset-env-from-file.sh
Last active March 25, 2023 11:14
Set and unset environment variables from an .env file
# set environment vars from an .env file
export $(grep -v '^#' .myenvfile | xargs)
# unset environment vars from an .env file
unset $(grep -v '^#' .myenvfile | awk 'BEGIN { FS = "=" } ; { print $1 }')
@apolopena
apolopena / for-in-vs-reduce.js
Last active November 4, 2020 18:00
Looking at readability of for-in vs reduce
// #1 Easy to read?
const colorStrings = (palette = pastelOne, c = chalk) => {
let r = {}
for (const key in palette) {
r[key] = c.hex(palette[key])
}
return r
}
// #2 Easier to read?