Skip to content

Instantly share code, notes, and snippets.

@yeiichi
yeiichi / excel_populator.py
Created November 13, 2024 00:17
Populate a template Excel sheet with DataFrame data.
#!/usr/bin/env python3
import time
import pandas as pd
from openpyxl import load_workbook
from openpyxl.utils import coordinate_to_tuple
from openpyxl.workbook.views import BookView
def populate_template_excel(
@yeiichi
yeiichi / mimic_do_while.py
Created November 12, 2024 02:30
Mimic do-while loop with an emergency brake feature.
#!/usr/bin/env python3
"""Mimic do-while loop with an emergency brake feature.
"""
def dummy_func():
for i in range(8):
yield i
@yeiichi
yeiichi / sql_find_kwd.py
Last active November 6, 2024 23:11
Check if the word is an SQL keyword or reserved word.
#!/usr/bin/env python3
import csv
def is_sql_kwd(word_in):
"""Check if the word is an SQL keyword or reserved word.
Args:
word_in (str):
Returns:
bool: If word_in is a SQL keyword/reserved word (True) or not (False).
@yeiichi
yeiichi / sphinmake.zsh
Created November 5, 2024 07:01
Run Sphinx "make html" in a subshell.
#!/usr/bin/env zsh
# Begin Help block
my_name=$(basename "$0")
display_help() {
cat <<EOF
*** Run Sphinx "make html" in a subshell. ***
usage: $my_name <No args are required>
@yeiichi
yeiichi / sphinedit.zsh
Created November 5, 2024 06:59
Open Sphinx reSt file from the project root.
#!/usr/bin/env zsh
# Begin Help block
my_name=$(basename "$0")
display_help() {
cat <<EOF
*** Open Sphinx reSt file from the project root. ***
usage: $my_name <filestem>
@yeiichi
yeiichi / get-dir-info.zsh
Created November 3, 2024 02:32
List content of the specified directories.
#!/usr/bin/env zsh
display-help() {
echo List content of the specified directories.
}
main() {
dir0='/path/to/directory_01'
dir1='/path/to/directory_02'
dir2='/path/to/directory_03'
@yeiichi
yeiichi / remove-bom.zsh
Created October 26, 2024 15:02
Remove the first n characters from the file content.
#!/usr/bin/env zsh
# Reference:
# https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
display_help() {
cat <<EOF
*** Remove the first n characters from the file content. ***
Use me when dos2unix nor nkf doesn't work.
@yeiichi
yeiichi / backup_a_file.py
Last active October 25, 2024 07:23
Make a backup file or a copy in the subdirectory.
#!/usr/bin/env python3
import shutil
from datetime import datetime
from pathlib import Path
def backup_a_file(fpath, action='c'):
"""Make a backup/copy of a file (NOT a directory) in the subdirectory.
Args:
fpath (str): Path to the source file.
@yeiichi
yeiichi / fname_with_epoch.py
Last active October 25, 2024 19:25
Create a filename with the epoch time / Parse an epoch-filename.
#!/usr/bin/env python3
import re
import time
from datetime import datetime, timezone
class FnameWithEpoch:
"""Create a filename with the epoch time / Parse an epoch-filename.
Reference:
File Naming Conventions
@yeiichi
yeiichi / disp-git-status.zsh
Last active October 20, 2024 11:48
Display git status of the projects under the CWD.
#!/usr/bin/env zsh
display_help() {
printf "\033[93m*** Display git status of the projects under the CWD. ***\033[0m\n"
}
main() {
display_help
sleep 3
for project in */; do