(reduce #(assoc %1 %2 1) {} ["apn1" "apn2" "apn3"]) {"apn1" 1, "apn2" 1, "apn3" 1}
Wednesday, November 29, 2017
Clojure: vector 2 map
Thursday, November 23, 2017
byobu: avoid terminal scrolling at each status update
Did not find a proper way to avoid terminal scrolling to the bottom when the byobu status is updated.
So, increased the tmux status-interval with a big enough value to not be bothered.
So, increased the tmux status-interval with a big enough value to not be bothered.
vi ~/.byoburc/.tmux.conf
set -g status-interval 86400
Friday, November 3, 2017
PostgreSQL: Table dependencies via Foreign Keys
Source: How to list tables affected by cascading delete
WITH RECURSIVE t AS ( SELECT c.oid AS origin_id, c.oid::regclass::text AS origin_table, c.oid AS referencing_id, c.oid::regclass::text AS referencing_table, c2.oid AS referenced_id, c2.oid::regclass::text AS referenced_table, ARRAY[c.oid::regclass,c2.oid::regclass] AS chain FROM pg_catalog.pg_constraint AS co INNER JOIN pg_catalog.pg_class AS c ON c.oid = co.conrelid INNER JOIN pg_catalog.pg_class AS c2 ON c2.oid = co.confrelid -- Add this line as an input parameter if you want to make a one-off query -- WHERE c.oid::regclass::text = 'YOUR TABLE' UNION ALL SELECT t.origin_id, t.origin_table, t.referenced_id AS referencing_id, t.referenced_table AS referencing_table, c3.oid AS referenced_id, c3.oid::regclass::text AS referenced_table, t.chain || c3.oid::regclass AS chain FROM pg_catalog.pg_constraint AS co INNER JOIN pg_catalog.pg_class AS c3 ON c3.oid = co.confrelid INNER JOIN t ON t.referenced_id = co.conrelid WHERE -- prevent infinite recursion by pruning paths where the last entry in -- the path already appears somewhere else in the path NOT ( ARRAY[ t.chain[array_upper(t.chain, 1)] ] -- an array containing the last element <@ -- "is contained by" t.chain[1:array_upper(t.chain, 1) - 1] -- a slice of the chain, -- from element 1 to n-1 ) ) SELECT origin_table, referenced_table, array_upper(chain,1) AS "depth", array_to_string(chain,',') as chain FROM t where referenced_table ~ 'shared_db'
Labels:
postgresql
Linux: Alert when running process finishes
Source: Alert when running process finishes
(while kill -0 $pid; do sleep 1; done) && echo "finished"
PostgreSQL: Running SQL scripts with psql
Source: Running SQL scripts with psql
PGOPTIONS='--client-min-messages=warning' psql -X -q -a -1 -v ON_ERROR_STOP=1 --pset pager=off -d mydb -f dump.sql
Labels:
postgresql
Subscribe to:
Posts (Atom)