Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@LouiS0616
LouiS0616 / map.dart
Last active November 29, 2020 02:05
Dartで嵌ったけど、原因が分かったやつ
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>>[];
@LouiS0616
LouiS0616 / strange_technique.py
Created November 22, 2020 02:16
jsみたいなノリでthisを使うための工夫、らしい
# pyquery.eachで使われていたテクニック?
class Spam:
def highly_func(self, func):
func.__globals__['this'] = self
func()
def __str__(self):
return "it's me!"
@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) {
@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 / 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 / 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 / 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
--
@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 / 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 / enc.bat
Created February 8, 2020 05:46
simple decoding tool
@echo off
python %~dp0\enc.py %*