Skip to content

Instantly share code, notes, and snippets.

@akramarev
akramarev / check-open-handlers-connections.sh
Created September 15, 2022 05:22
[check open (hanging) connections by process id]
lsof -p 66298
@akramarev
akramarev / disable-fks.sql
Created July 12, 2022 02:55
[disable triggers and FK checks in postgres]
-- If SET (or equivalently SET SESSION) is issued within a transaction that is later aborted, the effects of the SET command disappear when the transaction is rolled back. Once the surrounding transaction is committed, the effects will persist until the end of the session, unless overridden by another SET.
SET session_replication_role = 'replica';
...
SET session_replication_role = 'origin';
@akramarev
akramarev / jq-convert-json-csv.sh
Created June 15, 2022 20:26
[Convert JSON to CSV via the Command Line Using JQ]
# https://earthly.dev/blog/convert-to-from-json/
cat simple.json| jq -r '(map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $cols, $rows[] | @csv'
@akramarev
akramarev / install-aws-cli.sh
Created May 25, 2022 21:01
[install aws-cli in an alpine container]
apk add --no-cache \
python3 \
py3-pip \
&& pip3 install --upgrade pip \
&& pip3 install --no-cache-dir \
awscli \
&& rm -rf /var/cache/apk/*
@akramarev
akramarev / tty-width.sh
Created May 25, 2022 20:58
[How to change the width of remote serial console?] tty
stty rows 50 cols 132
@akramarev
akramarev / DistributedDataLoader.ts
Last active June 2, 2022 03:47
[Distributed Data Loader] GraphQL data loaders enhanced by distributed cache #AmplitudeEngineeringHandbook #public
import DataLoader from 'dataloader';
import logger from '../../../logger';
export const REDIS_KEY_DELIMITER = '\x1F'; // ASCII unit separator (31 in hex)
export const REDIS_NULL_VALUE = '\x00'; // ASCII NULL (0 in hex), value is set but it's null
export type RedisNullValueType = '\x00';
export type DistributedDataLoaderOptions<K, V> = DataLoader.Options<
K,
@akramarev
akramarev / get-db-indexes.sql
Last active November 27, 2022 19:20 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
SELECT tablename,
count(1) as count
FROM pg_indexes p
WHERE p.tablename not like 'pg_%'
GROUP BY p.tablename
ORDER BY p.tablename
@akramarev
akramarev / kill.sql
Created April 14, 2022 20:36
[kill connections in postgres]
SELECT
pg_terminate_backend(pid)
FROM
pg_stat_activity
WHERE
-- don't kill my own connection!
pid <> pg_backend_pid()
-- don't kill the connections to other databases
AND datname = 'database_name'
;
@akramarev
akramarev / table-index-size.sql
Created March 18, 2022 19:42
[postgres table and index size]
SELECT
relname as table_name,
pg_size_pretty(pg_total_relation_size(relid)) As "Total Size",
pg_size_pretty(pg_indexes_size(relid)) as "Index Size",
pg_size_pretty(pg_relation_size(relid)) as "Actual Size"
FROM pg_catalog.pg_statio_user_tables
ORDER BY pg_total_relation_size(relid) DESC;
{
"editor_path": "/usr/local/bin/code",
"editor_argument_format": "--goto ${file}:${line}:${col}"
}