Skip to content

Instantly share code, notes, and snippets.

View otakustay's full-sized avatar

Gray Zhang otakustay

  • Long lives alien!
  • Shanghai China
View GitHub Profile
@otakustay
otakustay / skill.ts
Last active March 14, 2024 09:08
Watch file
import fs from 'node:fs/promises';
import chokidar form 'chokidar';
const watchState = {
running: false,
};
export class MySkillProvider extends SkillProvider {
constructor(init: ProviderInit) {
super(init);
@otakustay
otakustay / rules.json
Created October 31, 2022 10:03
eslint-typescript config
{
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": ["error", {"default": "array-simple", "readonly": "generic"}],
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-comment": [
"error",
{
"ts-expect-eror": "allow-with-description",
"ts-ignore": true,
"ts-nocheck": true,
“工程规范治理”包括工程相关的规范制定与落地(Lint、UT、供应链等),工具研发与支持(各类命令行、框架、库等),平台化(Devops、依赖管理、技术中台等)。
Q:贵公司的名称?
Q:贵公司如何看待工程规范治理这件事?上层视角?基层管理者视角?业务员工视角?
Q:贵公司工程规范治理这件事的重视度和投入,主要推动方?
Q:开展过哪些工程规范治理的工作?如何开展的?
@otakustay
otakustay / style-resources.ts
Created December 7, 2021 08:53
vite plugin style resources
import path from 'path';
import fs from 'fs/promises';
import {memoizeWith, always} from 'ramda';
import {Plugin} from 'vite';
const CSS_LANGS = new Set(['.less']);
export default function styleResourcePlugin(patterns: string[]): Plugin {
const readContent = memoizeWith(
always(''),
@otakustay
otakustay / index.ts
Created March 23, 2021 10:01
balanced-unique
function optimizedRemove<T>(sets: Array<Set<T>>, value: T): void {
// 如果N个数组中都有这个元素,那么我们只保留长度最短的数组中的那一份,其它的都删掉
const containedSets = sets.filter(s => s.has(value));
const setWithMinSize = containedSets.reduce((out, current) => (current.size <= out.size ? current : out));
containedSets.filter(s => s !== setWithMinSize).forEach(s => s.delete(value));
}
function makeBalancedUnique<T>(values: T[][]): T[][] {
// 转成Set,这样判断元素是否存在、删除元素性能更高
const sets = values.map(v => new Set(v));
@otakustay
otakustay / index.js
Created March 10, 2021 10:16
Compute aspect ratio
const isApproximateInteger = value => {
const min = Math.floor(value);
const max = Math.ceil(value);
return value - min <= 0.01 || max - value <= 0.01;
};
const MAX_TRY = 120;
const computeToRatio = (width, height) => {
@otakustay
otakustay / useSelection.ts
Created February 22, 2020 05:38
React hook to control table selection
import {useReducer, useCallback} from 'react';
import {union, without, difference, range} from 'lodash';
interface Action {
type: 'single' | 'multiple' | 'range';
payload: number;
}
export interface SelectionMethods {
selectIndex(index: number, e: ClickContext): void;
@otakustay
otakustay / index.tsx
Created November 7, 2019 13:36
usePerformanceTiming
import {useRef, useLayoutEffect} from 'react';
interface PerformanceTiming {
firstRender: number;
firstLayout: number;
firstMeaningfulRender: number;
firstMeaningfulLayout: number;
}
const usePerformanceRecord = () => {
@otakustay
otakustay / index.ts
Created October 24, 2019 11:42
user attention detection
interface Options {
readonly maxIdleTime?: number;
}
type AttentionState = 'active' | 'inactive' | 'unknown';
interface AttentionChangeEvent {
readonly state: AttentionState;
readonly active: boolean;
readonly lastAction: number;
@otakustay
otakustay / unidiff.js
Created September 27, 2019 07:05
es2015 unidiff
"use strict";
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
!function (e, n) {
"object" == (typeof exports === "undefined" ? "undefined" : _typeof(exports)) && "undefined" != typeof module ? n(exports) : "function" == typeof define && define.amd ? define(["exports"], n) : n(e.unidiff = {});
}(void 0, function (e) {
"use strict";
function n(e) {