From 28daffb38a4bc23f6901b1e99a6ab8e35fe7e61c Mon Sep 17 00:00:00 2001 From: veypi Date: Sun, 5 Jun 2022 10:19:11 +0800 Subject: [PATCH] update --- babylonjs/start.md | 57 +++++++++++++ book/eyi.md | 3 + linux/iscsi.md | 14 +++ linux/lvm_recover.md | 3 + openstack/kolla.md | 5 +- rust/date.md | 10 +++ rust/future.md | 107 +++++++++++++++++++++++ rust/marco.md | 199 +++++++++++++++++++++++++++++++++++++++++++ rust/rust.md | 24 ++++++ vim/mac.md | 18 ++++ vue/vue3.md | 24 ++++++ 11 files changed, 463 insertions(+), 1 deletion(-) create mode 100644 babylonjs/start.md create mode 100644 book/eyi.md create mode 100644 linux/iscsi.md create mode 100644 linux/lvm_recover.md create mode 100644 rust/date.md create mode 100644 rust/future.md create mode 100644 rust/marco.md create mode 100644 rust/rust.md create mode 100644 vim/mac.md diff --git a/babylonjs/start.md b/babylonjs/start.md new file mode 100644 index 0000000..d01a222 --- /dev/null +++ b/babylonjs/start.md @@ -0,0 +1,57 @@ +# Babylon js + + + +## depends + +```bash +vue 3 +babylonjs 5 +``` + + + +## install + +```bash +yarn add @babylonjs/core @babylonjs/loaders +``` + + + +## 三核心 + +- 场景 +- 摄像头 +- 光 + +一般使用babylonjs 分为 3个步骤 + +```js +// 1 初始化 engine +var canvas = document.getElementById('renderCanvas') +let engine = new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true }); + +// 2 添加 场景、灯光、摄像头 +var createScene = function () { + const scene = new BABYLON.Scene(engine); + const camera = new BABYLON.ArcRotateCamera("camera", -Math.PI / 2, Math.PI / 2.5, 3, new BABYLON.Vector3(0, 0, 0)); + camera.attachControl(canvas, true); + const light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(0, 0, 1), scene); + const box = BABYLON.MeshBuilder.CreateBox("box", {}); + + return scene; +} +var scene = createScene(); + +// 3 循环渲染 +engine.runRenderLoop(function () { + scene.render(); +}); + +``` + + + +### 加载模型 + diff --git a/book/eyi.md b/book/eyi.md new file mode 100644 index 0000000..d93ea77 --- /dev/null +++ b/book/eyi.md @@ -0,0 +1,3 @@ +# 恶意 + +真的是太绝了 diff --git a/linux/iscsi.md b/linux/iscsi.md new file mode 100644 index 0000000..2f48942 --- /dev/null +++ b/linux/iscsi.md @@ -0,0 +1,14 @@ +# iscsi + + + +```bash +sudo apt-get install open-iscsi +sudo iscsiadm -m discovery -t sendtargets -p 10.*.*.* +# 挂载 +sudo iscsiadm -m node -T iqn.2000-01.com.synology:NAS01.Target-4.f41596f93f -p 10.*.*.* -l +# 卸载iscsi卷 +sudo iscsiadm -m node -T iqn.2000-01.com.synology:NAS01.Target-4.f41596f93f -p 10.*.*.* -u +``` + +sudo dd if=/dev/sdb of=/dev/sdd count=322122547200 bs=1M iflag=count_bytes,direct oflag=direct diff --git a/linux/lvm_recover.md b/linux/lvm_recover.md new file mode 100644 index 0000000..7c56de4 --- /dev/null +++ b/linux/lvm_recover.md @@ -0,0 +1,3 @@ +# lvm_recover + +https://www.golinuxcloud.com/recover-lvm2-partition-restore-vg-pv-metadata/ diff --git a/openstack/kolla.md b/openstack/kolla.md index 2aa8bf4..74cada2 100644 --- a/openstack/kolla.md +++ b/openstack/kolla.md @@ -56,7 +56,7 @@ source ~/kolla_venv/bin/activate # centos7 缺 utf-8 字符集 localedef -v -c -i en_US -f UTF-8 en_US.UTF-8 pip install -U pip -pip install ansible +pip install ansible==10.2 pip install ./kolla pip install ./kolla-ansible sudo mkdir -p /etc/kolla @@ -88,6 +88,9 @@ vim /root/kolla_venv/share/kolla-ansible/ansible/roles/baremetal/defaults/main.y docker_yum_gpgcheck: false enable_docker_repo: false +vim /home/parallels/kolla_venv/share/kolla-ansible/ansible/roles/prechecks/tasks/service_checks.yml +or result.stdout | regex_replace('.*\\b(\\d+\\.\\d+\\.\\d+)\\b.*', '\\1') is version(docker_version_min, '<') + kolla-ansible -i ./multinode bootstrap-servers kolla-ansible -i ./multinode prechecks kolla-ansible -i ./multinode deploy diff --git a/rust/date.md b/rust/date.md new file mode 100644 index 0000000..5840ceb --- /dev/null +++ b/rust/date.md @@ -0,0 +1,10 @@ +# rust 获取东八区时间 + + + +```rust +use time; + +let d = time::OffsetDateTime::now_utc().to_offset(time::UtcOffset::from_hms(8, 0, 0).unwrap()); + +``` diff --git a/rust/future.md b/rust/future.md new file mode 100644 index 0000000..9150ac2 --- /dev/null +++ b/rust/future.md @@ -0,0 +1,107 @@ +# rust 异步基础 + + + +### future + +Future 生成三种方式 + + - async {} + - fn {} -> impl Future<> + - Impl Future for struct_future {} + +```rust +use std::future::Future; +use std::pin::Pin; +use std::task::{Context, Poll}; + +use tokio::time::{sleep, Duration, Sleep}; + +struct ReadFileFuture { + count: u8, + sp: Pin>, +} + +impl Future for ReadFileFuture { + type Output = String; + fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + match self.sp.as_mut().poll(cx) { + Poll::Pending => { + println!("wait ...."); + return Poll::Pending; + } + Poll::Ready(()) => { + println!("finished wait"); + // return Poll::Ready("asd".to_string()); + } + } + if self.count < 5 { + println!(" continue read file"); + self.count = self.count + 1; + cx.waker().clone().wake(); + Poll::Pending + } else { + println!("finished to read file."); + return Poll::Ready("asd".to_string()); + } + } +} + +fn task() -> impl Future { + async { + sleep(Duration::new(1, 0)).await; + println!("task finished. cost 1."); + String::from("asd") + } +} + +async fn task2() { + sleep(Duration::new(2, 0)).await; + println!("task2 finished. cost 2s") +} +#[tokio::main] +async fn main() { + let d = Duration::new(4, 0); + let mut s = sleep(d); + let mut f1 = ReadFileFuture { + count: 0, + sp: Box::pin(s), + }; + let h1 = tokio::spawn(f1); + let h3 = tokio::spawn(task2()); + let h2 = tokio::spawn(task()); + _ = tokio::join!(h1, h2, h3); + println!("main finished") +} +``` + + + +- 运行结果 + + ```bash + wait .... + + + task finished. cost 1. + + task2 finished. cost 2s + + + finished wait + continue read file + finished wait + continue read file + finished wait + continue read file + finished wait + continue read file + finished wait + continue read file + finished wait + finished to read file. + main finished + + ``` + + diff --git a/rust/marco.md b/rust/marco.md new file mode 100644 index 0000000..ee9f703 --- /dev/null +++ b/rust/marco.md @@ -0,0 +1,199 @@ +# Rust 宏编程(1) + + + +rust 宏主要分为 派生宏、类函数宏、属性宏,可以非常方便的生成重复性代码。 + +终于可以能写会写代码的代码了罒ω罒。 + +### 环境准备 + +```bash +# dtolnay 大佬提供的 宏教学库 +git clone https://github.com/dtolnay/proc-macro-workshop.git + +## cargo expand 查看宏产生的全部代码 +rustup toolchain install nightly-x86_64-apple-darwin +# 可先执行该指令 会提示你看着那个版本的nightly +cargo +nightly install cargo-expand +``` + + + +## cargo test + +- 目录结构 + +```bash + +cd builder/ +tree + +. +├── Cargo.toml +├── src +│   └── lib.rs # 要编写宏的文件 +└── tests + ├── 01-parse.rs + ├── 02-create-builder.rs + ├── 03-call-setters.rs + ├── 04-call-build.rs + ├── 05-method-chaining.rs + ├── 06-optional-field.rs + ├── 07-repeated-field.rs + ├── 08-unrecognized-attribute.rs + ├── 08-unrecognized-attribute.stderr + ├── 09-redefined-prelude-types.rs + └── progress.rs # 通过取消注释来确定运行那个test文件 +``` + +- 编写宏代码 + +```rust +use proc_macro::TokenStream; + +#[proc_macro_derive(Builder)] +pub fn derive(input: TokenStream) -> TokenStream { + let _ = input; + // 打印看看input到底是什么 + eprintln!("{:#?}", input); + // 注释下行 并返回空的结果, 下行表示未实现该发放并进行panic + // unimplemented!() + TokenStream::new() +} +``` + +- 运行 test + +```bash +# builder 目录下 +cargo test +# 可以查看 test 运行成功无报错 并打印input 结构 +TokenStream [ + Ident { + ident: "pub", + span: #0 bytes(990..993), + }, + Ident { + ident: "struct", + span: #0 bytes(994..1000), + }, + Ident { + ident: "Command", + span: #0 bytes(1001..1008), + }, + Group { + delimiter: Brace, + stream: TokenStream [ + Ident { + ident: "executable", + span: #0 bytes(1015..1025), + }, + .... + .... + ... + Punct { + ch: ',', + spacing: Alone, + span: #0 bytes(1103..1104), + }, + ], + span: #0 bytes(1009..1106), + }, +] +``` + + + +## cargo expand + +- builder/src/lib.rs + + ```rust + use proc_macro::TokenStream; + + #[proc_macro_derive(Builder)] + pub fn derive(input: TokenStream) -> TokenStream { + eprintln!("{:#?}", input); + // 这里直接把传入的结构返回回去 + input + } + + ``` + +- main.rs 根目录下 + + ```rust + use derive_builder::Builder; + + #[derive(Builder)] + pub struct Command { + executable: String, + args: Vec, + env: Vec, + current_dir: String, + } + + fn main() {} + ``` + +- 查看扩展代码 + + ```bash + # 进入根目录, 运行 + cargo expand --bin workshop + # 等同于 + cargo expand + # 输出 + ``` + + ```rust + #![feature(prelude_import)] + #[prelude_import] + use std::prelude::rust_2021::*; + #[macro_use] + extern crate std; + use derive_builder::Builder; + pub struct Command { + executable: String, + args: Vec, + env: Vec, + current_dir: String, + } + pub struct Command { + executable: String, + args: Vec, + env: Vec, + current_dir: String, + } + fn main() {} + + ``` + + 可以看到生成了一个 多的Command结构体 + + ```bash + # 运行cargo test 可以看到报错 重复定义的Command + + ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ + error[E0428]: the name `Command` is defined multiple times + --> tests/01-parse.rs:27:1 + | + 27 | pub struct Command { + | ^^^^^^^^^^^^^^^^^^ + | | + | `Command` redefined here + | previous definition of the type `Command` here + | + = note: `Command` must be defined only once in the type namespace of this module + ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ + + ``` + + + +剩下的就是根据tests/目录下每个测试文件编写符合要求的宏代码。 + +祝各位顺利~ + +rust真TM难学,其他语言能看着demo直接上手写项目, rus已经看了一周多了,还没开始写实际代码。 \ No newline at end of file diff --git a/rust/rust.md b/rust/rust.md new file mode 100644 index 0000000..ddd742b --- /dev/null +++ b/rust/rust.md @@ -0,0 +1,24 @@ +# Rust + +#### install + +```bash +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh +rustup update +``` + + + + + +## expand + +```bash +# just for mac +rustup toolchain install nightly-x86_64-apple-darwin + +cargo +nightly install cargo-expand + + +``` + diff --git a/vim/mac.md b/vim/mac.md new file mode 100644 index 0000000..5e89d22 --- /dev/null +++ b/vim/mac.md @@ -0,0 +1,18 @@ +# vim config for mac + +```bash + +``` + + + +### fzf + +```bash + brew install fzf + # brew install --build-from-source fzf + +``` + + + diff --git a/vue/vue3.md b/vue/vue3.md index 041e26d..204f9d2 100644 --- a/vue/vue3.md +++ b/vue/vue3.md @@ -1,5 +1,17 @@ # vue3 typescript vue-router vuex setup + + +## 使用模板 + +```bash +npx degit veypi/vite-starter#master project_name +``` + + + + + ### 最近发现vue3相关库都更新的差不多了,尝试学习了新的版本, 使用setup 的确变了很多,像ref 、prop面目全非,刚开始用还找了很久 ## 创建项目 @@ -43,6 +55,18 @@ export default router +### tailwindcss + + + +```bash +npm install -D tailwindcss@latest postcss@latest autoprefixer@latest +npx tailwindcss init -p + +``` + + + ### [vuex](https://next.vuex.vuejs.org/zh/guide/typescript-support.html) ```bash