Skip to content

Instantly share code, notes, and snippets.

View yuwash's full-sized avatar

Yushin Washio yuwash

View GitHub Profile
@yuwash
yuwash / imagebatch.py
Created December 14, 2025 12:03
Image batch processing (rename, remove background, crop, paste into pptx)
import argparse
import os
import sys
import re
import shutil
from PIL import Image, ImageDraw
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.enum.shapes import MSO_SHAPE
from pptx.dml.color import RGBColor
@yuwash
yuwash / armv
Created August 6, 2023 21:41
Archive Move
# Armv "Archive Move"
# A command to write a "moved.txt" file in the source directory with a
# list of files moved and the destination.
# The command also moves all the files to the destination.
# Usage: armv source/path dest/path
FROM_PATH="$1"
TO_PATH="$2"
MOVED_FILE_HEADER="TO: $(realpath "$TO_PATH")"
@yuwash
yuwash / pulsate.sh
Created January 27, 2021 12:41
Pulsate following a pattern
#! /usr/bin/env bash
pulsate_once () {
export delay="$1"
echo -n O
sleep "$delay"
}
pulsate_word () {
word="$1"
@yuwash
yuwash / benchmark.py
Created January 5, 2021 10:34
Benchmark for empty lists
import argparse
def create_data(amount=50):
return [
{"content": "abcdefghijkl"} for __ in range(amount)
]
def create_data_empty_list(amount=50):
@yuwash
yuwash / paperformat.py
Created August 2, 2020 16:24
Find best-fit of tessarating two paper formats on each others
from itertools import product
dumplings = (352, 175) # Kartoffel Knödel 4000400130570
a5 = (210, 148)
def min_mod(x1, x2, n1_max):
def mod_for_n1(n1):
return (x1*n1) % x2
return min((mod_for_n1(n1), n1) for n1 in range(1, n1_max))
@yuwash
yuwash / plan_recurrent_charge.py
Created January 30, 2020 21:49
Calculate optimal standing order for prepaid account
#!/usr/bin/env python
import datetime
current_balance = 450
desired_buffer_days = 30
planned_charge_period_days = 365.25/6
past_charges = [
(datetime.date(2019, 6, 30), 525),
(datetime.date(2019, 7, 22), 1250),
(datetime.date(2019, 12, 1), 500),
@yuwash
yuwash / demo.py
Created January 29, 2020 22:01
Python closure to simulate a class
def Tool(name):
data = {
'name': name,
'size': 0,
'color': 0xffee88,
}
def get_color():
return data['color']
#! /usr/bin/env python
# -*- coding: utf-8 -*-
expect_at = 2**22
plants = expect_at * ['wind'] + ['solar'] + expect_at * ['biogas']
repetitions = 100
def where_is_eafp(target):
try:
@yuwash
yuwash / memwarn.bash
Last active May 27, 2018 13:53
Warn on nearly full memory
#!/bin/bash
# see https://askubuntu.com/questions/276234/need-application-script-alerting-when-system-memory-is-running-out/346779#346779
# add crontab -e the following:
# * * * * * DISPLAY=:0.0 /path/to/memwarn.bash
#Minimum available memory limit, MB
if [[ -n "$1" ]]; then
THRESHOLD="$1"
else
THRESHOLD=400
@yuwash
yuwash / topcombine
Created February 1, 2018 18:40
Combine top halves of two PDF into one page, rotating the second upside-down
#! /usr/bin/env bash
[[ "$#" == 2 ]] || {
echo Please specify the two input PDF files.
exit 1
}
PDF1="$1"
PDF2="$2"
PDFALL="all-$(date -I).pdf"
OUTPUTPDF="topcombine-${PDF1%.pdf}-$PDF2"