Virtual - Technology & Digital World

This section covers all technology-related knowledge: development tools, programming languages, system administration, and digital infrastructure.

Contents

Development Tools

  • Editor - Vim/Neovim and VSCode configuration & usage
  • Git - Version control workflows and best practices

Programming Languages

  • Rust - Systems programming language

System Administration & DevOps

  • Linux - System administration and command line
    • CentOS - CentOS-specific setup and configuration
  • S3 - AWS S3 and cloud storage solutions
  • Telegram - Bot development and automation

Philosophy

The "virtual" world encompasses all digital technologies, tools, and systems that exist in software and networks. This includes everything from text editors and programming languages to cloud infrastructure and automation tools.

Development

Editor Configuration & Usage

This guide covers setup and usage for various editors, primarily focusing on Vim/Neovim with VSCode as an alternative.

Vim/Neovim Setup

Installation

Amazon Linux 3

sudo yum groups install -y Development\ tools
sudo yum install -y cmake python34-{devel,pip}
sudo pip-3.4 install neovim --upgrade
(
cd "$(mktemp -d)"
git clone https://github.com/neovim/neovim.git
cd neovim
make CMAKE_BUILD_TYPE=Release
sudo make install
)

Amazon Linux 2

sudo yum install openssl-devel
wget https://github.com/Kitware/CMake/releases/download/v3.31.4/cmake-3.31.4.tar.gz
tar -xvzf cmake-3.31.4.tar.gz
cd cmake-3.31.4
./bootstrap && make && sudo make install
export PATH="/usr/local/bin:$PATH"

git clone https://github.com/neovim/neovim
cd neovim
git checkout stable
make CMAKE_BUILD_TYPE=RelWithDebInfo
sudo make install

Configuration

Basic Vim with Vundle

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

Basic ~/.vimrc:

set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

Plugin 'VundleVim/Vundle.vim'
Plugin 'scrooloose/nerdtree'
Plugin 'kien/ctrlp.vim'
Plugin 'google/vim-colorscheme-primary'
Plugin 'vim-airline/vim-airline'

call vundle#end()
filetype plugin indent on

" Navigation shortcuts
nmap <C-h> <C-w>h
nmap <C-j> <C-w>j
nmap <C-k> <C-w>k
nmap <C-l> <C-w>l
nmap <C-n> :NERDTree<CR>
nmap <C-p> :CtrlP<CR>

" Appearance
syntax on
set t_Co=256
set background=dark
colorscheme primary
set number

LazyVim

  • Add Rust support: run :LazyExtra
  • Check missed notifications: :messages
  • Close buffer: <leader>bd (where <leader> is space)
  • Jump to function: <leader>ss
  • Navigation: <c-o>, <c-i>, gd

Essential Operations

Basic Commands

ModeCommandDescription
Normali / aInsert before/after cursor
NormalvVisual mode
Any<ESC>Return to normal mode

Copy/Paste/Delete

CommandDescription
yyCopy whole line
yawCopy all word
2yyCopy next 2 lines
p / PPaste after/before
2ddDelete next 2 lines
"+System clipboard register

Window & Buffer Management

CommandDescription
:lsList buffers
:b NGo to buffer N
C-w s/vSplit window horizontally/vertically
C-w cClose current window
C-w oClose all other windows
C-w =Make all windows equal size
C-w TMove window to new tab
gtNext tab
:tabcClose current tab
CommandDescription
:e %:h[TAB]Edit from current file's directory
C-o / C-iNavigate jump list backward/forward
:juShow jump list
gdGo to definition (LazyVim)

VSCode Configuration

Rust Integration

Update settings.json:

{
  "rust-analyzer.server.path": "/Users/lky/.cargo/bin/rust-analyzer"
}

Quick Reference

Getting Started

  1. Hit <ESC> when confused
  2. Use i to insert, <ESC> to navigate
  3. Basic workflow: navigate → edit → save → repeat

Essential Help

  • :h [command] - Show help for command
  • :q - Quit
  • :w - Save
  • :wq - Save and quit

References

git

Local auth

