Skip to content

Instantly share code, notes, and snippets.

@yeiichi
yeiichi / scp2remote.zsh
Created September 3, 2024 00:52
Shortcut for routine SCP.
#!/usr/bin/env zsh
# Constants
tgt='filename.txt' # target file, as always.
dst='[email protected]:directory' # destination
pnr=#### # port number
idf="/path/to/identity_file" # identity file
display_help() {
cat <<EOF
@yeiichi
yeiichi / webloc2url.zsh
Created August 24, 2024 03:13
Extract URL strings from webloc files in a directory.
#!/usr/bin/env zsh
display_help() {
cat <<EOF
Extract URL strings from webloc files in a directory.
EOF
}
extract_urls() {
# Prepare an output filename
@yeiichi
yeiichi / file_sampler.py
Last active August 23, 2024 11:23
Random sample files in the orig dir and move them to the dest.
#!/usr/bin/env python3
from pathlib import Path
from pprint import pprint
from random import sample
from natsort import natsorted
def sampler(orig, dest, size, ptn='*'):
@yeiichi
yeiichi / sqlite_pd_sns_tmpl.py
Created August 18, 2024 13:50
Sqlite3-Pandas-Seaborn flow template
#!/usr/bin/env python3
import sqlite3
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
# https://hellomyworld.net/posts/matplotlib-how-to-resolve-missing-from-current-font-japanese/
plt.rcParams['font.family'] = 'Hiragino Maru Gothic Pro'
@yeiichi
yeiichi / decode_x509.zsh
Created August 14, 2024 09:24
Decode X.509 certificates and keys: PEM, CRT, etc.
#!/usr/bin/env zsh
# Decode X.509 certificates and keys: PEM, CRT, etc.
decode_x509() { openssl x509 -in "$1" -text -noout }
display_help() { echo '\033[93musage: decode509 <pem file>\033[0m\n' }
main() {
[[ -f "$1" ]] && decode_x509 "$1" && return 0
display_help }
@yeiichi
yeiichi / check_remote_eml.zsh
Last active August 12, 2024 08:47
Download a remote eml file and extract an attached zip file.
#!/usr/bin/env zsh
# Description: Download a remote eml file and extract an attached zip file.
src='user@server:path/to/source.eml'
port_num=<ssh port number>
id_file=</path/to/pubkey>
display_help(){
cat <<EOF
check_remote_eml [get cline conv]
@yeiichi
yeiichi / remove_stopwords.py
Last active August 16, 2024 13:43
SEARCH & REMOVE the stopwords from a word list.
#!/usr/bin/env python3
import numpy as np
def str2list(text_in: str, delimiter=';') -> list:
"""Convert a string to a list.
c.f. ast.literal_eval()
"""
crude_list = text_in.split(delimiter) # 'foo; bar' -> ['foo', ' bar']
return [i.strip() for i in crude_list] # ['foo', ' bar'] -> ['foo', 'bar']
@yeiichi
yeiichi / sql_runner.zsh
Created July 31, 2024 10:40
Run a SQL script of choice for the designated DB.
#!/usr/bin/env zsh
display_help() {
cat <<EOF
SQL Runner
----------
Run a SQL script of choice for the designated DB.
Usage: run_sql <foobar.sql>
Prerequisite: DB name: <qux.db>
@yeiichi
yeiichi / add_multi_hot.py
Created July 25, 2024 05:13
Multi-hot-encode the target column data and inner join the resultant table with the original table.
#!/usr/bin/env python3
import re
from pathlib import Path
import pandas as pd
from sklearn.preprocessing import MultiLabelBinarizer
def add_multi_hot_to_df(df_in, target_col: str):
"""Multi-hot-encode the target column data
@yeiichi
yeiichi / rstconv.zsh
Created July 24, 2024 07:46
Convert a reST file into an HTML5 file using rst2html5.py.
#!/usr/bin/env zsh
# References: https://stackoverflow.com/a/16596385/11042987
display_intro() {
printf "\033[93m** Convert a reST file into an HTML5 file **\n"
printf "** using rst2html5.py. **\033[0m\n"
return 0
}
main() {