Skip to content

Instantly share code, notes, and snippets.

@espring
espring / MQTT.js v5 enhanced authentication.md
Last active August 10, 2023 01:07
MQTT.js v5 enhanced authentication

与Server无交互, 使用固定的 authenticationData

  • authenticationMethod 在各处必须是相同.
  • 覆盖client.handleAuth方法, 在cb函数中将原有的packet返回, 不这样做, 会报undefined错误. 不明白为什么是这样.
const mqtt = require('mqtt')

  const opt = {
    protocolVersion: 5, // MQTT5
@espring
espring / protobuf.js.md
Last active August 1, 2023 05:45
protobuf.js

https://github.com/protobufjs/protobuf.js

保持proto文件中变量名的定义格式

> const protobuf = require('protobufjs');
> const root = new protobuf.Root();
> root.loadSync('./test.proto', {keepCase: true});
@espring
espring / gist:906bc6dc63db9295717be0109c6d3b0a
Last active March 24, 2023 10:17
ethers.js cheatsheet
## 生成bytes32
ethers.utils.formatBytes32String("")
空字符串时生成 0x00...00
## 私钥 -> 公钥 -> 地址
@espring
espring / golang: dotenv
Created January 5, 2023 02:05
golang 环境变量配置库
//https://github.com/joho/godotenv
import (
"log"
"os"
"github.com/joho/godotenv"
)
func main() {
err := godotenv.Load()
```js
'use strict';
const Boom = require('boom')
module.exports = {
lifecycles: {
beforeCreate: async (data) => {
# basic usgae.
const { describe, expect, test, it } = require('@jest/globals')
beforeAll( async () => { });
afterAll( async () => { });
beforeEach(() => { });
afterEach(() => { });
@espring
espring / Joi cheatsheet
Last active August 12, 2021 06:56
Joi cheatsheet
# basic usage.
```js
const Joi = require('joi')
const Schema = Joi.object({
username: Joi.string().required().description('user name)
})
// 如果失败, 抛出异常.
const value = await Schema.validateAsync(config)
// 同步返回value, 如果出错, error不为null
const fs = require('fs')
const path = require('path')
const withLess = require('@zeit/next-less')
const lessToJS = require('less-vars-to-js')
require('dotenv').config()
// Where your antd-custom.less file lives
const themeVariables = lessToJS(
fs.readFileSync(path.resolve(__dirname, './assets/custom-less/antd-custom.less'), 'utf8')
# create nextjs project.
会新建目录.
```
npx create-next-app
```
# import antd modules
1) next.config.js 中增加less相关的配置.(另见)
新建 ./assets/custom-less/antd-custom.less, 可在其中定义antd的theme变量.
注意, 使用css的地方暂时需要移除, 因为不能同时支持css和less
@espring
espring / setNodeMirror.sh
Created September 8, 2020 08:03 — forked from hetykai/setNodeMirror.sh
修改node npm yarn的镜像源设置,替换为国内的淘宝源
npm set registry https://registry.npm.taobao.org && \
npm set disturl https://npm.taobao.org/dist && \
npm set sass_binary_site https://npm.taobao.org/mirrors/node-sass && \
npm set electron_mirror https://npm.taobao.org/mirrors/electron/ && \
npm set puppeteer_download_host https://storage.googleapis.com.cnpmjs.org && \
npm set chromedriver_cdnurl https://npm.taobao.org/mirrors/chromedriver && \
npm set operadriver_cdnurl https://npm.taobao.org/mirrors/operadriver && \
npm set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs && \
npm set selenium_cdnurl https://npm.taobao.org/mirrors/selenium && \
npm set node_inspector_cdnurl https://npm.taobao.org/mirrors/node-inspector && \