如何在vim中格式代码?

网站管理员 Published the article • 0 comments • 32 views • 2019-08-01 10:50 • 来自相关话题

如何在vim中格式代码

如何在vim中格式化代码,格式化c/c++/golang/rust/php/js/javascript/css/html/等代码。

按照如下输入,然后回车

```
# 按下`Esc`,然后按下`:`,进入命令模式
gg=G
```
如何在vim中格式代码

如何在vim中格式化代码,格式化c/c++/golang/rust/php/js/javascript/css/html/等代码。

按照如下输入,然后回车

```
# 按下`Esc`,然后按下`:`,进入命令模式
gg=G
```

How to merge multiple git commits into a new branch?

网站管理员 Published the article • 0 comments • 165 views • 2019-07-24 15:40 • 来自相关话题

### We will use the following git command:

#### git log

#### git cherry-pick

> git-log - Show commit logs

```bash
git log [] [] [[--] …​]
```

1. `--author` match the author
2. `--after` after this time's commits
3. `--before` before this time's commits
4. `--no-merges` filter the merge commits

The official's introductions

> git-cherry-pick - Apply the changes introduced by some existing commits

```bash
git cherry-pick [--edit] [-n] [-m parent-number] [-s] [-x] [--ff]
[-S[]] …​
git cherry-pick --continue
git cherry-pick --quit
git cherry-pick --abort
```

### Step 1

Get all git commits, which you want to merge to a new branch. Then, we will use the git command `git cherry-pick` to do combine.

```bash
git log --author="phantom\|ydl" \
--after="2019-07-23" \
--before="2019-07-25" --no-merges \
| grep -oP "commit\s.+" | sed 's/commit /./g' | tr "\n" "." | sed 's/^.//g' | sed 's/.$//g'
```

Using this shell command, We will the commits, split by `..`, Like following:
`f560394908449057afa7e200a85052c26a58b181..aab71d9ac104cd1513fe5ac55de28211ec807c8e..be22dbb41a7ea4bc8aac147023645638f0777f3d`.

### Step2

Using git command `git cherry-pick`, pick the commits string.

```bash
git cherry-pick $(git log --author="phantom\|ydl" \
--after="2019-07-23" \
--before="2019-07-25" --no-merges \
| grep -oP "commit\s.+" | sed 's/commit /./g' | tr "\n" "." | sed 's/^.//g' | sed 's/.$//g')
```

Maybe we need to deal with the conflict between commits, and add a new commit, push to the new branch.

### Reference

