This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pathlib | |
import re | |
import cv2 | |
import numpy as np | |
import tqdm | |
_color_convert_dct = { | |
# B G R |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
python %~dp0\enc.py %* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) [] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
OpenCV utility functions. | |
""" | |
from functools import singledispatch | |
import cv2 | |
BackendError = type('BackendError', (Exception,), {}) | |
def _is_visible(winname): | |
try: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |