Skip to content

Instantly share code, notes, and snippets.

View nuintun's full-sized avatar
😊
I may be slow to respond.

nuintun nuintun

😊
I may be slow to respond.
View GitHub Profile
@nuintun
nuintun / Dockerfile
Last active June 8, 2021 09:33
Nextjs Docker 环境
# 配置运行环境
FROM node:alpine
# 配置工作目录
WORKDIR /wwwroot
# 配置 Node 运行模式
ENV NODE_ENV production
# 禁用 Next 数据遥测
ENV NEXT_TELEMETRY_DISABLED 1
@nuintun
nuintun / Dockerfile
Last active June 8, 2021 09:33
Nextjs Docker 应用
# 配置运行环境
FROM node:alpine AS deps
# 配置工作目录
WORKDIR /wwwroot
# 切换国内软件源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
# 安装编译环境
RUN apk update && apk upgrade -f && apk add --no-cache g++ make python3
@nuintun
nuintun / koa-compose.js
Last active September 27, 2021 06:21
koa-compose 简化版实现
/**
* @function compose
* @description compose koa middlewares
* @param {function[]} middlewares
* @returns {function}
*/
function compose(middlewares) {
const done = async () => {};
const compose = middlewares.reduce((compose, middleware) => {
@nuintun
nuintun / redux-compose.js
Last active September 16, 2021 02:34
redux-compose 实现
/**
* @function compose
* @description compose redux middlewares
* @param {function[]} funcs
* @returns {function}
*/
function compose(middlewares) {
return middlewares.reduce((compose, middleware) => {
return (...args) => compose(middleware(...args));
});
@nuintun
nuintun / koa-compose.ts
Last active May 9, 2023 02:31
koa-compose TypeScript 实现
/**
* @module compose
*/
export interface Next {
(): Promise<void>;
}
export interface Composed<C> {
(context: C, next?: Next): Promise<void>;
@nuintun
nuintun / compose.ts
Last active September 27, 2021 06:18
compose TypeScript 增强版
/**
* @module compose
*/
export type Next<C> = (context: C) => Promise<C>;
export type Middleware<C> = (context: C, next: Next<C>) => Promise<C> | C;
export type ComposedMiddleware<C> = (context: C, next?: Next<C>) => Promise<C>;
@nuintun
nuintun / koa-compose.ts
Last active March 23, 2024 13:52
koa-compose TypeScript 官方实现优化版
/**
* @module compose
*/
export interface Next {
(): Promise<void>;
}
export interface Composed<C> {
(context: C, next?: Next): Promise<void>;
@nuintun
nuintun / useStateMachine.ts
Last active June 8, 2024 01:44
useStateMachine.ts
/**
* @module useStateMachine
* @see https://github.com/cassiozen/useStateMachine
*/
import { isFunction, isString } from '/js/utils';
import { Dispatch, useEffect, useMemo, useReducer } from 'react';
type ContextUpdate<C> = (context: C) => C;
@nuintun
nuintun / path.ts
Last active March 3, 2022 03:21
URL resolve
/**
* @module path
*/
/**
* @function isURL
* @description 判断路径是否为 URL
* @param path 需要判断的路径
*/
function isURL(path: string): boolean {
@nuintun
nuintun / dfs.ts
Created March 2, 2022 04:42
DFS tree
/**
* @module DFSTree
*/
type Resolve<T> = (node: T) => T[] | void;
type IteratorValue<T> = [node: T, parent: T | undefined];
type Waiting<T> = [iterator: Iterator<T, undefined>, parent?: T];