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
List<List<U>> deepMap2D_F<T, U>(List<List<T>> src, U Function(T) f) { | |
var ret = <List<U>>[]; | |
for(List<T> innerList in src) { | |
ret.add([for(var e in innerList) f(e)]); | |
} | |
return ret; | |
} | |
extension <T,U> on List<List<T>> { | |
List<List<U>> deepMap2D_M(U Function(T) f) { | |
var ret = <List<U>>[]; |
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
# pyquery.eachで使われていたテクニック? | |
class Spam: | |
def highly_func(self, func): | |
func.__globals__['this'] = self | |
func() | |
def __str__(self): | |
return "it's me!" | |
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) { |
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
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 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
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
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 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
@echo off | |
python %~dp0\enc.py %* |
NewerOlder