Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / check-open-handlers-connections.sh
Created September 15, 2022 05:22
[check open (hanging) connections by process id]
lsof -p 66298
@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
git remote prune origin
git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}' | xargs git branch -D