Skip to content

Instantly share code, notes, and snippets.

View fgoinai's full-sized avatar

FGO fgoinai

  • Hong Kong
View GitHub Profile
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':
// 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
@fgoinai
fgoinai / FnChain.py
Last active July 26, 2022 02:49
Just for chain invocation of function
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:
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
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']
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;
""")
//以下是SQL Builder...
type stmtOption interface{}
type stdOption struct{
stmtOption
params []string
}
type selectB stdOption
...
type joinB {
stmtOption
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
#!/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
@fgoinai
fgoinai / fib_yield.kt
Created June 14, 2017 11:55
Fib generator using kotlin coroutine
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)
}