Skip to content

Instantly share code, notes, and snippets.

Avatar
🌴
On vacation

i18u iahu

🌴
On vacation
View GitHub Profile
@iahu
iahu / safari-touchemulator.user.js
Created December 17, 2015 14:58
emulate touch events of safari(with iOS userAgent)
View safari-touchemulator.user.js
// ==UserScript==
// @name emulator_touch_events
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author author (uses https://github.com/hammerjs/touchemulator)
// @match http://tampermonkey.net/index.php?version=3.13.4890&ext=G3XV&updated=true
// @match *://*/*
// @grant none
// ==/UserScript==
@iahu
iahu / cli.ts
Created September 9, 2021 06:29
获取图片主题色
View cli.ts
import fs from 'fs'
import glob from 'glob'
import cliProgress from 'cli-progress'
import getThemeColor from './main'
import ProHub from './prohub'
const [path] = process.argv.slice(2)
const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic)
glob(path, function (err, matches) {
View magic-bytes.md
描述 扩展名 Magic Number
Adobe Illustrator .ai 25 50 44 46 [%PDF]
Bitmap graphic .bmp 42 4D [BM]
Class File .class CA FE BA BE
JPEG graphic file .jpg FF D8
JPEG 2000 graphic file .jp2 0000000C6A5020200D0A [....jP..]
@iahu
iahu / magic-bytes.md
Created June 8, 2021 06:01
magic bytes of media file type
View magic-bytes.md

| 描述 | 扩展名 | Magic Number | | ------------------------------ | ------ | -------------------------------------------------------------------------------------------------------------- | ---- | | Adobe Illustrator | .ai | 25 50 44 46 [%PDF] | | Bitmap graphic | .bmp | 42 4D [BM] | | Class File | .class | CA FE BA BE | | JPEG graphic file | .jpg | FF D8 | | JPEG 2000 graphic file | .jp2 | 0000000C6A5020200D0A [....jP..]

@iahu
iahu / promiseThrottle.ts
Created June 7, 2021 09:22
promise throttle
View promiseThrottle.ts
type Job<T> = () => Promise<T>
export const promiseThrottle = async <T>(
jobs: Job<T>[],
parallelCount: number,
onParallelDone?: (results: T[], index: number) => void
): Promise<T[]> => {
if (!(jobs && Array.isArray(jobs))) {
return Promise.reject('jobs must be Array')
}
@iahu
iahu / dsp-adx-price-decrypt.ts
Created May 31, 2021 02:45
DSP-ADX 价格解密逻辑 Typescript 版
View dsp-adx-price-decrypt.ts
import * as crypto from 'crypto'
const HMAC_ALGORITHM = 'HmacSHA1'
const ekey = Buffer.from('9527')
const ikey = Buffer.from('2840')
const mergeBytes = (...args: Uint8Array[]) => {
return Buffer.concat(args)
}
@iahu
iahu / install_cygwin_sshd.txt
Created May 26, 2021 02:37 — forked from roxlu/install_cygwin_sshd.txt
Installing CYGWIN + SSHD for remote access through SSH on windows
View install_cygwin_sshd.txt
Installing CYGWIN with SSH
1) Download cygwin setup.exe from http://www.cygwin.com
- Execute setup.exe
- Install from internet
- Root directory: `c:\cygwin` + all users
- Local package directory: use default value
- Select a mirror to download files from
- Select these packages:
- editors > xemacs 21.4.22-1
- net > openssh 6.1-p
@iahu
iahu / .importjs.js
Last active April 29, 2021 08:52
importjs use tsconfig paths
View .importjs.js
const Path = require('path');
const tsconfig = require('./tsconfig.json');
const baseUrl = tsconfig.compilerOptions.baseUrl;
const paths = tsconfig.compilerOptions.paths;
// 优先使用短的 key
const pathKeys = Object.keys(paths).sort((a, b) => b.length - a.length);
const removeWired = (str) => str.replace(/\*$/, '');
View pinyin-sort.ts
import memoize from 'lodash/memoize';
const supportLocaleCompare = typeof String.prototype.localeCompare === 'function';
const getShengmu = memoize((c: string) => {
const MAP = 'abcdefghjklmnopqrstwxyz';
const boundaryChar = '驁簿錯鵽樲鰒餜靃攟鬠纙鞪黁漚曝裠鶸蜶籜鶩鑂韻糳';
if (!supportLocaleCompare) {
return c;
}
View 怎么编写一个高可用的前端组件.md

怎么编写一个高可用的前端组件

React 流行以后,编写前端组件的成本变得非常低廉,开发一个通用组件是件非常容易的事,日常业务开发也早已变成搭积木式的堆组件了。在这种开发环境下组件的可用性就变得至关重要,谁都希望拿在手的组件可以像橡皮泥一样”任人摆布“,“放之四海皆准”,而不是动不动就要去改源码。

高可用包含两层意思,

一是开发时的高可用,一处编码,处处可用

二是用户群体的高可用,正常用户行为可用,特殊用户行为也可用。