Skip to content

Instantly share code, notes, and snippets.

View yuwash's full-sized avatar

Yushin Washio yuwash

View GitHub Profile
@yuwash
yuwash / pasaffe_lib_usage.py
Created November 6, 2017 00:22
pasaffe_lib usage
#! /usr/bin/env python3
import getpass
from pasaffe_lib.readdb import PassSafeFile # should come with apt-get install pasaffe
pspass = getpass.getpass('pspass: ')
pf = PassSafeFile('/path/to/file.psafe3', pspass)
pf.get_all_folders()
# [['Folder 1'], ['Folder 2'], …]
@yuwash
yuwash / classifier.py
Last active November 26, 2017 16:40
read stdin, find conversations (quoted text, whereas first conversation of a line needs to begin at the line start)
#! /usr/bin/env python3
from itertools import islice
from find_conversations import read
class Census:
def __init__(self, represent=None):
self.data = {}
self.represent = represent
@yuwash
yuwash / elektroreturn_multiply.sh
Created January 6, 2018 16:52
Die Elektroreturn-Versandmarke papiersparend viermal auf einer Seite ausdrucken
#! /usr/bin/env bash
ETIKETT_PDF="dp-electroreturn_versandetikett.pdf"
OUT_PDF="${ETIKETT_PDF%.pdf}-multiplied.ps"
if ! [[ -e "$ETIKETT_PDF" ]]; then
echo please download it from https://www.deutschepost.de/de/e/electroreturn.html
else
pdftops "$ETIKETT_PDF" \
&& pstops "0R(0,.5h)+0R(.5w,.5h)+0L(1w,.5h)+0L(.5w,.5h)" "${ETIKETT_PDF%.pdf}.ps" "${OUT_PDF%.pdf}.ps" \
&& ps2pdf "${OUT_PDF%.pdf}.ps" \
&& echo generated "$OUT_PDF"
@yuwash
yuwash / bestgoldenratio.py
Created January 16, 2018 10:42
Find best fit for Golden Ratio
def get_best(choice=range(1, 1080)):
'''Find best integer fit for the shorter side of Golden Ratio
Best fit has a integer-valued longer side with the smallest error to the real Golden Ratio
:param choice list(int): choioce of integers
>>> get_best()
(1.2018646489717657e-06, 305)
'''
return min((((x*(5**0.5)/2) % 1)/x, x) for x in choice)
@yuwash
yuwash / wochenangebote
Last active January 26, 2018 18:33
Überblick über Wochenangebote bekommen ohne Ablenkung
#!/usr/bin/env bash
[[ -n "$GOPATH" ]] || GOPATH="$HOME/gocode/bin"
PUP="$GOPATH/pup"
if ! [[ -e "$PUP" ]]; then
echo 'please install pup with'
echo 'GOPATH="$HOME/gocode" go get github.com/ericchiang/pup'
exit 1
fi
# Aldi-Sued
@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
#! /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 / 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']
@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 / 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))