Skip to content

Instantly share code, notes, and snippets.

@myesn
myesn / promise.js
Created November 2, 2020 09:57
Promise
const p = new Promise((resolve, reject) => {
const a = 1 + 1;
if (a === 2) {
resolve('Success');
} else {
reject('Faild');
}
});
p.then((message) => {
// This file was initially generated by Windows Terminal Preview 1.2.2022.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
@myesn
myesn / TranslateToChineseOnYouTube.user.js
Created April 16, 2021 14:42 — forked from qwertyuiop6/TranslateToChineseOnYouTube.user.js
Translate to Chinese automatically. youtube自动翻译中文简体
// ==UserScript==
// @name YouTube字幕自动翻译->中文简体
// @namespace http://tampermonkey.net/
// @version 1.0
// @description translate to Chinese automatically. 自动点击字幕翻译到中文简体
// @author qwertyuiop6
// @match https://www.youtube.com/watch*
// @grant none
// ==/UserScript==
@myesn
myesn / compare-folder.js
Last active August 3, 2021 02:04
比较两个文件夹中的文件, 以 origin 为基础, target 文件夹中缺失了哪些文件
const fs = require('fs');
const path = require('path');
const origin = 'C:/origin';
const target = 'C:/target';
const originFiles = fs.readdirSync(origin);
const targetFiles = fs.readdirSync(target);
originFiles.forEach((el) => {
@myesn
myesn / notranslate.user.js
Created August 6, 2021 13:42 — forked from abel533/notranslate.user.js
浏览器翻译时排除代码片段
// ==UserScript==
// @name notranslate
// @namespace https://gist.github.com/abel533/5839d3eca4686646baba113fc47e9b22
// @version 1.0
// @description 浏览器翻译时排除代码片段
// @author isea533
// @match *://**/*
// @grant none
// ==/UserScript==
@myesn
myesn / node-express-cluster.js
Last active December 21, 2021 03:31
node.js 利用所有的 CPU 内核
const express = require('express');
const os = require('os');
const cluster = require('cluster');
const app = express();
const PORT = process.env.PORT || 5000;
const clusterWorkerSize = os.cpus().length;
if (clusterWorkerSize > 1) {
if (cluster.isMaster) {
@myesn
myesn / node-koa-cluster.js
Last active December 21, 2021 03:31
node.js 利用所有的 CPU 内核
const Koa = require('koa');
const os = require('os');
const cluster = require('cluster');
const app = new Koa();
const PORT = process.env.PORT || 5000;
const clusterWorkerSize = os.cpus().length;
if (clusterWorkerSize > 1) {
if (cluster.isMaster) {
@myesn
myesn / shenyu-admin logs(step 6).txt
Created April 8, 2022 03:21
shenyu-admin logs(step 6)
ubuntu@ubuntu:~/shenyu/docker/shenyu-v2.4.2$ docker-compose logs -f shenyu-admin
Attaching to shenyu-admin
shenyu-admin | entrypoint.sh: 19: [[: not found
shenyu-admin | current jdk version:1.8.0_322
shenyu-admin | /opt/shenyu-admin/bin/start.sh: 45: [[: not found
shenyu-admin | /opt/shenyu-admin/bin/start.sh: 47: [[: not found
shenyu-admin | /opt/shenyu-admin/bin/start.sh: 49: [[: not found
shenyu-admin | Starting the ShenYu-Admin ...
shenyu-admin | Please check the log files: /opt/shenyu-admin/logs/shenyu-admin.log
shenyu-admin | 02:15:20,659 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
@myesn
myesn / shenyu-admin logs(step 8).txt
Created April 8, 2022 03:24
shenyu-admin logs(step 8)
ubuntu@ubuntu:~/shenyu/docker/shenyu-v2.4.2$ docker-compose logs -f shenyu-admin
Attaching to shenyu-admin
shenyu-admin | entrypoint.sh: 19: [[: not found
shenyu-admin | current jdk version:1.8.0_322
shenyu-admin | Starting the ShenYu-Admin ...
shenyu-admin | /opt/shenyu-admin/bin/start.sh: 45: [[: not found
shenyu-admin | /opt/shenyu-admin/bin/start.sh: 47: [[: not found
shenyu-admin | /opt/shenyu-admin/bin/start.sh: 49: [[: not found
shenyu-admin | Please check the log files: /opt/shenyu-admin/logs/shenyu-admin.log
shenyu-admin | at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434)
@myesn
myesn / diff-between-datetime-by-rules.js
Created April 21, 2022 14:12
按照指定规则计算 开始日期时间-结束日期时间 之间的时间差
getTimes(val) {
const [startDateRaw, endDateRaw] = val;
const startDate = new Date(startDateRaw);
const endDate = new Date(endDateRaw);
const diffOfMilliseconds = endDate - startDate; // 时间差,单位毫秒
const hoursOfDay = 24; // 一天的小时数
const millisencondsOfMinute = 60 * 1000; // 每分钟的毫秒数
const millisencondsOfHour = 60 * millisencondsOfMinute; // 每小时的毫秒数
const millisencondsOfDay = hoursOfDay * millisencondsOfHour; // 每天的毫秒数