This file contains hidden or 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 compose: | |
def __init__(self, *fs: Callable, from_left=False): | |
self.__from_left = from_left | |
self.__f_list = list(fs) | |
def __call__(self, *args, **kwargs): | |
fs = self.__f_list if self.__from_left else list(reversed(self.__f_list)) | |
return reduce(lambda result, f: f(result), tail(fs), head(fs)(*args, **kwargs)) | |
def __or__(self, other: Callable) -> 'compose': |
This file contains hidden or 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
// Require kotlinx.coroutines jar as dependency, handle it yourself | |
import kotlinx.coroutines.experimental.async | |
import kotlinx.coroutines.experimental.launch | |
import kotlinx.coroutines.experimental.runBlocking | |
import java.io.FileOutputStream | |
import java.net.HttpURLConnection | |
import java.net.URL | |
import java.nio.channels.Channels |
This file contains hidden or 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
from functools import partial, reduce | |
from itertools import chain | |
from typing import Callable, Any, Sequence, Optional, Mapping | |
class FnChain: | |
""" | |
FnChain(obj).map(...).filter(...).reduce(...)... | |
API LIST: |
This file contains hidden or 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
minimaxWithLeastDepth :: Tree Grid -> Tree (Grid, Player, Int) | |
minimaxWithLeastDepth (Node g []) | |
| wins O g = Node (g,O,1) [] | |
| wins X g = Node (g,X,1) [] | |
| otherwise = Node (g,B,1) [] | |
minimaxWithLeastDepth (Node g ts) | |
| turn g == O = Node (g, minimum ps, minimum cs) ts' | |
| turn g == X = Node (g, maximum ps, minimum cs) ts' | |
where | |
ts' = map minimaxWithLeastDepth ts |
This file contains hidden or 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
from bokeh.models import DatetimeTickFormatter | |
from bokeh.plotting import figure | |
from bokeh.io import output_file, show | |
from gen import onoff_to_multiline_x_ls | |
import datetime | |
ticker = DatetimeTickFormatter( | |
seconds=['%c'], minutes=['%c'], hours=['%c'], | |
days=['%c'], months=['%c'], years=['%c'] |
This file contains hidden or 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
btn.callback = CustomJS(args=dict(btn0=btn0, btn1=btn1, a0=graphs0[0], a1=graphs0[1], b0=graphs1[0], b1=graphs1[1]), code=""" | |
btn0.active = cb_obj.active; | |
a0.visible = (cb_obj.active.includes(0)) ? true : false; | |
a1.visible = (cb_obj.active.includes(1)) ? true : false; | |
btn1.active = cb_obj.active; | |
b0.visible = (cb_obj.active.includes(0)) ? true : false; | |
b1.visible = (cb_obj.active.includes(1)) ? true : false; | |
""") |
This file contains hidden or 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
//以下是SQL Builder... | |
type stmtOption interface{} | |
type stdOption struct{ | |
stmtOption | |
params []string | |
} | |
type selectB stdOption | |
... | |
type joinB { | |
stmtOption |
This file contains hidden or 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
ln -sf /usr/share/zoneinfo/$(tzselect) /etc/localtime | |
hwclock --systohc | |
nano /etc/locale.gen && locale-gen | |
read -p "Default LANG is? [en_US,zh_CN...]" loc | |
echo "LANG=$loc.UTF-8" >> /etc/locale.conf | |
read -p "Hostname is?" hn | |
echo $hc > /etc/hostname | |
echo "127.0.1.1\t$hc.localdomain\t$hc" > /etc/hosts |
This file contains hidden or 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
#!/bin/bash | |
#check network connection | |
con=$(ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` > /dev/null && echo ok || echo error) | |
if [ $con == "error" ]; then | |
exit -1 | |
fi | |
timedatectl set-ntp true | |
lsblk |
This file contains hidden or 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
fun main(args: Array<String>) { | |
fib.take(10).forEach { println(it) } | |
} | |
val fib = buildSequence { | |
var tmp = Pair(0, 1) | |
while(true) { | |
yield(tmp.first) | |
tmp = Pair(tmp.second, tmp.first + tmp.second) | |
} |
NewerOlder