西维蜀黍

【Git】常用命令

Branch

Create a New Branch

git checkout

# create a new branch checkouted from current commit, and switch to the new branch
$ git checkout -b <new_branch_name>

# create a new branch checkouted based on a specific reference (branch, remote/branch, tag are examples of valid references)
$ git checkout -b <new_branch_name> <reference>
# e.g.,
$ git checkout -b feature-branch master

git branch

# Create new branch based on the current commit (but doesn't switch to the new branch created)
$ git branch <branch_name>

# Create new branch based on a specific commit
$ git branch <branch_name> <commit_hash>
  ...


【macOS】效率

macOS 快捷键

跳转光标

  • 到行首:[ctrl + A] or [Command + 方向键左]
  • 到行尾:[ctrl + E] or [Command + 方向键右]
  • 按 word 移动:Alt (Option ⌥) + ←/→
  • 将光标快速移动到整篇文本开头/结尾:Command + 方向键上/方向键下

快速选中文本

  • 选中从当前位置到行首/行尾的所有内容:Command + Shift + ←/ →

  • 可以选中一个单词:Option + Shift + 方向键左/右」

  • 用鼠标点任意一个位置(即时你什么都看不见),按住shift,点另外一个位置,就自动选中这之间的内容了

删除内容

  • 使用 Option ⌥ + ⌫ 或 Control + ⌫ 来向左按 word 删除
  • 使用 Option ⌥ + Delete 或 Control+ Delete 来向右按 word 删除
  • 使用 Command + ⌫ 来向左将从光标位置至行首部分全部删除
  • 使用 Command + Delete 来向右将从光标位置至行尾部分全部删除

Control Mission Control

  ...


【Cache System】缓存(Cache)

Definition

In computing, a cache is a hardware or software component that stores data so that future requests for that data can be served faster; the data stored in a cache might be the result of an earlier computation or a copy of data stored elsewhere.

A cache hit occurs when the requested data can be found in a cache, while a cache miss occurs when it cannot. Cache hits are served by reading data from the cache, which is faster than recomputing a result or reading from a slower data store; thus, the more requests that can be served from the cache, the faster the system performs.

To be cost-effective and to enable efficient use of data, caches must be relatively small. Nevertheless, caches have proven themselves in many areas of computing, because typical computer applications access data with a high degree of locality of reference. Such access patterns exhibit temporal locality, where data is requested that has been recently requested already, and spatial locality, where data is requested that is stored physically close to data that has already been requested.

  ...


【Linux】Shell - Bash Utility

# Execute a command:
$ bash -c "command"

# Run commands from a file:
$ bash file.sh

# Run commands from a file, logging all commands executed to the terminal:
$ bash -x file.sh

# Run commands from a file, stopping at the first error:
$ bash -e file.sh

# Run commands from stdin:
$ bash -s
  ...


【Linux】命令 - echo

Usage

# Print a text message. Note: quotes are optional:
$ echo "Hello World"

# Print a message with environment variables:
$ echo "My path is $PATH"

# Append a message to the file:
$ echo "Hello World" >> file.txt

# Enable interpretation of backslash escapes (special characters):
$ echo -e "Column 1\tColumn 2"
  ...


【Distributed System】高可用(High-availability)

High availability

High availability (HA) is a characteristic of a system which aims to ensure an agreed level of operational performance, usually uptime, for a higher than normal period.

Modernization has resulted in an increased reliance on these systems. For example, hospitals and data centers require high availability of their systems to perform routine daily activities. Availability refers to the ability of the user community to obtain a service or good, access the system, whether to submit new work, update or alter existing work, or collect the results of previous work. If a user cannot access the system, it is – from the user’s point of view – unavailable.

Generally, the term downtime is used to refer to periods when a system is unavailable.

  ...


【Cache System】缓存更新策略

Update Cache Design Pattern

  • Cache aside Pattern
  • Read through Pattern
  • Write through Pattern
  • Write Back/ Write Behind Pattern
  ...


【Engineering】Code Review

  ...


【MySQL】MySQL 性能优化

EXPLAIN 你的 SELECT 查询

使用 EXPLAIN 关键字可以让你知道MySQL是如何处理你的SQL语句的。这可以帮你分析你的查询语句或是表结构的性能瓶颈。

EXPLAIN 的查询结果还会告诉你你的索引主键被如何利用的,你的数据表是如何被搜索和排序的……等等,等等。

  ...


【Performance】网络调优

Misc

查看一下网络带宽使用情况,在Linux下,你可以使用iftop, iptraf, ntop, tcpdump这些命令来查看

测试TCP的RTT时间

$ ping aaa.com
PING aaa.com (10.1.2.3) 56(84) bytes of data.
64 bytes from 10.1.2.3: icmp_seq=1 ttl=61 time=0.104 ms
64 bytes from 10.1.2.3: icmp_seq=2 ttl=61 time=0.097 ms
64 bytes from 10.1.2.3: icmp_seq=3 ttl=61 time=0.103 ms
64 bytes from 10.1.2.3: icmp_seq=4 ttl=61 time=0.116 ms
64 bytes from 10.1.2.3: icmp_seq=5 ttl=61 time=0.086 ms
64 bytes from 10.1.2.3: icmp_seq=6 ttl=61 time=0.101 ms
64 bytes from 10.1.2.3: icmp_seq=7 ttl=61 time=0.086 ms
64 bytes from 10.1.2.3: icmp_seq=8 ttl=61 time=0.095 ms
64 bytes from 10.1.2.3: icmp_seq=9 ttl=61 time=0.091 ms
64 bytes from 10.1.2.3: icmp_seq=10 ttl=61 time=0.092 ms

输出显示每个包的往返时间(round trip time,RTT)并总结各种统计信息。由于时间戳是由ping命令自己计量的,其中包括获取时间戳到处理网络 I/O 的整个 CPU 代码路径执行时间。

  ...