Skip to content

Instantly share code, notes, and snippets.

View yuzhouu's full-sized avatar
🎉

##-- yuzhouu

🎉
View GitHub Profile
@yuzhouu
yuzhouu / go_threadLimit.go
Last active July 29, 2018 06:18
go thread limit from net.go
var threadLimit chan struct{}
var threadOnce sync.Once
func acquireThread() {
threadOnce.Do(func() {
threadLimit = make(chan struct{}, concurrentThreadsLimit())
})
threadLimit <- struct{}{}
}
@yuzhouu
yuzhouu / preventAutocomplete.vue
Created January 15, 2019 09:24
prevent chrome autocomplete
<template>
<div>
<input type="password" :style="{ position: 'absolute', top: '-99999px' }"> // this line prevent chrome autocomplete below
<input :type="computedType" autocomplete="off">
<span
v-if="type==='password'"
:class="['eye', eyeStatus?'eye-open':'eye-close']"
@click="toggleEyeStatus"
></span>
</div>
@yuzhouu
yuzhouu / profile.txt
Last active May 31, 2022 06:06
profile
Hi!
@yuzhouu
yuzhouu / text2image.ts
Created May 31, 2022 02:37
convert text to text-image
interface Options {
fontFamily?: string;
fontSize?: number;
}
export default function text2image(text: string, opts?: Options) {
const { fontFamily = "serif", fontSize = 14 } = opts || {};
// high ratio, high dpi
const ratio = Math.max(window.devicePixelRatio || 4, 4);
const canvas = document.createElement("canvas");
@yuzhouu
yuzhouu / limitPromiseConcurrency.ts
Last active July 28, 2022 09:39
限制promise操作的并发数
/*
* 改自 https://github.com/sindresorhus/p-limit
*/
export function limitPromiseConcurrency<Result = any>(concurrency: number) {
type FnType = () => Promise<Result>
type ResolveFn = (r: Result) => void
type RejectFn = (r: any) => void
if (concurrency <= 0) {