/images/avatar.png

谷中仁的博客

所有文章观点仅代表本站观点,与他人无关。

Config ssh to Keychina

将生成的 ssh 私钥添加到 Mac 的 keychain 中, 如果是其他操作系统,可忽略此步骤

$ ssh-add -K .ssh/is_rsa

将登录信息配置到。ssh/config 中

$ touch ~/.ssh/config
$ vim ~/.ssh/config
# edit text
Host myvm
  Hostname ip
  User user

保存之后就可以使用如下命令快捷登录服务器了

$ ssh myvm

参考地址

https://blog.infox.ren/2019/10/24/ssh-guide/

基于 Rust 的 WebAssembly 工程开发过程小记

初始化工程

$ npm init rust-webpack web_assembly_demo
npx: 18 安装成功,用时 3.989 秒
 Rust +  WebAssembly + Webpack = ️
Installed dependencies

安装 Web 依赖

$ yarn
yarn install v1.19.1
warning package.json: No license field
info No lockfile found.
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
warning rust-webpack-template@0.1.0: No license field
[1/4]   Resolving packages...
warning @wasm-tool/wasm-pack-plugin > watchpack > chokidar > fsevents@1.2.9: One of your dependencies needs to upgrade to fsevents v2: 1) Proper nodejs v10+ support 2) No more fetching binaries from AWS, smaller package size
[2/4]   Fetching packages...
[3/4]   Linking dependencies...
[4/4]   Building fresh packages...
success Saved lockfile.
  Done in 17.87s.

修改 Cargo.toml 为

# You must change these to your own details.
[package]
name = "web_assembly_demo"
description = "My super awesome Rust, WebAssembly, and Webpack project!"
version = "0.1.0"
authors = ["guzhongren <guzhoongren@live.cn>"]
categories = ["wasm"]
readme = "README.md"
edition = "2018"

[lib]
crate-type = ["cdylib"]

[profile.release]
# This makes the compiled code faster and smaller, but it makes compiling slower,
# so it's only enabled in release mode.
lto = true

[features]
# If you uncomment this line, it will enable `wee_alloc`:
#default = ["wee_alloc"]

[dependencies]
# The `wasm-bindgen` crate provides the bare minimum functionality needed
# to interact with JavaScript.
wasm-bindgen = "0.2.45"

# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
# compared to the default allocator's ~10K. However, it is slower than the default
# allocator, so it's not enabled by default.
wee_alloc = { version = "0.4.2", optional = true }

# The `web-sys` crate allows you to interact with the various browser APIs,
# like the DOM.
[dependencies.web-sys]
version = "0.3.22"
features = ["console"]

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so it's only enabled
# in debug mode.
[target."cfg(debug_assertions)".dependencies]
console_error_panic_hook = "0.1.5"

# These crates are used for running unit tests.
[dev-dependencies]
wasm-bindgen-test = "0.2.45"
futures = "0.1.27"
js-sys = "0.3.22"
wasm-bindgen-futures = "0.3.22"

Rust 的依赖会在启动 Web 程序的时候自动安装。

在 VSCode 上配置 Rust 的调试环境

https://images.pexels.com/photos/3858142/pexels-photo-3858142.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260

插件

在 VS Code 上进行 Rust 的开发,需要使用一下两个库

  • RLS(vscode 搜索插件 rls)
  • lldb(vscode 搜索插件 codelldb)

安装很简单,不用说

配置

{
  // 使用 IntelliSense 了解相关属性。
  // 悬停以查看现有属性的描述。
  // 欲了解更多信息,请访问:https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug executable 'show_posts'", // 配置名称,将会在调试配置下拉列表中显示
      "type": "lldb", // 调试器类型:Windows 表示器使用 cppvsdbg;GDB 和 LLDB 使用 cppdbg。该值自动生成
      "request": "launch", // 调试方式
      "cargo": { // 运行的参数
        "args": [
          "build",
          "--bin=show_posts",
          "--package=diesel_demo"
        ],
        "filter": {
          "name": "show_posts",
          "kind": "bin"
        }
      },
      "args": [], // 传递给程序的参数,没有参数留空即可
      "cwd": "${workspaceFolder}" // 调试程序时的工作目录
    },
}

https://yqfile.alicdn.com/418ec9989800421ab7ab8d03aa79b3ebde85e77d.png

Git Revert 多条已提交的记录

我需要撤销最后的四个提交

https://yqfile.alicdn.com/3fbcbf5e8d1d7d7d1ab6f5978b9df1f702f4e420.png

如果用* git revert * 一个一个 revert 挺费劲,可以用* git revert OLDER_COMMIT^..NEWER_COMMIT* 这种格式,对应我的工程就是

$ git revert 54b23c2251acde.....09123463e99436fba83f9^..a19a10b24b648b80401234686aac65...

这样会在 log 上多留下四条 revert 相关的记录,我不想生成 revert 相关的记录呢?可以的

Golang 依赖注入 (Dependency Injection)

Dependency Injection 🧪

依赖注入是目前很多优秀框架都在使用的一个设计模式。 Dependency Injection 常常简称为:DI。它是实现控制反转(Inversion of Control – IoC)的一个模式。

在各种大工程中少不了各种测试,其中 TDD 就是非常流行的一种,在前端开发中用的比较多的 Jest 就是一种,在 Golang 开发命令行工具的时候也是需要 DI 这种模式来实现命令行测试的。因为传统的测试室获取不到命令行的输入输出的。

Golang With SQLLite Practice

简介

SQLite 是一个进程内的库,实现了自给自足的、无服务器的、零配置的、事务性的 SQL 数据库引擎。它是一个零配置的数据库,这意味着与其他数据库一样,你不需要在系统中配置。在 Golang 中使用 SQLLite 也相当简单,只需要安装 SQLLite 的 Golang 包即可使用; Golang 就不多介绍了,能看到这个肯定对 Golang 有一定的了解。