Skip to content

Instantly share code, notes, and snippets.

View yuwash's full-sized avatar

Yushin Washio yuwash

View GitHub Profile
@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 / 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 / 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 / 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 / plot-examples.py
Created August 1, 2013 19:40
Simple ASCII Plotter usage examples, 1-D (some discrete points) and 2-D (sin([0,2pi])) each
""" @file plot-examples.py
@brief ASCII-Plotter examples
@details Example usage of
[ASCII-Plotter](https://pypi.python.org/pypi/ASCII-Plotter/1.0),
with 1-D and 2-D examples each;
Currently you can obtain the aplotter.py file by
Imri Goldberg from
http://www.algorithm.co.il/blogs/ascii-plotter/