Skip to content

Instantly share code, notes, and snippets.

import pathlib
import re
import cv2
import numpy as np
import tqdm
_color_convert_dct = {
# B G R
@LouiS0616
LouiS0616 / enc.bat
Created February 8, 2020 05:46
simple decoding tool
@echo off
python %~dp0\enc.py %*
@LouiS0616
LouiS0616 / module.py
Created March 1, 2020 12:56
pyyamlについて:タグの加え方
import yaml
from yaml import ScalarNode, SequenceNode
def _flatten(_, node):
def _inner(n):
if isinstance(n, ScalarNode):
yield n
elif isinstance(n, SequenceNode):
for e in n.value:
@LouiS0616
LouiS0616 / main.hs
Created April 15, 2020 06:05
連続するスペースの削除いろいろ
import Data.List (group)
removeSequencialSpace1 :: String -> String
removeSequencialSpace1 = concat . compressSpaces . group
where
compressSpaces :: [String] -> [String]
compressSpaces = foldr (\str acc -> (if ' ' `elem` str then " " else str): acc) []
@LouiS0616
LouiS0616 / Rpn.hs
Created April 17, 2020 07:32
逆ポーランド記法電卓 Reverse Polish Notation Calcurator
import Text.Read
import Stack
--
readWithEffort :: Read r => String -> Either String r
readWithEffort src = case readMaybe src of
(Just a) -> Right a
Nothing -> Left src
--
"""
OpenCV utility functions.
"""
from functools import singledispatch
import cv2
BackendError = type('BackendError', (Exception,), {})
def _is_visible(winname):
try:
@LouiS0616
LouiS0616 / Main.hs
Created May 10, 2020 12:31
歪んだコイン
import Data.List
import Data.Ratio
--
newtype Probs a = Probs { getProbs :: [(a, Rational)] } deriving Show
instance Functor Probs where
fmap f (Probs xs) = Probs $ do
(a, rate) <- xs
return (f a, rate)
@LouiS0616
LouiS0616 / flow.py
Created May 25, 2020 06:30
JISフローチャートの規格に無理やり適合させたPython。while は while not( ) と書けばよろしい。
class Array_(list):
def __init__(self, size, lst=None):
if lst is None:
lst = [None] * size
assert len(lst) == size
list.__init__(self, lst)
def __getitem__(self, idx):
return list.__getitem__(self, idx-1)
@LouiS0616
LouiS0616 / BRIterator.java
Created May 29, 2020 03:08
突合処理用のラッパー群;普通に書くのが面倒なので
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Iterator;
import java.util.NoSuchElementException;
public class BRIterator implements Iterator<String> {
private final BufferedReader br;
public BRIterator(BufferedReader bufferedReader) {
br = bufferedReader;
@LouiS0616
LouiS0616 / PeekableIterator.java
Last active May 31, 2020 05:38
覗き見できるイテレータ
import java.util.Iterator;
import java.util.NoSuchElementException;
public class PeekableIterator<T> implements Iterator<T> {
//
private final Iterator<T> it;
private T nextElem;
private boolean hasNext = false;
public PeekableIterator(Iterable<T> iterable) {