Skip to content

Instantly share code, notes, and snippets.

View bokwoon95's full-sized avatar
💭
effective. Power لُلُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ 冗

bokwoon95

💭
effective. Power لُلُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ 冗
View GitHub Profile
#!/usr/bin/expect
spawn dlv debug
expect "(dlv) "
foreach bp [lrange $argv 0 end] {
send "break $bp\r"
}
send "continue\r"
interact
-- https://stackoverflow.com/questions/3318727/postgresql-index-usage-analysis
SELECT relname, seq_scan-idx_scan AS too_much_seq,
case when seq_scan-idx_scan>0 THEN 'Missing Index?' ELSE 'OK' END,
pg_relation_size(relid::regclass) AS rel_size, seq_scan, idx_scan
FROM pg_stat_all_tables
WHERE schemaname='public' AND pg_relation_size(relid::regclass)>80000
ORDER BY too_much_seq DESC;
#!/bin/bash
# 1) Install virtualbox https://www.virtualbox.org/wiki/Downloads
# 2) Download the latest ubuntu ISO https://ubuntu.com/download/desktop
# 3) Setup a new Virtualbox VM with the Ubuntu ISO (2GB RAM & 8GB Disk, dynamically allocated. Adjust to taste)
# 4) Install Virtualbox guest additions for the Ubuntu VM
# Open a terminal, run this script
# Add PostgreSQL APT repository https://www.postgresql.org/download/linux/ubuntu/
echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | sudo tee -a /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
@bokwoon95
bokwoon95 / min-sane.sh
Last active May 21, 2020 10:43
minimal sane settings for .tmux.conf + .bashrc/.inputrc
echo "bind R source-file ~/.tmux.conf\\; display \"Reloaded!\"
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
bind e last-window
bind-key @ break-pane \\; last-window
bind-key S choose-window 'join-pane -v -s \"%%\"'
bind-key V choose-window 'join-pane -h -s \"%%\"'
set -sg escape-time 0
#!/bin/bash
sudo apt-get update
sudo apt-get install -y mysql-server
# sudo mysql_secure_installation
echo "
CREATE USER 'pg'@'localhost' IDENTIFIED BY 'pg';
CREATE USER 'pg'@'%' IDENTIFIED BY 'pg';
GRANT ALL PRIVILEGES ON *.* TO 'pg'@'localhost' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'pg'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
@bokwoon95
bokwoon95 / multiprocessor.sh
Last active January 2, 2020 14:41
Run multiple instances of a python script on each file inside a directory concurrently, then merge the results
#!/bin/bash
shopt -s extglob
HELP=" Usage: multiprocessor.sh --pythonscript <script.py> --datadir <data_directory> [--resultdir <result_directory> --removeheaders --jobs <num_of_jobs>]
multiprocessor.sh coordinates multiple instances of the same python script to
run concurrently on files inside the data directory. This allows you to write
python scripts that are single-threaded in nature, and let this script handle
the concurrency.
The only requirement is that the python script print its result to standard
package main
import (
"bytes"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"os"
@bokwoon95
bokwoon95 / crun
Last active March 23, 2020 17:06
Run C files by compiling, executing and deleting the binary. Emulating a C interpreter
#!/bin/bash
in="$1"
out="$(echo "$in" | sed 's/\.c$//g')"
rand="$(date +%s)$(LC_ALL=C tr -dc a-zA-Z0-9 < /dev/urandom | head -c10)"
cleanup() {
rm -rf "$rand$out"
}
trap cleanup EXIT
if ! clang -Wall -Wextra "$in" -o "$rand$out"; then
@bokwoon95
bokwoon95 / drop_tables.sql
Created March 24, 2020 03:57
drop all tables in public schema
DO $$ DECLARE
r RECORD;
BEGIN
FOR r IN
SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname = 'public'
LOOP
EXECUTE 'DROP TABLE ' || quote_ident(r.tablename) || ' CASCADE';
END LOOP;
END $$;
@bokwoon95
bokwoon95 / schemaspy-docker-postgres.sh
Last active March 26, 2025 07:27
How to run Docker SchemaSpy on a locally running Postgres
docker run -v "$PWD/schemaspy_output:/output" schemaspy/schemaspy:latest \
-t pgsql \
-host host.docker.internal \
-port 5432 \
-db my_database \
-u my_username \
-p my_password \
-vizjs
# -host needs to be host.docker.internal to refer to your local machine's localhost,
# not the schemaspy container's localhost. Schemaspy's docker documentation for this is horrible.