Skip to content

Instantly share code, notes, and snippets.

View chinthakagodawita's full-sized avatar

Chin Godawita chinthakagodawita

View GitHub Profile

Shows index status, table size and index size. For Postgres <12, from https://dba.stackexchange.com/a/161992

SELECT
  t.tablename,
  indexname,
  c.reltuples AS num_rows,
  pg_size_pretty(pg_relation_size(quote_ident(t.tablename)::text)) AS table_size,
  pg_size_pretty(pg_relation_size(quote_ident(indexrelname)::text)) AS index_size,
 CASE WHEN indisunique THEN 'Y'
#!/usr/bin/env bash
#
# Script to remove GPG user (recipient) with git-crypt
#
# It will re-initialize git-crypt for the repository and re-add all keys except
# the one requested for removal.
#
# Note: You still need to change all your secrets to fully protect yourself.
# Removing a user will prevent them from reading future changes but they will
# still have a copy of the data up to the point of their removal.
@chinthakagodawita
chinthakagodawita / agent-8.7.0--enabled.txt
Created September 12, 2019 16:53
NewRelic PHP Agent memory leak
# 8.7.0.242 (enabled)
ITEM::686504 MEM::45.17578125MB
ITEM::686505 MEM::47.6640625MB
ITEM::686506 MEM::48.33203125MB
ITEM::686507 MEM::48.734375MB
ITEM::686508 MEM::48.74609375MB
ITEM::686543 MEM::48.74609375MB
ITEM::686834 MEM::48.77734375MB
ITEM::686836 MEM::50.14453125MB
@chinthakagodawita
chinthakagodawita / kernel-memory-usage.php
Created September 12, 2019 16:29
PHP memory usage as reported by the kernel
<?php
function memory_get_process_usage()
{
$status = file_get_contents('/proc/' . getmypid() . '/status');
$matchArr = [];
preg_match_all('~^(VmRSS|VmSwap):\s*([0-9]+).*$~im', $status, $matchArr);
if (!isset($matchArr[2][0], $matchArr[2][1])) {
@chinthakagodawita
chinthakagodawita / README.md
Created August 1, 2019 00:48 — forked from shortjared/README.md
If you have ever wanted to grab a marketplace AMI (ex: OpenVPN) you'll know that the process is painful. This solves the pain.

Usage

  • You will need to first make sure you have subscribed to the marketplace product
  • Get the AMI of the marketplace
  • Copy the script to machine
  • awsume (or otherwise authorize) to AWS
  • chmod the script to be executable if needed chmod +x marketplace-ami-encryptor.sh

Usage ./marketplace-ami-encryptor.sh {region} {ami} {name}
Example: ./marketplace-ami-encryptor.sh us-east-1 ami-f6eed4e0 OpenVPN

document.addEventListener("DOMContentLoaded", function(event) {
if ((document.referrer.endsWith('display/redirect') || document.referrer.endsWith('/tests')) && window.location.pathname === '/') {
console.log('Redirecting back to original URL to fix OAUth issue: ', document.referrer);
window.location = document.referrer;
}
});
@chinthakagodawita
chinthakagodawita / postgres_queries_and_commands.sql
Created January 24, 2019 13:32 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@chinthakagodawita
chinthakagodawita / get-shasum.sh
Created August 25, 2015 13:23
Get SHA256 for a homebrew-dh release.
#!/usr/bin/env bash
set -o nounset
tag=""
echo "Enter version tag: "
read tag
curl "https://github.com/chinthakagodawita/docker-hat/releases/tag/$tag" | shasum -a 256
@chinthakagodawita
chinthakagodawita / php-version.fish
Created July 21, 2015 13:12
`php-version` in Fish
function php-version
set -l env_file (mktemp -t php-version.fish.XXXXXXXXXX)
bash -c 'echo "$@"; source $(brew --prefix php-version)/php-version.sh; php-version "$@"; status=$?; env > "$0"; exit $status' $env_file $argv
# apply php-version_* and *PATH variables from the captured environment
echo (cat $env_file)
# and eval (grep '^php-version\|^[^=]*PATH' $env_file | sed '/^[^=]*PATH/y/:/ /; s/^/set -xg /; s/=/ /; s/$/ ;/; s/(//; s/)//')
# clean up
rm -f $env_file
end