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 / Term.vim
Last active April 14, 2019 13:15
Vim/Nvim reusable terminal buffers(s)
fun! Term(...) abort
let l:currmax=0
let l:currwinnr=win_getid()
for l:bn in range(1,bufnr('$'))
let l:currbufname = bufname(l:bn)
let l:currshellnr = str2nr(bufname(l:bn)[10:-1])
if bufloaded(l:bn) && l:currbufname =~# "term:shell.*" && l:currshellnr != 0
if l:currshellnr > l:currmax
let l:currmax = l:currshellnr
endif
@bokwoon95
bokwoon95 / replace.sh
Last active August 30, 2022 19:13
Search (and Replace) in multiple files using ag
#!/bin/sh
#
# Provides 2 functions
# 1) agf (ag-find) : searches for a string
# 2) ragf (replace-ag-find) : searches for a string and replaces it; displays results
#
# WHY IS THIS NOT A SIMPLE ONE LINER?
# It is a convenience function with shorthand for the inclusion and exclusion list.
# $ ragf "^foo|bar$" "baz" file1 file2 *.csv somedirectory/ :: somedirectory/.gitignore somedirectory/*.log data/
# ┗━━━━━━━ included files ━━━━━━━┛ ┗━━━━━━━━━━━━━━━━ excluded files ━━━━━━━━━━━━━━━━┛
@bokwoon95
bokwoon95 / install-node.sh
Created June 17, 2019 08:17
Node uninstall/install
#!/bin/sh
rm ~/.npmrc
touch ~/.npmrc && echo prefix=~/.npm-packages >> ~/.npmrc
mkdir ~/.npm-packages
curl -L https://www.npmjs.com/install.sh | sh
@bokwoon95
bokwoon95 / joinlines.sh
Last active November 7, 2019 08:53
joinlines.sh
#!/usr/bin/env bash
SCRIPT_PATH=${BASH_SOURCE[0]}
SCRIPT_NAME=${SCRIPT_PATH##*/}
SCRIPT_DIR="$(cd "$(dirname "${SCRIPT_PATH:-$PWD}")" 2>/dev/null 1>&2 && pwd)"
HELP=$(cat <<EOF
Usage: $SCRIPT_NAME <file.csv>
Joins lines in a csv file that are meant to be one line. If CRLF + LF
terminated lines are present, this script will join all LF terminated lines.
@bokwoon95
bokwoon95 / sqlite2mysql.sh
Last active November 14, 2019 17:31
sqlite2mysql.sh
#!/usr/bin/env bash
SCRIPT_PATH=${BASH_SOURCE[0]}
SCRIPT_NAME=${SCRIPT_PATH##*/}
# SCRIPT_DIR="$(cd "$(dirname "${SCRIPT_PATH:-$PWD}")" 2>/dev/null 1>&2 && pwd)"
HELPDOC=$(cat <<HEREDOC
Usage: $SCRIPT_NAME <file.sqlite3> [--db <mysql_database_name> --table <table_name> --user <username> --pass <password> --dumpfile <sql_file> --execute --help]
Dumps an SQLite table into a MySQL table. Requires an sqlite3 database file.
MySQL table will be created if it doesn\'t already exist.
@bokwoon95
bokwoon95 / csv2mysql.sh
Last active November 19, 2019 15:24
Dump a csv file into mysql, creating a table if necessary
#!/usr/bin/env bash
SCRIPT_PATH=${BASH_SOURCE[0]}
SCRIPT_NAME=${SCRIPT_PATH##*/}
# SCRIPT_DIR="$(cd "$(dirname "${SCRIPT_PATH:-$PWD}")" 2>/dev/null 1>&2 && pwd)"
HELPDOC=$(cat <<HEREDOC
Usage: $SCRIPT_NAME <file.csv> [--delim <csv_delimter> --db <mysql_database_name> --table <table_name> --user <username> --pass <password> --execute --help]
Dumps a CSV file into a MySQL table. MySQL table will be created if it
doesn\'t already exist.
@bokwoon95
bokwoon95 / select.sh
Created November 11, 2019 06:06
select.sh
#!/usr/bin/env bash
# Renders a text based list of options that can be selected by the
# user using up, down and enter keys and returns the chosen option.
#
# Usage:
# echo "Select one option using up/down keys and enter to confirm:"
# options=("one" "two" "three")
# select_option "${options[@]}"
# choice=$?
@bokwoon95
bokwoon95 / mysql2csv.sh
Last active November 14, 2019 17:31
dump an SQL file's query into CSV
#!/bin/bash
SCRIPT_PATH=${BASH_SOURCE[0]}
SCRIPT_NAME=${SCRIPT_PATH##*/}
# SCRIPT_DIR="$(cd "$(dirname "${SCRIPT_PATH:-$PWD}")" 2>/dev/null 1>&2 && pwd)"
HELPDOC=$(cat <<HEREDOC
Usage: $SCRIPT_NAME <file.sql> [--db <mysql_database_name> --user <username> --pass <password>]
Dumps the query from a provided SQL file into a CSV file. The CSV file will
be in same place as the SQL file, but with '.csv' appended to the end of it.
@bokwoon95
bokwoon95 / vars.sql
Last active August 8, 2020 15:11
How to use psql, plpgsql and session variables together in one file
-- psql variables can only be used outside functions
-- plpgsql variables can only be used inside functions
-- session variables can be used both outside and inside functions, bridging the gap between the two types of variables
\set func_name vars
\echo '[':func_name'.sql]'
CREATE OR REPLACE FUNCTION :func_name (arg_execute TEXT)
RETURNS VOID AS $$ DECLARE
BEGIN
END;
@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"