Skip to content

Instantly share code, notes, and snippets.

@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() {
@yeiichi
yeiichi / stop_watches.rst
Created July 24, 2024 04:36
Stopwatches for Python/C++

Stopwatches for Python/C++

Python

#import time

start = time.time()
@yeiichi
yeiichi / wget_files.sh
Created July 22, 2024 10:18
Download contiguous HTMLs using wget.
#!/usr/bin/env zsh
# Download contiguous HTMLs using wget.
base='https://example.com/'
for i in {1..9}; do
wget -O "$i".html "$base""$i"/
sleep 3
done
@yeiichi
yeiichi / get_xl_properties.py
Last active July 15, 2024 01:42
Get properties from an excel file.
#!/usr/bin/env python3
from datetime import datetime
from pathlib import Path
import pandas as pd
from natsort import natsorted
from openpyxl import load_workbook
CWD = Path('.')
@yeiichi
yeiichi / webloc2url_list.py
Last active July 14, 2024 07:16
Extract url strings from the webloc files and save them as a CSV file.
#!/usr/bin/env python3
import hashlib
# noinspection PyPep8Naming
import xml.etree.ElementTree as ET
from datetime import datetime
from pathlib import Path
from time import sleep
import pandas as pd
import requests
@yeiichi
yeiichi / msg_header_checker.py
Last active July 13, 2024 00:44
View & check the headers and attachment filename(s) of an EML file.
#!/usr/bin/env python3
from email.header import decode_header
def check_items(msg_):
"""Extract header items from a msg object and Display them.
Args:
msg_ (email.message.Message)
"""
decoded_header = decode_header(msg_.get('subject'))[0] # (b'\x##', 'utf-8')
@yeiichi
yeiichi / load_n_send_eml.py
Last active July 7, 2024 08:58
Load message from an EML file and send it to an SMTP server.
#!/usr/bin/env python3
import email
import email.utils
import smtplib
def load_eml(src_eml):
"""Load message from an EML file.
Returns:
@yeiichi
yeiichi / find_n_mv.sh
Created June 28, 2024 03:07
Move files using find command.
#!/usr/bin/env zsh
# Move files using find command.
find <dir_src> -type f -iregex <pattern> -exec mv {} <dir_dst> \;
@yeiichi
yeiichi / file_mime_typer.py
Created June 24, 2024 09:15
Guess the MIME types of the files in the file directory.
#!/usr/bin/env python3
import mimetypes
from pathlib import Path
CWD = Path('.')
def file_mime_typer(fp):
"""Guess the MIME type of file.