Skip to content

Instantly share code, notes, and snippets.

@yeiichi
yeiichi / ren_n_utf8_bklog_csv.py
Last active December 29, 2024 01:03
Rename and re-encode Nulab Backlog CSV files in a directory.
#!/usr/bin/env python3
import re
from pathlib import Path
import pandas as pd
def glob_backlog_csvs(csv_dir):
csv_files = list(Path(csv_dir).glob('Backlog-Issues*.csv'))
if csv_files:
@yeiichi
yeiichi / det_nth_wk_of_month.py
Last active December 24, 2024 21:55
Determine the nth week of the month for a given date string.
#!/usr/bin/env python3
import calendar
from datetime import date
import numpy as np
def ordinal(n):
"""Converts an integer to its ordinal representation.
Reference:
@yeiichi
yeiichi / dates_in_week.py
Created December 15, 2024 00:22
Return the dates within the same week as the given date.
#!/usr/bin/env python3
from collections import namedtuple
from datetime import datetime
def get_week_dates(date_str):
"""Return the dates within the same week as the given date.
Args:
date_str (str): A date string in ISO format (e.g., '2021-01-01').
Returns:
@yeiichi
yeiichi / ical2csv.py
Created December 14, 2024 11:47
Extract dates, locations, and summaries of events within a specified period from an ICS file and save them as a CSV file.
#!/usr/bin/env python3
from datetime import datetime
from pathlib import Path
import pandas as pd
from icalendar import Calendar
def extract_vevents(ics_file, from_yymmdd='1677-09-21', to_yymmdd='2262-04-11'):
"""Extract dates, locations, and summaries of events within a specified period
@yeiichi
yeiichi / isbinary.py
Last active December 9, 2024 02:27
Simple non/binary file classifier. """
#!/usr/bin/env python3
def isbinary(file):
"""Simple non/binary file classifier.
"""
with open(file, encoding='utf8') as f:
try:
f.read(256)
return False
except UnicodeDecodeError:
return True
@yeiichi
yeiichi / sphinclean.zsh
Created November 28, 2024 21:15
Run Sphinx "make clean" in a subshell.
#!/usr/bin/env zsh
# Begin Help block
my_name=$(basename "$0")
display_help() {
cat <<EOF
*** Run Sphinx "make clean" in a subshell. ***
usage: $my_name <No args are required>
@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>