Skip to content

Instantly share code, notes, and snippets.

@misebox
misebox / gist:50a7cf988cab3bc329954c64a8b8dc62
Created April 11, 2024 11:39
openapi.jsonからapiclientを生成する
#!/bin/bash -xe
# リポジトリルートへ移動
cd $(dirname $0)/..
# up API server
docker compose up -d --build --wait --quiet-pull api
# openapi.jsonの保存先
@misebox
misebox / utils.ts
Last active April 9, 2024 17:12
TypeScript array utilities
/**
* オブジェクトの配列を辞書化
*/
const indexBy = <T, K extends T[keyof T] & (string | number | symbol)>(arr: T[], getKey: ((t: T) => K)): Record<K, T> => {
return arr.reduce((acc, cur) => {
const key = getKey(cur);
acc[key] = cur;
return acc;
}, {} as Record<K, T>);
};
@misebox
misebox / gist:b110dd38e75418fc2329a744f59dc4a5
Last active October 2, 2023 09:28
/:(.*株式会社.*)/ というテキストを含む h3 要素を探して、: **********に置換する
// /:(.*株式会社.*)/ というテキストを含む h3 要素を探して、: **********に置換する
[...document.querySelectorAll("h3")].forEach(h3 => {h3.innerText?.includes("株式会社") && (h3.innerHTML = h3.innerText.replace(/:.+/, ": **********")) && console.log(h3.innerText)});
[...document.querySelectorAll("p")].forEach(p => {p.innerText?.includes("氏名:") && (p.innerHTML = p.innerText.replace(/氏名:.+/, "氏名:********"))});
[...document.querySelectorAll("a")].forEach(a => {a.href.includes("misebox") && a.remove()});
[...document.querySelectorAll("script")].forEach(s => { s.remove()});
@misebox
misebox / mov2gif.sh
Created June 21, 2023 03:29
The tool that converts a movie file to a compact animation GIF with ffmpeg
#!/bin/bash
if [ $# -lt 1 ]
then
echo "usage: $0 <input video file>"
fi
INPUT_FILE="$1"
OUTPUT_FILE=`echo ${INPUT_FILE} | sed -E 's/\.[^\.]*$//'`.gif
@misebox
misebox / geechs_project_list_parser.py
Last active May 3, 2023 07:36
Parse the text file of the item list from geechs and output TSV
import sys
import pathlib
def parse_project_data(file_path):
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
parts = content.split('=============================')
projects = []
for i in range(0, len(parts)-2, 2):
projects.append(parts[i] + parts[i+1])
#!/bin/bash
# Usage: ./generate-certificates.sh {OUTPUT_PATH (default: ./certs)}
function genclient() {
# Create the client-side certificates
OUT=$1
OPENSSL_CLIENT=$2
docker run --rm -v $OUT:/certs -it nginx \
@misebox
misebox / chunk_util.py
Created April 28, 2022 09:51
chunk and logs
import time
import alog
def chunks(l, n, logging_step=10):
count = 0
total = len(l)
start_time = time.perf_counter()
for i in range(0, len(l), n):
chunk = l[i:i + n]
@misebox
misebox / stopwatch.py
Last active February 1, 2024 03:08
Python Decorator for Function Execution Timing and Call Hierarchy Logging
from functools import wraps
import time
import alog
level = 0
def stopwatch(func):
@wraps(func)
def wrapper(*args, **kwargs):
global level
level += 1
@misebox
misebox / envst-nginx-conf
Last active July 9, 2021 17:46
Script for using environment variables in /etc/nginx/**/*.conf.template
#!/bin/sh
# Create /etc/nginx/**/*.conf from replacing the strings like
# ${NGINX_xxxxx} contained in /etc/nginx/**/*.conf.template
# with the value of each environment variable.
envs="$(env | egrep '^NGINX_' | sed -r 's/^(.+)=.*/\$\$\1/g')"
for template in `find /etc/nginx -name '*.conf.template'`
do
conf=`basename -s .template $template`
@misebox
misebox / base64util.py
Last active June 14, 2021 11:20
URLsafe Base64 encoding and decoding without trailing '='
from typing import Union
import base64
def base64encode(data: Union[bytes, str]) -> bytes:
data = data.encode() if type(data) is str else data
return base64.urlsafe_b64encode(data).rstrip(b'=')
def base64decode(b64: Union[bytes, str]) -> bytes: