This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn apply-if | |
"if(p(m)) then f(m, ...args) else m | |
Useful for `maybe-*` like updates." | |
[m p f & args] | |
(if (p m) | |
(apply f m args) | |
m)) | |
(defn fork [l c r] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create extension postgres_fdw ; | |
create server dev foreign data wrapper postgres_fdw options (host 'localhost', dbname 'db_dev'); | |
select user; | |
create user mapping for my_user server dev options (user 'my_user' ); | |
create schema dev; | |
import foreign schema public limit to ( table_to_copy ) from server dev into dev; | |
select * from dev.table_to_copy; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
D create table test as SELECT i as i ,random() as r, i%4 as gr from generate_series(1,100) t(i); | |
D select * from test; | |
┌───────┬──────────────────────┬───────┐ | |
│ i │ r │ gr │ | |
│ int64 │ double │ int64 │ | |
├───────┼──────────────────────┼───────┤ | |
│ 1 │ 0.14984029697949075 │ 1 │ | |
│ 2 │ 0.20274345139105418 │ 2 │ | |
│ 3 │ 0.07478489612107744 │ 3 │ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
r.table_name | |
FROM information_schema.constraint_column_usage u | |
INNER JOIN information_schema.referential_constraints fk | |
ON u.constraint_catalog = fk.unique_constraint_catalog | |
AND u.constraint_schema = fk.unique_constraint_schema | |
AND u.constraint_name = fk.unique_constraint_name | |
INNER JOIN information_schema.key_column_usage r | |
ON r.constraint_catalog = fk.constraint_catalog | |
AND r.constraint_schema = fk.constraint_schema |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# deps jq curl 'http httpie' | |
deps() { | |
for dep in "$@"; do | |
read cmd package <<<"$dep" | |
package=${package:-$cmd} | |
mute which "$cmd" || | |
apt install -y $package || | |
exit 1 | |
done | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
pg_conf_file=/var/lib/postgresql/data/postgresql.conf | |
echo "\ | |
log_statement = 'all' | |
log_disconnections = off | |
log_duration = on | |
log_min_duration_statement = -1 | |
shared_preload_libraries = 'pg_stat_statements' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def testing(fname): | |
print(fname) | |
cmds = { "testing": testing } | |
if __name__ == "__main__": | |
cmds[sys.argv[1]](*sys.argv[2:]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ropsql() { | |
PSQLRC=<( | |
cat ~/.psqlrc && | |
echo 'set session characteristics as transaction read only;') \ | |
psql "$@" | |
} | |
mb:ropsql() { | |
`aws secretsmanager get-secret-value --secret-id "${1? secret arn needed }" | jq '.SecretString | fromjson | "ropsql -d \(.mb_db_connection_uri | sub("&loginTimeout.*"; ""))"' -r` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def testing(foo, fname, **kwargs): | |
"""This is functions does this and that. | |
The longer explanation is here | |
""" | |
print(foo, fname, kwargs) | |
def parse_args(a=[]): | |
r, extra = [], [] | |
for i in a: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def testing(foo, fname, **kwargs): | |
print(foo, fname, kwargs) | |
def parse_args(a=[]): | |
r, extra = [], [] | |
for i in a: | |
if re.match("^--[^-].*=.+", i): | |
r.append(re.split("=", i[2:], 2)) | |
else: | |
extra.append(i) |