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
package main | |
import ( | |
"golang.org/x/tour/pic" | |
"image" | |
"image/color" | |
) | |
type MyImage struct{ | |
size int |
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
copyfiles -u 1 src/**/*.js lib |
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
// how to compose the existed Action / Reducer to make create multi instances on global redux store (combineReducer) | |
// inspired from https://github.com/reduxjs/redux/issues/897 | |
/** liftAction lifting your existed Action */ | |
export function liftAction<LType extends string, Arg, A>( | |
/** lift key */ | |
liftedType: LType, | |
/** original action generator */ | |
actionGenerator: (...args: Arg[]) => A | |
/* considering react-thunk so i use `HIGHT_ORDER_ACTION` refers to `LType` */ |
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
/** 特性支持表 */ | |
export const FEATURES = new class { | |
/** Is Window Supports Passive Event */ | |
public PASSIVE_EVENT = false; | |
public constructor() { | |
this.init(); | |
} | |
public init() { |
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
export type Maybe<T> = null | T | Maybe<T>[] | { props?: { children?: Maybe<T> } }; | |
export type ID<T> = (a: any) => a is T; | |
export const isNumber = ((x: any) => typeof x === 'number') as ID<number>; // 看来又是一个 ts shit | |
export function flat<T>(arr: Maybe<T>[], isT: ID<T>): T[] { | |
if (arr.length === 0) return []; | |
const [x, ...xs] = arr; |
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
import React from 'react'; | |
/** useTimeMachine option define */ | |
export interface TimeMachineOption<T> { | |
/** outter changing timer */ | |
machineTime: number, | |
/** time map to state */ | |
getStateByTime: (time: number) => Promise<T>, | |
/** judge should update state by stateTime & machineTime */ | |
shouldUpdateState: (stateTime: number, machineTime: number) => boolean; |
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
import 'reflect-metadata'; | |
/** 此类型可描述任意 class */ | |
type AnyClass<Args extends any[] = any, Instance = any> = new (...args: Args) => Instance; | |
/** | |
* ## IOC 控制器 | |
* 支持做 IOC 设计模式 | |
* - IOC.Register 注册类到 IOC 控制器 | |
* - IOC.RegisterOne 注册类到 IOC 控制器 (单例模式) |
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
/** a way to use promise as an immutable state machine */ | |
export class PromiseMachine<T> { | |
/** this promise instance */ | |
private $promise: Promise<T>; | |
/** make this resolved */ | |
private $resolve!: (val: T) => void; | |
/** make this rejected */ | |
private $reject!: (err: any) => void; | |
/** 全部が終わった */ |
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
// recursive style | |
fn sum(n: i32) -> i32 { | |
if n == 0 { 0 } else { | |
n + sum(n - 1) | |
} | |
} | |
// iterative style | |
fn sum2(n: i32) -> i32 { | |
fn iter(i: i32, accumulate: i32) -> i32 { |
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
use std::fs; | |
use std::io::Error; | |
#[derive(serde_derive::Deserialize)] | |
#[derive(Debug)] | |
struct MyConfDefine { | |
eczn_info: EcznInfo | |
} | |
#[derive(serde_derive::Deserialize)] |