Skip to content

Instantly share code, notes, and snippets.

@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
@yeiichi
yeiichi / parse-outlook.zsh
Created October 9, 2024 03:17
Parse MS Outlook msg file
#!/usr/bin/env zsh
display_help() {
cat <<EOF
parse-outlook:
Extracts emails and attachments saved
in Microsoft Outlook's .msg files
https://github.com/TeamMsgExtractor/msg-extractor
--------------------------------------------------------
@yeiichi
yeiichi / default_permissions.zsh
Last active October 8, 2024 10:32
Reset the permissions to the default (755/644).
#!/usr/bin/env zsh
# Reset the permissions to the default (755/644).
printf '\033[93mReset the permissions to the default (755/644). OK? [y/N] >> \033[0m'
read -r res
[[ "$res" = [yY] ]] && {
find ./ -type d -exec chmod 755 {} \+
find ./ -type f -exec chmod 644 {} \+
@yeiichi
yeiichi / download_w_name.py
Last active October 25, 2024 01:27
Download and save data with an appropriate filename.
#!/usr/bin/env python3
import re
from pathlib import Path
from time import sleep
from urllib.parse import urlsplit
import pandas as pd
import requests
CWD = Path('.')
@yeiichi
yeiichi / dlfromalist.zsh
Created September 30, 2024 09:08
Download files from the URLs listed in a list (one URL per row).
#!/usr/bin/env zsh
display_help() {
cat <<EOF
Download files from the URLs listed in a list (one URL per row).
----------------------------------------------------------------
Usage: dlfromalist <filepath of the URL list>
EOF