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 pg_terminate_backend(pg_stat_activity.pid) | |
| from pg_stat_activity | |
| where pg_stat_activity.datname = '<db_name>' -- ← change this to your db | |
| and pid <> pg_backend_pid() and usename = '<user>' | |
| ; |
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
| # get listing of files in file tree with glob-like searching | |
| files = [f for f in glob.glob(SOURCE_DIR + '/**/af*.xlsx', recursive=True)] |
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
| -- generates 5000000 rows of random data | |
| select i | |
| ,now() - (random() * (interval '100 years')) | |
| ,(array['1', '2'])[floor(random() * 2 + 1)] | |
| from pg_catalog.generate_series(100000001, 105000000, 1) s(i) | |
| ; |
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
| # take a load of boolean flag columns (names beginning with f_) and produce a column that lists which flags the row is true for | |
| concat_flags <- function(x){ | |
| separator = ';' | |
| a <- paste0(names(x)[as.logical(x)], sep = separator) | |
| ifelse(a == separator, NA, a) | |
| } | |
| data$concat_flags <- apply(data[,colnames(data)[startsWith(colnames(data), "f_")]], 1, concat_flags) |
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
| Function GetFillColor(Rng As Range) As Long | |
| GetFillColor = Rng.Interior.ColorIndex | |
| End Function | |
| # to use this: | |
| # 1. open the visual basic editor (alt + F11 or fn + alt + f11) | |
| # 2. paste the above code | |
| # 3. save then quit and return to the workbook |
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
| /* use user:password for superuser on https://cnfl.extge.co.uk/display/CDT/_Logins */ | |
| psql metrics -h localhost -p 5441 -U postgres | |
| create database <db_name>; | |
| grant all privileges on database <db_name> to cdt_user; |
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
| brew services stop postgresql | |
| rm /usr/local/var/postgres/postmaster.pid | |
| brew services start postgresql |
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 progress_bar(iterable, prefix='Progress', suffix='Complete', decimals=1, | |
| length=50, fill='=', printEnd="\r"): | |
| """ | |
| shows a terminal progreess bar as iterations are passed through, use as | |
| for i in progress_bar(range(1000)): | |
| pass | |
| :params: iteration: current iteration | |
| :params: total: total iterations | |
| :params: prefix: prefix string | |
| :params: suffix: suffix string |
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 sequence testes.test_id_seq | |
| ; | |
| create or replace function pseudo_encrypt(value int) returns int as $$ | |
| declare | |
| l1 int; | |
| l2 int; | |
| r1 int; | |
| r2 int; | |
| i int:=0; |
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 | |
| current_time=$(date "+%Y%m%d-%H%M") | |
| file_name="db_bu_$current_time.sql" | |
| echo $file_name | |
| pg_dump -h 10.1.24.39 -U cdt_user --schema consent_audit metrics > $file_name |