Skip to content

Instantly share code, notes, and snippets.

View alexleone's full-sized avatar

Alex Leone alexleone

View GitHub Profile
@alexleone
alexleone / generate-random-string.sh
Created October 28, 2022 01:48
[Generate secure random string via Openssl] #openssl #random #salt
# Base64 string 20 char legth
openssl rand -base64 20
@alexleone
alexleone / slack-bot.sh
Last active July 25, 2022 16:00
Slack Bot Command Line via Webhook
# This script is used to send a slack notification to the channel configured in the webhook url
# See this page for creating a webhook in slack https://slack.com/help/articles/115005265063-Incoming-webhooks-for-Slack
# To use this script, change the fallback values for the params below
# Update the path to the package.json or set the $VERSION variable before calling this script
# Usage afte updating the script just execute it to send the message ./slack-bot.sh
FALLBACK="${TITLE:-:rocket: Deployed app}"
PRETEXT="${TITLE:-:rocket: Deployed app}"
COLOR="${COLOR:-#36a64f}"
AUTHOR_NAME="${AUTHOR_NAME:-Custom Slack Bot}"
@alexleone
alexleone / unzip-example.sh
Created May 17, 2022 18:16
[unzip xip file] Unzip the .xip type file. #xcode
xip -x file.xip
@alexleone
alexleone / git-delete-all-local-branches-not-on-origin.sh
Last active May 17, 2022 16:58
[Git Delete All Local Branches Not On Origin] #git
git remote prune origin prunes tracking branches not on the remote.
git branch --merged lists branches that have been merged into the current branch.
xargs git branch -d deletes branches listed on standard input.
Be careful deleting branches listed by git branch --merged. The list could include master or other branches you'd prefer not to delete.
To give yourself the opportunity to edit the list before deleting branches, you could do the following in one line:
@alexleone
alexleone / format-hard-drive.sh
Created August 14, 2020 19:53
Format External Hard Drive
# basic usage
diskutil eraseDisk FILE_SYSTEM DISK_NAME DISK_IDENTIFIER
#Formatting a Disk to Mac OS Extended Journaled (JHFS+) from Terminal in Mac OS X
diskutil eraseDisk JHFS+ DiskName /dev/DiskNodeID
#Formatting a Disk to Mac OS Extended (HFS+) from Terminal in Mac OS X
diskutil eraseDisk HFS+ DiskName /dev/DiskNodeID
#Formatting a Disk to MS-DOS fat32 from the Command Line in Mac OS X
diskutil eraseDisk FAT32 DiskName /dev/DiskNodeID
#Formatting a Disk to ExFAT from the Command Line in Mac OS X
diskutil eraseDisk ExFAT DiskName /dev/DiskNodeID
@alexleone
alexleone / flush-dns-cache.sh
Created July 1, 2020 22:40
Flush the DNS cache on your Mac OS X
macbook$ sudo killall -HUP mDNSResponder;sudo killall mDNSResponderHelper;sudo dscacheutil -flushcache
@alexleone
alexleone / docker-utility-conmmands.sh
Created May 5, 2020 16:39
Docker helper commands to list and remove images, container, and volumes.
# Remove all docker images matching pattern
docker images -a | grep "pattern" | awk '{print $3}' | xargs docker rmi
# Force remove all docker images matching pattern
docker images -a | grep "pattern" | awk '{print $3}' | xargs docker rmi -f
# List all images
docker images -a
# Remove all imaages
docker rmi $(docker images -a -q)
@alexleone
alexleone / difference.js
Created April 17, 2020 18:33
Difference between two arrays in javascript ES7.
// Intersection
let intersection = arr1.filter(x => arr2.includes(x));
// For [1,2,3] [2,3] it will yield [2,3]. On the other hand, for [1,2,3] [2,3,5] will return the same thing.
// Difference
let difference = arr1.filter(x => !arr2.includes(x));
// For [1,2,3] [2,3] it will yield [1]. On the other hand, for [1,2,3] [2,3,5] will return the same thing.
// For a symmetric difference, you can do:
let difference = arr1
@alexleone
alexleone / setup-lets-encrypt.sh
Created February 4, 2020 16:00
Set Up Lets Encrypt on Ubuntu 16.04
# Find the repo
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
# Get cert bot
sudo apt-get install python-certbot-apache
# The certbot Let’s Encrypt client is now ready to use.
# Setup cert for one domain
@alexleone
alexleone / wordpress-change-site-name.sh
Last active February 4, 2020 16:11
Use the WP CLI to update a wordpress site url, home url, and the DB references.
# Note the current urls to later be used in DB update
# use the flag --allow-root if only have a root user
wp option get siteurl
wp option get home --allow-root
wp option update home 'https://example.com'
wp option update siteurl 'https://example.com'
# Search and replace all the old urls to reference the new one
wp search-replace 'http://example.test' 'http://example.com'