vim 視窗分割

雖說 tmux 很好用,不過 vim 本身內建視窗切割功能了,好像沒必要因此開多個 shell 跟 vim 浪費記憶體,還是記一下 vim 常用的分割視窗指令:

開新水平視窗:
:new
開新垂直視窗:
:vnew

水平切割後開起現有或指定檔案:
:sp (split)
垂直切割後開起現有或指定檔案:
:vsp (vsplit)
這兩個命令後面接檔名(記得前面要一個空格)會直接打開對應的檔案~

另外 vim 的分割視窗操作預設 hot key 是 Ctrl + w, 也可以用熱鍵來操作:

水平切割視窗:
<Hot key> s
垂直切割視窗:
<Hot key> v

在分割視窗之間切換/移動焦點(游標):
<Hot key> k  或  <Hot key> ↑
<Hot key> j  或  <Hot key> ↓
<Hot key> h  或  <Hot key> ←
<Hot key> l  或  <Hot key> →
(把英文字母改成大寫則可移動到最上最下最左最右)

把目前的分割視窗加大:
<Hot key> +
把目前的分割視窗縮小:
<Hot key> –
把目前同一行/列的分割視窗高/寬平均:
<Hot key> =
把目前的分割視窗放到最大(寬or高):
<Hot key> _
<Hot key> |
把目前的分割視窗用一個新的分頁(tab)開啟:
<Hot key> T

要強迫自己習慣一下~

How to setup and deploy ssh keys under linux?

Not a hard working, and there are already many articles talk about that, but many students still don’t know how to do that …

The simple syntax for generating ssh key pair:
$ ssh-keygen -t algorithm -b bits -C "comments"

For example:
$ ssh-keygen -t rsa -b 4096 -C "my first ssh key pair!"

The simple syntax for deploying ssh key:
$ ssh-copy-id [email protected]

For example:
$ ssh-copy-id [email protected]

If you also have problems with ssh keys, I will suggest you to read the articles below, they are confirmed by myself, I think those are correct and easy versions, and there is no need to write them in my blog again …

3 good articles should be enough …

How to sync/update forked git repository with upstream?

中文版: https://www.peterdavehello.org/2014/02/update_forked_repository/

I found the origin post in Chinese is more popular among all the posts, so just rewrite it in English now :)

Once you forked a repository on GitHub, the commit history from the upstream will stay at the moment you forked it, sometimes we’ll need to update it, so that the parent of our commit won’t be so old, which can help us have a better look, easier to trace git commit history, and prevent some potential or known conflicts, maybe you have other reasons, anyway. This method can also sync a repository between different git servers.

NOTE:
If you forked repository is behind the upstream repository for more than 1k commits and the repository is fat, you can consider to delete your forked repository and re-fork the origin one, it may be faster and more efficient.

Let’s start it.

First, if you didn’t have the repository locally, you have to clone the forked repository to local, you can set the clone depth to save the bandwidth and disk space usage:
$ git clone --depth 1 https://github.com/user/repo.git

(Replace the url to your forked repository)

Once you cloned it, check its ‘remote’, usually you’ll get only one remote after clone, like this:
$ git remote -v
origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)

Now we should add another ‘remote’ – the origin upstream, so that we can pull the updates from, in this case, use read-only git protocol will be faster, more efficient (but note that some firewall may not allow that protocol, so you’ll need to use https in that case):
$ git remote add upstream git://github.com/otheruser/upstreamRepo.git

PS: ‘upstream’ is the name I gave it, you can give it another name as you want.

To verify new added remote, let’s check it again, you should have two remotes now:

origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)
upstream git://github.com/otheruser/upstreamRepo.git (fetch)
upstream git://github.com/otheruser/upstreamRepo.git (push)

Now we can start the “update” works, I assume the branch you’re going to update is the master branch, if you are going to update a non-master branch, just checkout to the branch you want, but don’t forget to change the branch from the below examples!

If your branch is only behind the upstream, no any “ahead” commits(which means you didn’t commit any new things on the same branch came from upstream), you can directly pull the updates from upstream:
$ git pull upstream master

If your branch also contains your own commits, you should better pull with “–rebase” parameter:
$ git pull --rebase upstream master

Now, almost done, if there is no error or conflicts(we don’t discuss conflicts here), push your master to origin remote, then you’ll found that your forked repo is fresh again:
$ git push origin master

Remotely shutdown/restart Windows via Linux on Debian/Ubuntu based Linux

Need samba-common package first, install via apt:

$ sudo apt-get install samba-common

Then use this command to shutdown the computer remotely(replace ip, username and password with your own):

$ net rpc shutdown --ipaddress ip --user username%password

Add -r if you want to restart, not shutdown:

$ net rpc shutdown -r --ipaddress ip --user username%password

After execution, here is the success message:

Shutdown of remote machine succeeded

If receive these messages below means something failed:

Could not connect to server 192.168.1.55
Connection failed: NT_STATUS_IO_TIMEOUT
Connection failed: NT_STATUS_RESOURCE_NAME_NOT_FOUND
Could not initialise pipe winreg. Error was NT_STATUS_OBJECT_NAME_NOT_FOUND

There are many functions provide by net [rpc], like:

net rpc audit Modify global audit settings
net rpc info Show basic info about a domain
net rpc join Join a domain
net rpc oldjoin Join a domain created in server manager
net rpc testjoin Test that a join is valid
net rpc user List/modify users
net rpc password Change a user password
net rpc group List/modify groups
net rpc share List/modify shares
net rpc file List open files
net rpc printer List/modify printers
net rpc changetrustpw Change trust account password
net rpc trustdom Modify domain trusts
net rpc abortshutdown Abort a remote shutdown
net rpc shutdown Shutdown a remote server
net rpc samdump Dump SAM data of remote NT PDC
net rpc vampire Sync a remote NT PDC’s data into local passdb
net rpc getsid Fetch the domain sid into local secrets.tdb
net rpc rights Manage privileges assigned to SID
net rpc service Start/stop/query remote services
net rpc registry Manage registry hives
net rpc shell Open interactive shell on remote server
net rpc trust Manage trusts
net rpc conf Configure a remote samba server

Check man rpc for more details!