The easiest way to avoid creating a token.

brew install gh

gh auth login

Branches

descriptioncommand
checkout branchgit checkout <branch name>
create branchgit branch <branch name>
remove local branchgit branch -D <branch name>
remove remote branchgit push origin --delete <branch name>
list branchgit branch
sync local branch to remote origin/maingit fetch origin && git merge origin/main

Commits

descriptioncommand
take the most recent commit and add new staged change to itgit commit --amend
remove all untracked files including ignoredgit clean --fdx
uncommit change but keep filesgit reset --soft HEAD^
remove all untracked filesgit restore .
move head to a commit and discard changes aftergit reset --hard <COMMIT_ID>
force syncing remote to localgit push --force
rebase to maingit checkout main && git pull && git checkout <FEATURE> && git rebase main
merge to mainuse sqash and merge

Files

descriptioncommand
move changes to stashgit stash
move changes out of stashgit stash pop
revert a file to its state in maingit checkout origin/main [filename]

Misc

descriptioncommand
pretty loggit log --all --decorate --oneline --graph
emojihttps://gitmoji.dev/

Programming

Rust

References

  1. tokio

Tokio

Q n A

  1. What does Send mean? Send means that when .await suspends the thread, the result can be moved to another thread (the caller thread). Rcis a type that cannot be Send. Sync means a type can be concurrently accessed through immutable references. Cell is Send but not Sync because it can be modified through an immutable reference.
  2. What's the benefit of bytes::Bytes over Vec<u8>? clone() on Bytes does not clone the data. It is roughly an Arc<Vec<u8>>.
  3. Difference between sync mutex std::sync::Mutex and async mutext tokio::sync::Mutex? Sync mutex will block current thread while waiting but async mutex won't.
  4. The problem with sync mutex is that when multiple threads are contending (i.e. competing) for a mutex, only one will be working while others are all waiting. To solve this problem:
  5. Switching to a dedicated task to manage state and use message passing
  6. shard the mutex
  7. restructure code to avoid mutex
  8. Sending with oneshot channel does not require await. Result of success or failure is known immediately.
  9. rust async functions are state machines. It will check the contained future's poll() and decide if go to the next state, or check back later.

Stream

Follow this tutorial to learn how to create a stream. Especially the implementation of into_stream()

Trait

Blanket implementations

implementations of a trait on any type that satisfies the trait bounds are called blanket implementations and are use extensively in the rust standard library. For example, the standard library implements the ToString trait on any type that implements the Display trait. The impl block in the standard library looks similar to this code:

#![allow(unused)]
fn main() {
impl <T: Display> ToString for T {}
}

System

Linux

Linux commands. From the book of A Practical Guild to Linux Commands, Editors and Shells.

stdio

File descriptor 0 (stdin), 1 (stdout), 2 (stderr).

  • > is short for 1>, meaning redirecting standard output.
  • < is short for 0< redirects standard input.
  • 2> redirects stardard error.

Example

$ cat y
This is y

$ cat x
cat: x: No such file or directory

$ cat x y
This is y
cat: x: No such file or directory

pipe only sends stdout not stderr

$ cat x y | tr "[a-z]" "[A-Z]"
cat: x: No such file or directory
THIS IS Y

In the next example, 1> redirects stdout to hold, then 2>&1 declares file descriptor 2 to be a duplicate of file descriptor 1, so both stdout and stderr are redirected to hold. Notice that 1> should happen first.

$ cat x y 1> hold 2>&1
$ cat hold
cat: x: No such file or directory
This is y

In the next example, 2>&1 means also send stderr to stdout. Then pipes stdout to tr

$ cat x y 2>&1 | tr "[a-z]" "[A-Z]"
CAT: X: NO SUCH FILE OR DIRECTORY
THIS IS Y

2>&1 | can be shortened as |&

pipe | - tunnels the output (stdout only) of left to right.

Example:

$ cat abstract
cab

$ cat abstract | tr abc ABC
CAB

$ tr abc ABC < abstract
CAB

