Skip to content

Instantly share code, notes, and snippets.

View atian25's full-sized avatar
🐷
is watching you.

TZ | 天猪 atian25

🐷
is watching you.
View GitHub Profile
// https://tsplay.dev/WJ73Zw
type MountPlugin<T, TestRunner> = {
[key in keyof T]: T[key] extends (core: TestRunner, ...args: infer I) => any ? (...args: I) => MountPlugin<T, TestRunner> : undefined;
} & TestRunner;
interface PluginLike {
[key: string]: (core: any, ...args: any[]) => any;
}
type RestParam<T> = T extends (first: any, ...args: infer R) => any ? R : any;
// https://tsplay.dev/WG4bKw
class TestRunner {
plugin(plugins) {
for (const key of Object.keys(plugins)) {
const initFn = plugins[key];
this[key] = (...args) => {
initFn(this, ...args);
return this;
};
}
@atian25
atian25 / ctx.ts
Created December 22, 2022 02:34
AsyncLocalStorage
import { AsyncLocalStorage } from 'async_hooks';
class App {
private asyncLocalStorage = new AsyncLocalStorage();
private middlewares = [];
async use(fn, opts) {
const mw = fn(this, opts);
this.middlewares.push(mw);
}
function lazyRequire(id) {
return new Proxy({}, {
get: (_, key, reciver) => {
const mod = require(id);
return Reflect.get(mod, key, reciver);
},
});
}
const fs = lazyRequire('fs');
OS: darwin x64
Adapter node: v7.9.0 x64
vscode-chrome-debug-core: 5.0.2
16:27:32, 2018-6-13
node-debug2: 1.24.2
From client: initialize({"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"node2","locale":"en","linesStartAt1":true,"columnsStartAt1":true,"pathFormat":"path","supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true})
To client: {"seq":0,"type":"response","request_seq":1,"command":"initialize","success":true,"body":{"exceptionBreakpointFilters":[{"label":"All Exceptions","filter":"all","default":false},{"label":"Uncaught Exceptions","filter":"uncaught","default":false}],"supportsConfigurationDoneRequest":true,"supportsSetVariable":true,"supportsConditionalBreakpoints":true,"supportsCompletionsRequest":true,"supportsHitConditionalBreakpoints":true,"supportsRestartFrame":true,"supportsExceptionInfoRequest":true,"supportsDelayedStackTraceLoading":true,"supportsValueFormattingOptions":true,"supportsEvaluateForHovers":true,"supportsLogPoints":true}}
@atian25
atian25 / result.md
Last active November 22, 2017 01:29
error stack - co vs async

Intro

compare error stack between egg@1(co-base) and egg@2(async-base)

Fixture

// /app/service/test.js
class TestService extends Service {
  echo() {
@atian25
atian25 / log
Last active October 10, 2017 05:17
now.sh issue report
➜ showcase git:(now) ✗ now log https://showcase-vonarcxljh.now.sh/
10/10 12:55 PM npm install
10/10 12:55 PM ⧗ Installing 11 main dependencies…
10/10 12:56 PM ✓ Installed 896 modules [13s]
10/10 12:56 PM npm start
10/10 12:56 PM npm WARN lifecycle The node binary used for scripts is /home/nowuser/bin/node but npm is using /usr/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
10/10 12:56 PM
> [email protected] start /home/nowuser/src
> egg-scripts start --workers=1
10/10 12:56 PM

quick npm owner add

@atian25
atian25 / egg-scripts-proposals-465.md
Created February 28, 2017 01:38
egg-scripts proposals #465 backup

eggjs/egg#241 太长了,重开一个,讨论第一期的实现方案。

仅提供 egg-scripts startegg-scripts stop 几条最基础的线上指令。 而看了下原内网的实现,会比较依赖于环境变量,本方案更倾向于用 cli options 的方式

start

$ egg-scripts start --baseDir=<APP_BASE> --port=7001 --env=prod --workers=2 --no-daemon
@atian25
atian25 / header_get.js
Created September 20, 2016 09:50
get header use lowercase, 10x speed
'use strict';
const Benchmark = require('benchmark');
const benchmarks = require('beautify-benchmark');
const suite = new Benchmark.Suite();
suite
.add('get header all lower case', function() {
const res = {};
res['x-frame-options1'] = 'X-Frame-Options1 value';