Live Note

Remain optimistic

** 需求:已知一个路径,读取文件内容并返回 **

  • 普通读取文件方式:
1
2
3
4
5
6
const fs = require("fs")
const path = require("path")
fs.readFile(path.join(__dirname, "./1.txt"), "utf-8", (err, dataStr) => {
if (err) throw err
console.log(dataStr)
})
Read more »

Binary Search Tree

  • 若左子树不空,则左子树上所有结点的值均小于它的根结点的值。
  • 若右子树不空,则右子树上所有结点的值均大于它的根结点的值。
  • 左、右子树也分别为二叉排序树。
  • 没有键值相等的节点。

实现

Node:

1
2
3
4
5
6
7
8
let print = (key) => console.log(key)
class Node {
constructor(key) {
this.key = key
this.left = null
this.right = null
}
}
Read more »

什么是 Diamond

Diamond 指的是一种设计模式,称为 EIP-2535 Diamonds。这种模式用于构建可模块化和可升级的以太坊智能合约。

Diamond

  • 模块化架构:Diamond 是一种创建单一、模块化合约(称为 Diamond)的方式,该合约将不同的功能委托给分离的、可互换的合约组件(称为 Facets)。这有助于更好地组织代码和分离关注点。
  • Facets:每个 Facet 包含特定的功能,并可以独立升级。例如,一个 Facet 可能处理用户管理,而另一个处理交易。
  • Diamond Storage:在 Diamond 模式中,合约的存储结构被设计成可以支持不同 Facets 的升级,而不影响整体合约的其他部分。

对外部世界(如用户界面、其他智能合约和软件/脚本)而言,Diamond 看起来是一个单一的智能合约,具有一个单一的以太坊地址。但在内部,它使用一组称为 Facets 的合约来处理其外部功能,这些 Facets 对外部是隐藏的。

Read more »

Why is this error occurring?

The ERR_OSSL_EVP_UNSUPPORTED error in a React JS application typically arises due to an underlying issue with the version of Node.js and OpenSSL being used. This error is commonly encountered when certain cryptographic algorithms or keys are not supported by the OpenSSL version bundled with the Node.js installation.

How can I fix this error?

Node.js 17 has a new option called –openssl-legacy-provider. This option lets you go back to using the old way of doing things until you can update your code to work with the new rules.

package.json file

package.json
1
2
3
4
5
{
"scripts": {
"start": "node --openssl-legacy-provider index.js"
}
}

set environment variable

1
export NODE_OPTIONS=--openssl-legacy-provider

change it in the gradle file

build.gradle
1
2
3
project.ext.react = [
nodeExecutableAndArgs: ["node", "--openssl-legacy-provider"]
]

change it in the Xcode build settings

project.pbxproj
1
2
3
buildSettings = {
NODE_OPTIONS = "--openssl-legacy-provider";
}

After changes, try running the application again. Or you also need to reinstall the dependencies.