&& and ||, cmd1 && cmd2 means run cmd2 if cmd1 succeeds. cmd1 || cmd2 means run cmd2 if cmd1 fails.

adding & means running the command in the background.

kill can kill a job with PID or job number.

$ ps

11829 pts/10

$ kill 11829

$ jobs
[1]

$ kill %1

Bash

./whoson the ./ tells the shell to look for an executable file in the working dir.

#!/bin/bash tells the system which shell to use. #! is called hashbang or shebang

-e will cause bash to exit when command fails. -u will cause bash to display a message and exit when it tries to expand an unset variable.

d & e & f will run d and e in the background and run f in the foreground.

[1]- Done  d
[2]+ Done  e

The + means it's the last job. - means it's the job before the last one.

Setup CentOS machine (AWS Amazon Linux 2023)

Installations

  1. VIM

  2. zsh

    1. sudo yum install zsh
    2. set zsh as default by editing /etc/passwd
    3. sudo yum install git
    4. install OhMyZsh sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
    5. install PowerLevel10k: git clone --depth=1 https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k
    6. change theme to it in ~/.zshrc: ZSH_THEME="powerlevel10k/powerlevel10k"
    7. source ~/.zshrc
    8. install zsh-autosuggestions: ref
      git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
      
    9. install zsh-syntax-highlighting: ref
      git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
      
  3. tmux

    1. git clone https://github.com/gpakosz/.tmux.git ~/.tmux
    2. ln -s ~/.tmux/.tmux.conf ~/.tmux.conf
    3. add to zshrc: work() { tmux new-session -A -s ${1:-work}; }
# ~/.tmux.conf

# make delay shorter
set -sg escape-time 0

### key bindings ###
bind r source-file ~/.tmux.conf \; display ".tmux.conf reloaded!"

# quickly open a new window
bind N new-window

# synchronize all panes in a window
bind y setw synchronize-panes

