Skip to content

Instantly share code, notes, and snippets.

View chinthakagodawita's full-sized avatar

Chin Godawita chinthakagodawita

View GitHub Profile
@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%'
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 / 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

@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 / 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
#!/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.

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'