Skip to content

Instantly share code, notes, and snippets.

View gpascale's full-sized avatar

Greg Pascale gpascale

View GitHub Profile
@gpascale
gpascale / bash_cheat_sheet.sh
Last active December 8, 2017 20:21
bash cheat sheet
# Information about arguments and the current script
echo "# arguments called with ----> ${@} "
echo "# \$1 ----------------------> $1 "
echo "# \$2 ----------------------> $2 "
echo "# path to me ---------------> ${0} "
echo "# parent path --------------> ${0%/*} "
echo "# my name ------------------> ${0##*/} "
# Check that a variable is defined and not empty ("")
if [ -z "$1" ]; then
@gpascale
gpascale / 0_reuse_code.js
Created June 5, 2017 00:10
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@gpascale
gpascale / Simple PS1
Created June 25, 2017 23:21
A simple, colorized bash PS1 with just the basics
PS1="\033[32m\u\033[m@\033[33m\h \033[34m\w\n\033[m$ "
@gpascale
gpascale / gist:654fbcfbcd2d5edc609e29377c42572a
Created August 23, 2017 21:51
kill process using specific port
lsof -ti :<port> | xargs kill
-- Lowercase all files in a directory
for f in `ls`; do mv "$f" "`echo "$f" | awk '{print tolower($0)}'`"; done
@gpascale
gpascale / chaitsheet
Last active November 6, 2017 08:12
Chai Cheatsheet
# property validation
expect(result).to.all.have.property('propName');
expect(result).to.all.have.property('propName', 'propVal');
expect(obj).to.have.deep.property('field1.field2').that.is.oneOf([ 0, 1, 2 ])
expect(obj).to.have.deep.property('field1.field2').that.is.within(0, 2)
fetch('/myurl', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ foo, bar })
})
@gpascale
gpascale / psql_conn_str.txt
Created December 24, 2017 20:23
psql connection string
psql --host=mypostgresql.c6c8mwvfdgv0.us-west-2.rds.amazonaws.com --port=5432 --username=
@gpascale
gpascale / extract-jwt.js
Created May 14, 2019 19:10
Extract payload from JWT
const extractJWTPayload = (jwt) => {
const jwtComponents = jwt.split('.');
// A JWT string is divided into 3 components, the second of which
// contains the payload (user information) which is what we care about.
if (jwtComponents.length !== 3)
throw new Error('invalid jwt');
// Base64 decode with urlsafe character set
const decoded = atob(jwtComponents[1].replace(/_/g, '/').replace(/-/g, '+'));
return JSON.parse(decoded).data;
}
@gpascale
gpascale / gist:60bcff2e7a668d7b1adc362d56b0c885
Created February 6, 2020 23:14
bash cwd (dir of script)
"$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"