# pane movement shortcuts
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# enable mouse support for switching panes/windows
set -g mouse on
#### copy mode : vim ####
# set vi mode for copy mode
setw -g mode-keys vi
# copy mode using 'Esc'
unbind [
bind Escape copy-mode
# paste using 'p'
unbind p
bind p paste-buffer

set-option -g default-shell "/bin/zsh"
  1. github

    1. curl -Lo gh-cli.rpm https://github.com/cli/cli/releases/download/v2.30.0/gh_2.30.0_linux_arm64.rpm
    2. sudo yum install -y ./gh-cli.rpm
  2. docker

    1. sudo dnf update -y
    2. sudo dnf install -y docker
    3. sudo systemctl enable docker
    4. sudo curl -L "https://github.com/docker/compose/releases/download/$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    5. sudo chmod +x /usr/local/bin/docker-compose
    6. docker-compose --version
1. mosh
# Install dependencies
sudo yum groupinstall "Development Tools" -y
sudo yum install openssl-devel protobuf-devel ncurses-devel zlib-devel perl cmake -y

# Download and build Mosh
curl -L -O https://github.com/mobile-shell/mosh/releases/download/mosh-1.3.2/mosh-1.3.2.tar.gz
tar -xzf mosh-1.3.2.tar.gz
cd mosh-1.3.2
./configure
make
sudo make install

S3 + Remote File System

S3

To keep S3 in sync with local fs, use the AWS CLI. For example, we have a s3 directory s3://s3-yoshi/kongming_snapshot. Then run this command to sync.

aws s3 sync s3://s3-yoshi/kongming_snapshot ~/kongming_snapshot

Before this, acquire the key and secret by clicking user name on the top right corner in AWS console, and select credentials. Then add them as env var in .zshrc.

export AWS_ACCESS_KEY_ID=<ID> && export AWS_SECRET_ACCESS_KEY=<KEY>

Remote desktop

  1. In mac, the mounted external drive is in /Volumes directory. Then go to settings, general, and choose to share the external drive.
  2. In the client machine, right click on finders, select "connect to server" and pick the shared directory. This directory will show up under /Volumes/ then.

Telegram

How to create a bot and send messages to group

  1. create a bot use BotFather, get the bot token
  2. create a group and add Get ID Bot
  3. send a message in the group chat with \my_id @<BOT_NAME>, there will be a Your Group Chat ID: <GOURP_CHAT_ID>.
  4. use the bot token and group chat id to send messages to the group

Real - Physical World & Human Knowledge

This section covers knowledge about the physical world, human learning, and real-world domains.

Contents

Learning & Methods

Professional Knowledge

  • Medical - Medical knowledge and clinical notes
    • CRVO - Central Retinal Vein Obstruction

Philosophy

The "real" world encompasses physical phenomena, human biology and psychology, learning processes, and knowledge that applies to tangible, real-world situations. This includes learning methodologies, medical knowledge, and other domains rooted in physical reality.

Methodology

Talks about how to do things effectively.

Work

  • Focus - Eliminate distractions:

    • Keep a clean desk with minimal items
    • Use fewer tools to avoid context switching
    • Find quiet spaces away from notifications and conversations
    • Avoid multi-tasking
    • Block 1-2 hours for focused work, then take breaks
  • Energy Management - Identify your peak hours when you're most alert (typically 2-4 hours after waking) and schedule demanding work during these times. Work in 90-120 minute cycles with 15-20 minute breaks to match your natural energy rhythms.

  • Reflection - Periodically improve the process by reprioritizing work and finding ways to further improve efficiency.

Learn

Four key steps to learn a technique.

  1. Select a concept and map your knowledge
  2. Teach it to a 12-year-old
  3. Review and refine
  4. Test and archive

Step 1 Select a concept and map your knowledge

Start with a blank page. Write everything you know about your chosen topic.

Explain it to a 12-year-old

Review and refine

When you find weak spots, return to the source material. Study those sections until you can explain them simply.

Test and Archive

Test your understanding by teaching someone else. Once satisfied, archive your simple explanation in a learning binder for periodic review.

Medical

Central Retinal Vein Obstruction

Terminologies

  • edema: swelling due to fluid buildup

  • Etiology: the cause or origin of disease or condition

  • ischemic: ischemic refers to a condition caused by restricted blood flow to a part of the body, usually due to blockage in blood vessels. This lack of blood flow reduces oxygen supply to tissues, which can lead to damage or dysfunction.

  • macula: The macula is the cental part of the retina, located at the back of the eye. It is responsible for sharp, detailed central vision and color perception. The macula contains a high concentration of cone photoreceptor cells, which help in recognizing fine details, such as reading, recognizing faces and seeing colors vividly.

Epidemology and Etiology

Pathophysiology

Important Clinical Signs

Differential Diagnosis

Diagnostic Evaluation

  • Intravenous fluorescein angiography: This is to inject fluorescein dye into a vein, which then travels to the blood vessels in the retina. Normally the dye fills the arteries first, then veins without delay. A delay in retinal venous filling sugests an issue with blood flow through the veins, which is commonly seen in conditions like CRVO. Intra-retinal leakage of dye means that the blood vessels are leaking fluid into the retina, which is a sign of vascular damage or breakdown of the blood-retinal barrier.

  • OCT: reveals the presence or absense of macular edema. PAMM (paracentral accute middle maculopathy, a specific OCT finding that indicates ischemia affecting the deep capillary plexus) is a sign of retinal ischemia.

Stories 📚

真实世界中的故事与人生感悟

关于这个分类

这里收录了各种有趣的故事、历史典故和人生感悟。通过故事的形式,我们可以更好地理解历史、人性和社会现象。

故事特色

  • 历史重现:用现代视角重新诠释历史事件
  • 人性思考:通过故事探讨人性的复杂与美好
  • 现实映射:古代故事与现代生活的巧妙对比
  • 幽默风趣:用轻松的语言讲述深刻的道理

阅读体验

每个故事都经过精心整理,采用:

  • 🎭 分幕结构:清晰的章节划分
  • 💡 现代元素:贴近当代的表达方式
  • 🎯 深度思考:故事背后的人生哲理
  • 📖 易读性:适合各种场景阅读

"故事是人类最古老的学习方式,也是最温暖的传承载体。"