Skip to content

Instantly share code, notes, and snippets.

View leizongmin's full-sized avatar
😴
I may be slow to respond

LEI Zongmin leizongmin

😴
I may be slow to respond
View GitHub Profile
@leizongmin
leizongmin / timer.js
Last active April 20, 2023 04:05
Use `queueMicrotask` to implement timer function
function setTimeout(callback, delay, ...args) {
const id = setTimeout._nextId++;
const start = Date.now();
function loop() {
queueMicrotask(() => {
if (!setTimeout._timers[id]) return;
if (Date.now() - start >= delay) {
delete setTimeout._timers[id];
callback(...args);
} else {
@leizongmin
leizongmin / main.go
Created July 14, 2021 14:14
fasthttp ReadBufferSize example
package main
import (
"fmt"
"github.com/valyala/fasthttp"
"log"
"net/http"
"os"
"strings"
"time"
@leizongmin
leizongmin / shared.js
Created January 7, 2021 08:40
worker_threads & SharedArrayBuffer Node.js 多线程共享内存(缓存管理)实验
const { MessageChannel } = require("worker_threads");
class Shared {
#clientCounter = 0;
#ports = new Map();
#map = new Map();
#parentPort = null;
#callbacks = new Map();
#callbackCounter = 0;
@leizongmin
leizongmin / go-mini-build.sh
Last active October 13, 2020 18:02
go-mini-build
#!/bin/sh
usage() {
echo "usage: go-mini-build <package-name> [output-path]"
}
file_size() {
echo $(ls -lh "$1" | awk '{print $5}')
}
@leizongmin
leizongmin / mweb-lei-simple.css
Created March 22, 2019 05:39
mweb-lei-simple MWeb预览主题
* {
margin: 0;
padding: 0;
}
body {
min-width: 200px;
max-width: 900px;
margin: 0 auto;
padding: 20px;
@leizongmin
leizongmin / output.html
Last active December 24, 2018 15:18
JSX语法转换
<div class="xxx" zz="{&quote;a&quote;:1}">
<text>hello</text>
<a>dsds</a>
ok
<x>
<y>z</y>
</x>
</div>
@leizongmin
leizongmin / AI.fsx
Created December 13, 2018 07:52
价值一百个亿的 AI 核心代码
// 价值一百个亿的 AI 核心代码
// Do What The Fuck You Want To Public License
open System
let replace (oldstr : string) (newstr : string) (text : string) =
text.Replace(oldstr, newstr)
let ask() =
Console.Write("> ")
Console.ReadLine()
@leizongmin
leizongmin / baidu_pan_downloads.js
Created February 27, 2018 06:28
百度网盘BT任务快捷录入
// 从页面获取所有链接URL
// http://www.msj1.com/archives/2868.html
console.log(
"list=%s",
JSON.stringify(
Array.from(document.querySelector("#content table").querySelectorAll("tr"))
.map(tr => tr.querySelector("td a"))
.filter(a => a)
.map(a => a.href)
)
@leizongmin
leizongmin / timer1.js
Created February 6, 2018 03:39
Node.js定时器测试代码
// 高精度定时器,interval为毫秒
function myTimer(callback, interval) {
function getTime() {
return process.uptime() * 1000;
}
let previous = getTime();
setInterval(function() {
const now = getTime();
if (now - previous >= interval) {
previous = now;
@leizongmin
leizongmin / package.json
Created January 3, 2018 08:15
跨域共享Cookie示例
{
"name": "cookie example",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"connect-redis": "^3.3.3",
"cookie-parser": "^1.4.3",
"express": "^4.16.2",
"express-session": "^1.15.6"