Skip to content

Instantly share code, notes, and snippets.

View yuwash's full-sized avatar

Yushin Washio yuwash

View GitHub Profile
@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/
@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 / 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"
@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']