Skip to content

Instantly share code, notes, and snippets.

View iamevn's full-sized avatar

Evan Minsk iamevn

View GitHub Profile
@iamevn
iamevn / riichi_scoring.py
Created January 3, 2020 10:20
riichi final scoring (oka & uma)
#!/usr/bin/env python3
# Do Riichi final scoring based on
# http://arcturus.su/wiki/Oka_and_uma
def placements(scores):
"""return array of relative placements in scores.
0 for the best score 1 for second best, etc.
ties broken by order in scores
#! /usr/bin/env python3
from sys import argv, exit
from os import path, remove, scandir, rename
try:
from bencodepy import decode_from_file
except ImportError:
exit('bencodepy is not installed.\n(hint: pip install bencodepy)')
if len(argv) < 2:
@iamevn
iamevn / restructure_mbox.py
Created June 15, 2018 23:33
small tool that was helpful in importing many mboxes to thunderbird
#!/usr/bin/env python3
import os
from os import path
options = {debug:True,
doit :True}
def restructure(basepath):
"""given a basepath, restructure each folder within basepath.
equilivant to the following lines of bash where out is basepath:
@iamevn
iamevn / get_status.js
Last active June 9, 2018 22:51
displays discord status based on currently playing thing in plex. I couldn't get timestamps working for whatever reason
#!/usr/bin/node
const PlexAPI = require('plex-api');
const credentials = require('plex-api-credentials');
const userAndPass = credentials({
username: 'username',
password: 'hunter2'
});
const client = new PlexAPI({
hostname: 'localhost',
import sys
def replace_text(inpath, outpath, replacements):
with open(outpath, 'w', encoding='utf-8') as outfile:
for line in open(inpath, encoding='utf-8'):
for key in replacements:
val = replacements[key]
line = line.replace('\\an{}'.format(key), '\\an{}'.format(val))
outfile.write(line)
#!/usr/bin/env python3
# split out AMAZON/NETFLIX STYLE TYPESETTING
#by iamevn
import sys, re
def find_nth(string, substring, n, start=0):
"""find nth occurance of substring in string starting at position start.
(uses string.find) n starts at 1, start starts at 0"""
found = string.find(substring, start)
if n == 1 or found == -1:
@iamevn
iamevn / life.wordy
Last active October 28, 2017 20:14
unoptimized wimpmode Game of Life in Wordy https://esolangs.org/wiki/Wordy
# Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
# Any live cell with two or three live neighbours lives on to the next generation.
# Any live cell with more than three live neighbours dies, as if by overpopulation.
# Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
# width and height define the world, it wraps around like a torus
# clear screen by outputting \033c (27 99)
# (0, 0) (top left) is in cell 0. (0, 1) is in cell 1. (1, 0) is in cell {width}
# for a cell n in grid of width w and height h, its neighbors are:
# {(n - w - 1), (n - w), (n - w + 1)
#!/usr/bin/env python3
# combine adjacent lines with the same timecodes
import sys
from datetime import datetime, timedelta
def find_nth(string, substring, n, start=0):
"""find nth occurance of substring in string starting at position start.
(uses string.find) n starts at 1, start starts at 0"""
found = string.find(substring, start)
#! /usr/bin/env python3
from sys import argv, exit
from os import walk,path
try:
from bencodepy import decode_from_file
except ImportError:
exit("bencodepy is not installed. ")
if len(argv) < 2:
script_name="Shift Transforms"
script_description="shift \\t transforms by input ms"
script_author="iamevn"
script_version="0.2"
script_namespace="evn.ShiftTransforms"
--[[
Usage:
selected lines should have a transform on them