Skip to content

Instantly share code, notes, and snippets.

@yeiichi
yeiichi / yconv.bash
Last active April 30, 2024 13:42
Convert Japanese era (JE) to/from Common Era (CE) Calendar
#!/usr/bin/env bash
# Convert Japanese era (JE) to/from Common Era (CE) Calendar
# c.f. https://www.jacar.archives.go.jp/apps/help/chronological_table.html
display_help_message() {
cat <<EOF
$0, Convert Japanese era (JE) to/from Common Era (CE) Calendar
usage: $0 [MTSHR] <year jp>
$0 <year ce>
@yeiichi
yeiichi / ctry_region_finder.py
Created April 27, 2024 07:58
Return region name of the country. (Japanese version)
#!/usr/bin/env python3
def country2region(country_name_jp):
"""Return region name of the country. (Japanese version)
"""
country_name_jp = country_name_jp.strip()
return country_region_200_ja[country_name_jp]
country_region_200_ja = {
@yeiichi
yeiichi / country_region_200_ja.json
Created April 27, 2024 07:11
Country name -> Region name, Japanese version. c.f. mofa-j
{
"アイスランド": "欧州",
"アイルランド": "欧州",
"アゼルバイジャン": "欧州",
"アフガニスタン": "中東",
"アラブ首長国連邦": "中東",
"アルジェリア": "アフリカ",
"アルゼンチン": "中南米",
"アルバニア": "欧州",
"アルメニア": "欧州",
@yeiichi
yeiichi / csv2json.py
Created April 27, 2024 05:58
Convert an n*2 array (CSV) to a JSON file.
#!/usr/bin/env python3
import json
from io import StringIO
import pandas as pd
def csv_to_json(csv_in):
"""Convert an n*2 array (CSV) to a JSON file.
"""
# Load CSV data
@yeiichi
yeiichi / download_html.py
Last active April 20, 2024 15:45
Download html files from the URLs listed in a CSV file.
#!/usr/bin/env python3
from pathlib import Path
from sys import exit
from hashlib import md5
from datetime import datetime
from time import sleep
import pandas as pd
import requests
@yeiichi
yeiichi / concat-csvs.bash
Last active April 19, 2024 10:18
Concatenate CSVs WITH HEADERs and deduplicate HEADERs.
#!/usr/bin/env bash
# c.f. CSVと親しくなるAWK術
# https://future-architect.github.io/articles/20210330/#複数のCSVファイルを1ファイル結合する
echo
echo 'Concatenate CSVs \033[93mWITH HEADERs\033[0m and deduplicate HEADERs.'
read -rp 'glob pattern? >> ' pattern
@yeiichi
yeiichi / renamer.bash
Last active April 12, 2024 07:38
Rename files/directories in the current directory.
#!/usr/bin/env bash
# Rename files/directories in the current directory.
# Unlike bash, sh doesn't implement [[ operator. Thus, the extension is intentionally set to .bash. 
# Help message
if [[ $1 == '' || $1 == '--help' || $2 == '' ]]; then
{
echo 'usage: renamer \033[3mpattern repl\033[0m\n'
exit
}
@yeiichi
yeiichi / r-sqlite-tmpl.R
Last active November 10, 2023 03:34
SQLite template for R language
library(tidyverse)
library(DBI)
# RSQLite is a DBI-compatible interface which means
# you primarily use functions defined in the DBI package,
# so you should always start by loading DBI, not RSQLite:
# c.f. <https://cran.r-project.org/web/packages/RSQLite/vignettes/RSQLite.html>
fetcher <- function(query_in) {
mydb <- dbConnect(RSQLite::SQLite(), "/somewhere/my_db.sqlite3")
@yeiichi
yeiichi / timedelta_calc.cpp
Last active November 2, 2023 08:28
timedelta c++ version w/chrono
//
// timedelta c++ version w/chrono
//
#include <iostream>
#include <chrono>
#include <ctime>
#include <iomanip>
// for the header
@yeiichi
yeiichi / clion_mac_cmake_boost.txt
Last active October 31, 2023 12:22
CLion on Mac CMakeLists script for Boost
# CLion on a Mac with Homebrew-ed Boost C++ Libraries needs the following CMake script.
# c.f. https://intellij-support.jetbrains.com/hc/en-us/community/posts/206607995/comments/360002127239
# c.f. https://formulae.brew.sh/formula/boost
# Ubuntu(sudo apt install libboost-all-dev)/CLion doesn't need the script.
set(Boost_INCLUDE_DIR /usr/local/Cellar/boost/1.83.0/include)
set(Boost_LIBRARY_DIR /usr/local/Cellar/boost/1.83.0/lib)
find_package(Boost 1.83.0)
include_directories(${Boost_INCLUDE_DIR})