Skip to content

Instantly share code, notes, and snippets.

View gpascale's full-sized avatar

Greg Pascale gpascale

View GitHub Profile
@gpascale
gpascale / pg_size.sql
Created October 2, 2020 20:48
Postgres Size Query - how much disk space used by each table/view
WITH sz AS (
SELECT nspname || '.' || relname AS "relation",
pg_size_bytes(pg_size_pretty(pg_relation_size(C.oid))) / (1024.0 * 1024.0 * 1024.0) AS "size_gb",
pg_size_pretty(pg_relation_size(C.oid)) AS "size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
ORDER BY pg_relation_size(C.oid) DESC
LIMIT 50
)
connection = engine.connect()
trans = connection.begin()
try:
connection.execute("DELETE * FROM blah")
connection.execute("INSERT INTO blah VALUES ('blah')")
trans.commit()
except:
trans.rollback()
raise
@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 )"
@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 / 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=
fetch('/myurl', {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ foo, bar })
})
@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)
-- Lowercase all files in a directory
for f in `ls`; do mv "$f" "`echo "$f" | awk '{print tolower($0)}'`"; done
@gpascale
gpascale / gist:654fbcfbcd2d5edc609e29377c42572a
Created August 23, 2017 21:51
kill process using specific port
lsof -ti :<port> | xargs kill
@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$ "