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
@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 / 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
package main
import (
"bytes"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"os"
@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
#!/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 / 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
# 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 -
-- 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;
#!/usr/bin/expect
spawn dlv debug
expect "(dlv) "
foreach bp [lrange $argv 0 end] {
send "break $bp\r"
}
send "continue\r"
interact
@bokwoon95
bokwoon95 / dump_tar_xz_contents.sh
Created November 18, 2019 08:03
Dump the list of filenames of all *.tar.xz files in the current directory into a text file (parallelized by xargs)
#!/bin/bash
dump_tar_xz_contents() {
total="$1"
index="$2"
file="$3"
file_without_extension="$(basename "$file" .tar.xz)"
echo "[START][$index/$total] $file"
tar tf "$file" > "$file_without_extension.txt"
echo "[END][$index/$total] $file"