Skip to content

Instantly share code, notes, and snippets.

View nmccready's full-sized avatar

nmccready nmccready

View GitHub Profile
SELECT pg_terminate_backend(pid) FROM pg_stat_activity
WHERE
usename = 'USERNAME' AND
client_addr ='IP_ADDRESS';
SELECT * FROM pg_stat_activity WHERE usename = 'USERNAME' limit 50;
select pg_size_pretty(sum(p.total_bytes)) from (SELECT *, pg_size_pretty(total_bytes) AS total
, pg_size_pretty(index_bytes) AS INDEX
, pg_size_pretty(toast_bytes) AS toast
, pg_size_pretty(table_bytes) AS TABLE
FROM (
SELECT *, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes FROM (
SELECT c.oid,nspname AS table_schema, relname AS TABLE_NAME
, c.reltuples AS row_estimate
, pg_total_relation_size(c.oid) AS total_bytes
, pg_indexes_size(c.oid) AS index_bytes
@nmccready
nmccready / globals.js
Created May 22, 2020 17:16
es6 modules globals lost in node 12, 14 when in es6 mode
import { dirname } from 'path';
import { fileURLToPath } from 'url';
// this is rediculous, node 14 / 12 breaking backwards compat
export const __filename = fileURLToPath(import.meta.url);
export const __dirname = dirname(__filename);
global.__filename = __filename;
global.__dirname = __dirname;
NEED_ARG=${1? required}
DEFAULT_ARG=${2:-DEFINED}
echo DEFAULT_ARG: $DEFAULT_ARG
MY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd "$MY_DIR"
cd ../ # normalize to a known working directory could be ../../
@nmccready
nmccready / hack.sh
Created April 28, 2020 13:21 — forked from mbinna/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2357277/hack.sh | sh
#
@nmccready
nmccready / defer.ts
Created March 31, 2020 15:33
Promise.defer
const defer = <T>() => {
let resolve, reject;
const promise = new Promise<T>((_resolve, _reject) => {
resolve = _resolve;
reject = _reject;
});
return {
promise,
resolve,
reject,
@nmccready
nmccready / sourceOrSubshell.sh
Last active May 6, 2020 20:35
check sourced or subshell bash
#!/usr/bin/env bash
function ohHi(){
echo "Hi"
}
(return 0 2>/dev/null) && return || echo "Script is a subshell"
# self invoke if not sourced
@nmccready
nmccready / disable_vim_auto_visual_on_mouse.txt
Created November 22, 2019 14:10 — forked from u0d7i/disable_vim_auto_visual_on_mouse.txt
Disable vim automatic visual mode on mouse select
Disable vim automatic visual mode on mouse select
issue: :set mouse-=a
add to ~/.vimrc: set mouse-=a