1. [Git Offical Document git cherry-pick](https://git-scm.com/docs/git-cherry-pick)
2. [Git Offical Document git log](https://git-scm.com/docs/git-log) 查看全部

### We will use the following git command:

#### git log

#### git cherry-pick

> git-log - Show commit logs

```bash
git log [] [] [[--] …​]
```

1. `--author` match the author
2. `--after` after this time's commits
3. `--before` before this time's commits
4. `--no-merges` filter the merge commits

The official's introductions

> git-cherry-pick - Apply the changes introduced by some existing commits

```bash
git cherry-pick [--edit] [-n] [-m parent-number] [-s] [-x] [--ff]
[-S[]] …​
git cherry-pick --continue
git cherry-pick --quit
git cherry-pick --abort
```

### Step 1

Get all git commits, which you want to merge to a new branch. Then, we will use the git command `git cherry-pick` to do combine.

```bash
git log --author="phantom\|ydl" \
--after="2019-07-23" \
--before="2019-07-25" --no-merges \
| grep -oP "commit\s.+" | sed 's/commit /./g' | tr "\n" "." | sed 's/^.//g' | sed 's/.$//g'
```

Using this shell command, We will the commits, split by `..`, Like following:
`f560394908449057afa7e200a85052c26a58b181..aab71d9ac104cd1513fe5ac55de28211ec807c8e..be22dbb41a7ea4bc8aac147023645638f0777f3d`.

### Step2

Using git command `git cherry-pick`, pick the commits string.

```bash
git cherry-pick $(git log --author="phantom\|ydl" \
--after="2019-07-23" \
--before="2019-07-25" --no-merges \
| grep -oP "commit\s.+" | sed 's/commit /./g' | tr "\n" "." | sed 's/^.//g' | sed 's/.$//g')
```

Maybe we need to deal with the conflict between commits, and add a new commit, push to the new branch.

### Reference

1. [Git Offical Document git cherry-pick](https://git-scm.com/docs/git-cherry-pick)
2. [Git Offical Document git log](https://git-scm.com/docs/git-log)

Some tips, better use of Vim

网站管理员 Published the article • 0 comments • 259 views • 2019-04-17 11:07 • 来自相关话题

### Directory is not exist?

```bash
Command Control + Z, run vim background, and user command mkdir to create this directory
```

### No permission to create this file, or edit it?

```
# ESC
:w !sudo tee % >/dev/null
```

And then, your need to choice ```Ok``` or ```Load```, after your choice, the file mode will be readonly. don't feel fear, your can use command above 查看全部
### Directory is not exist?

```bash
Command Control + Z, run vim background, and user command mkdir to create this directory
```

### No permission to create this file, or edit it?

```
# ESC
:w !sudo tee % >/dev/null
```

And then, your need to choice ```Ok``` or ```Load```, after your choice, the file mode will be readonly. don't feel fear, your can use command above

It is required that your private key files are NOT accessible by others

网站管理员 Published the article • 0 comments • 355 views • 2019-04-09 10:55 • 来自相关话题

```
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/root/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/root/.ssh/id_rsa": bad permissions
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
```

### Solution

权限```0644```对于文件```~/.ssh/id_rsa```太开放了。

```bash
chmod 600 ~/.ssh/id_rsa ~/.ssh/id_rsa.pub
``` 查看全部
```
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/root/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/root/.ssh/id_rsa": bad permissions
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
```

### Solution

权限```0644```对于文件```~/.ssh/id_rsa```太开放了。

```bash
chmod 600 ~/.ssh/id_rsa ~/.ssh/id_rsa.pub
```

为什么用Charles配置了ssl证书还是抓不到https的包呢?

网站管理员 Published the article • 0 comments • 393 views • 2019-04-04 14:50 • 来自相关话题

### 背景

像往常一样,我在电脑端安装了ssl证书,然后手机端了下载了```chls.pro/ssl```的描述文件,且安装。但是依旧抓不到https包。

>
> iOS devices
> * Set your iOS device to use Charles as its HTTP proxy in the Settings app > Wifi settings.
> * Open Safari and browse to https://chls.pro/ssl. Safari will prompt you to install the SSL certificate.
> * If you are on iOS 10.3 or later, open the Settings.app and navigate to General > About > Certificate Trust Settings, and find the Charles Proxy certificate, and switch it on to enable full trust for it (More information about this change in iOS 10).
Now you should be able to access SSL websites with Charles using SSL Proxying.

### 出现问题的原因

1. 问题出现在第三点上,在iOS 10.3之后,我们需要在设置里```信任证书```

> 设置>通用>关于本机>信任证书设置(最下面)>信任对应的证书

### 总结

1. 如果你使用python的```mitmproxy```安装了证书,也抓不到https的包,那么处理方法也是这样的。 查看全部
### 背景

像往常一样,我在电脑端安装了ssl证书,然后手机端了下载了```chls.pro/ssl```的描述文件,且安装。但是依旧抓不到https包。

>
> iOS devices
> * Set your iOS device to use Charles as its HTTP proxy in the Settings app > Wifi settings.
> * Open Safari and browse to https://chls.pro/ssl. Safari will prompt you to install the SSL certificate.
> * If you are on iOS 10.3 or later, open the Settings.app and navigate to General > About > Certificate Trust Settings, and find the Charles Proxy certificate, and switch it on to enable full trust for it (More information about this change in iOS 10).
Now you should be able to access SSL websites with Charles using SSL Proxying.

### 出现问题的原因

1. 问题出现在第三点上,在iOS 10.3之后,我们需要在设置里```信任证书```

> 设置>通用>关于本机>信任证书设置(最下面)>信任对应的证书

### 总结

1. 如果你使用python的```mitmproxy```安装了证书,也抓不到https的包,那么处理方法也是这样的。

How to write a file, which named CMakeLists.txt,and build c-lang program with libevent

网站管理员 Published the article • 0 comments • 131 views • 2019-04-02 08:57 • 来自相关话题

I want to write a libevent c-lang program on the IDE clion, so I need to write a file, which named CMakeLists.txt to build this program.

### My program source code
```c

#include
#include
#include
#include
#include

#include
#include
#include

struct event ev;
struct timeval tv;

void time_cb(int fd, short event, void *argc) {
printf("timer wakeup\n");
event_add(&ev, &tv);
}

int main(int argc, char* argv[]) {
struct event_base *base = event_base_new();
tv.tv_sec = 10;
tv.tv_usec = 0;
event_assign(&ev, base, -1, 0, time_cb, NULL);
event_add(&ev, &tv);
event_base_dispatch(base);
}
```

### The CMakeLists.txt content
```
cmake_minimum_required(VERSION 3.12)
project(test)

set(CMAKE_CXX_STANDARD 98)

include_directories(/usr/local/Cellar/libevent/2.1.8/include/)
link_directories(/usr/local/Cellar/libevent/2.1.8/lib/)
add_executable(test a.c)
target_link_libraries(test event)
```
> used the function link_directions load the libraries, and use function target_link_libraries to link levent 查看全部

I want to write a libevent c-lang program on the IDE clion, so I need to write a file, which named CMakeLists.txt to build this program.

### My program source code
```c

#include
#include
#include
#include
#include

#include
#include
#include

struct event ev;
struct timeval tv;

void time_cb(int fd, short event, void *argc) {
printf("timer wakeup\n");
event_add(&ev, &tv);
}

int main(int argc, char* argv[]) {
struct event_base *base = event_base_new();
tv.tv_sec = 10;
tv.tv_usec = 0;
event_assign(&ev, base, -1, 0, time_cb, NULL);
event_add(&ev, &tv);
event_base_dispatch(base);
}
```

### The CMakeLists.txt content
```
cmake_minimum_required(VERSION 3.12)
project(test)

set(CMAKE_CXX_STANDARD 98)

include_directories(/usr/local/Cellar/libevent/2.1.8/include/)
link_directories(/usr/local/Cellar/libevent/2.1.8/lib/)
add_executable(test a.c)
target_link_libraries(test event)
```
> used the function link_directions load the libraries, and use function target_link_libraries to link levent

git的文件模式曾困扰了我

网站管理员 Published the article • 0 comments • 198 views • 2019-02-21 15:29 • 来自相关话题

当我为git里的某个文件建立软链的时候,文件模式从100644变成了120000,我起初以为是我的权限问题,导致文件的权限也发生了变化,

翻阅git的资料得知:
文件模式为 100644,表明这是一个普通文件,
其他可用的模式有:100755 表示可执行文件,
120000 表示符号链接。

文件模式是从常规的 UNIX 文件模式中参考来的,但是没有那么灵活 ── 上述三种模式仅对 Git 中的文件 (blobs) 有效 (虽然也有其他模式用于目录和子模块)。 查看全部

当我为git里的某个文件建立软链的时候,文件模式从100644变成了120000,我起初以为是我的权限问题,导致文件的权限也发生了变化,

翻阅git的资料得知:
文件模式为 100644,表明这是一个普通文件,
其他可用的模式有:100755 表示可执行文件,
120000 表示符号链接。

文件模式是从常规的 UNIX 文件模式中参考来的,但是没有那么灵活 ── 上述三种模式仅对 Git 中的文件 (blobs) 有效 (虽然也有其他模式用于目录和子模块)。

how to solve the command mv warning directory not empty, when target is directory?

网站管理员 Published the article • 0 comments • 183 views • 2019-02-14 12:57 • 来自相关话题

I get error ```mv: cannot move '/vendor/bin' to 'vendor/bin': Directory not empty```, when i used command ```mv``` on linux.
This problem is the direcotry is not empty, if your want overwrite it, you must add param ```-f``` or ```--force```.

### How to view the help of command ```mv```?

```bash
man mv
# or
mv --help
``` 查看全部

I get error ```mv: cannot move '/vendor/bin' to 'vendor/bin': Directory not empty```, when i used command ```mv``` on linux.
This problem is the direcotry is not empty, if your want overwrite it, you must add param ```-f``` or ```--force```.

### How to view the help of command ```mv```?

```bash
man mv
# or
mv --help
```

vim如何进行无格式化粘贴,苦恼:每次在vim内粘贴文本格式都会变乱

网站管理员 Published the article • 0 comments • 236 views • 2018-11-21 16:06 • 来自相关话题

### 解决vim内文本粘贴格式变乱的问题?

### 解决方案
输入```:set paste```即可,然后再粘贴进去,就不会出现文本混乱的问题了。

```bash
vim docker-compose.yml

:set paste
```

### 解决vim内文本粘贴格式变乱的问题?

### 解决方案
输入```:set paste```即可,然后再粘贴进去,就不会出现文本混乱的问题了。

```bash
vim docker-compose.yml

:set paste
```

如何快速获取一个网站的HTML页面源码wget之爬虫系列

网站管理员 Published the article • 0 comments • 280 views • 2018-10-31 17:42 • 来自相关话题

其实使用wget获取整个网站的源代码其实用wget就可以,而且一个命令就可以解决,爬取页面十分的快

```bash
mkdir -p wingman
wget -c -r -npH -k wingman.mediumra.re
```

### 如何去掉字体font后面的get参数
```bash
cd assets/fonts
for i in `ls .`; do echo ${i}; mv ${i} `echo ${i} | sed 's/?.*$//g'`; done
```

是不是十分的简单 查看全部

其实使用wget获取整个网站的源代码其实用wget就可以,而且一个命令就可以解决,爬取页面十分的快

```bash
mkdir -p wingman
wget -c -r -npH -k wingman.mediumra.re
```

### 如何去掉字体font后面的get参数
```bash
cd assets/fonts
for i in `ls .`; do echo ${i}; mv ${i} `echo ${i} | sed 's/?.*$//g'`; done
```

是不是十分的简单