-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtricks.txt
222 lines (212 loc) · 8.88 KB
/
tricks.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
There is a website built for cheatsheet https://devhints.io/, I may want to build one for myself.
# Node
# Easy way to update the node.js
$ npm install -g n
$ n stable
# npm global install location on OSX: /usr/local/share/npm
# Use taobao image to help speed up the npm install
$ npm install --registry=https://registry.npm.taobao.org
# check the installed npm package version
$ npm view <package name> version
# Short key for WebStorm
Alt+F12: internal terminal
Ctrl+shift+F10: Run the code
# Webstorm tricks
# split edit view: right click the doc tab and choose split
# Find in Path
ctrl+shift+F
# Replace all
cmd + R
# Docker
# check images
$ docker images
# check containers
docker ps
# -a means all, -l means the last run container
# rm docker image by image_id
$ docker rmi <image_id>
# rm all docker containers
$ docker rm -f $(docker ps -aq)
# -f: force, -a: all, -q: quiet(only show the id part)
# speed up docker pull if u r in China: https://www.docker-cn.com/registry-mirror
# example: just add registry.docker-cn.com before the image
$ docker pull registry.docker-cn.com/library/ubuntu:16.04
# If u r using ubuntu, to download from China image website for good, open /etc/default/docker and add a line at the end of the file
DOCKER_OPTS="--registry-mirror=https://registry.docker-cn.com"
# reboot the Docker service
$ sudo service docker restart
# enter running docker container
$ docker exec -it <name> /bin/bash
# if there is no parameter -it during "docker run", we need use cmd above to enter the container
# read docker logs
$ docker log -f
$ docker logs <container name>
# remove
# docker image
$ docker rmi <image1> <image2>
# docker container
$ docker rm <container>
# all the currently-running containers:
$ docker rm -f $(docker ps -aq)
# docker volumes
$ docker volume ls # check the list of volumes
$ docker volume rm <volume_name>
# stop docker container
$ docker container stop <docker container id>
# start the container
$ docker start <docker container id>
# diff from "docker run" which will build a new container every time, the docker start will only work on the existing one
# for the running docker containe, restart
$ docker restart <container id>
# rename the docker image
$ docker tag oldrepo:tag newrepo:tag
# remove the old name if u want
$ docker rmi oldrepo
# check the logs
$ docker logs -f <container id>
# when docker is running the container and there is -it for entering the container, we need this command to check the output
# check the process in docker
$ docker top <container id>
# Build the docker image
# method 1: update the existing image
# First run a container based on the existing image
$ docker run -t -i ubuntu:16.04 /bin/bash
# Then run the update command inside the running container
$ apt-get update
# exit the container and commit the update version
$ docker commit -m="some messge" -a="author name" <container id> repo:tag
# method 2: build the docker image from the ground
# basically we need a Dockerfile, check how to write a Dockerfile by yourself
# copy the file from a running Docker container to local host
$ docker container cp <container ID>:</path/to/file>
# if something like "permission denied" in docker, add the current user to the docker group, log out and log back install
sudo usermod -a -G docker $USER
# save docker image
$ docker save -o <filename>.tar <image_name>:version
# load docker image
$ docker load < <filename>.tar
# check all the containers whose image name contains <string> and just print out the container ID
$ docker ps -a | awk '$2~/<string>/ {print $1}'
# check all the docker images whose repo starts with <string> and just print out the image ID
docker images | grep "^<string>" | awk '{print $3}'
# assign the work permission for work
$ sudo groupadd docker # add the docker group if it doesn't exist
$ sudo gpasswd -a $USER docker # add the $USER to group
$ systemctl restart docker $ restart the docker to activate the settin
# change the default setting for storing the docker image and container data
config the /etc/docker/daemon.json or /usr/lib/systemd/system/docker.service fileg
# copy files from docker container to host
docker cp <container ID>:/file/path/within/container /host/path
# Vim
# go to the end of file
shift+g
# go to the beginning of the file
press g twice
# move to the end of line
$(the last empty), A(it's like $ + i), g_(jump to last non blank)
# move to the beginning
^ or _(move to the first non-whitespace char in the line), | or 0(zero)(move a little bit ahead of ^ or _)
# to search a string
/<target_string>
# press n to go to next matched string, press N to go to the previous string
# search from the end of the files
?<target_string>
# disable highlights at other files
:noh
# comment multiple line at once
# move the cursor to the first char of the first line in block code you want to comment and type "CTRL+V" to enter VISUAL BLOCK mode
# CTRL+V
# use down arrow button or j button to move the cursor down until you reach the last line of the code block
# move cursor down
# Then type the below key to enter INSERT mode
# shift+I
# type # or the character for commenting for the certain language
# type #
# click ESC and done
# check the fileformat
$ set ff
# set the fileformat
$ set ff=unix OR dos
# shell command
# delete all files in current directory and its sub-directories where the file name starts with "foo"
$ find . -type f -name foo\* -exec rm {} \;
$ grep -R -i "<foo>" *
# check the port being used
$ sudo lsof -i tcp:<port number>
# to run the program at the background, first ctrl+z
$ bg
$ fg # put it front again and we can kill it by press ctrl+c
# to send a post request
$ curl -i http://localhost:3000/users -d "name=test"
# change the environment variables for mac
$ vim ~/.bash_profile
# change the file or directory role from root to work
$ chown work: <filename or directory>
# pack the file using tar
$ tar -zcvf <>.tar.gz <dir_name>/
# To unpack a tar file
$ tar -xvzf filename.tar.gz
# send GET request to API
$ curl <ip_address>:<port>/<api>
# change the usermode from root to work
$ su - work
# command for secureCRT
$ rz # upload file
$ sz -e <filename> # download file
# go to option/Session Option/\X/Y/Zmodem\ to configure the download path
# find which file include the string under this folder
$ grep -nr '<string>*' .
# list all fiiles in the current directory staring with <string>
$ find . -name <string>\*
# the previous command
$ !! OR $ !-1
# the most recent input that starts with "mak"
$ !mak
# use the last term from the previous input
!$ # from 'ls /some/path', !$ = /home/path
# get the 2nd row, 2nd column from the command output
$ <command> | sed -n '2p' | awk '{print $2}'
# notes: it may be quite useful to kill the process. 'sed' and 'awk' are really useful in text manipulation.
# example: kill the process which is using the port 1081
$ kill $(lsof -i tcp:1081 | sed -n '2p' | awk '{print $2}')
# list the files w/ size under this directory
$ ll --block-size=M
# count how much lines the file contains
$ wc -l <filename>
# check the hostname
$ hostname
# check whoami
$ whoami
# check who is using the machine
$ w
# check what they are doing
$ top
# check the connection for certain port
netstat -ant | grep -i "port"
# shell if statements
# check if the first arg is an empty string, where ! means 'not', -z meanns empty
if [! -z $1]; then
# IntelliJ IDEA
1. To open any class in the editor quickly, press ⌘O (Navigate | Class) and start typing the name of the class. Choose the class from a drop-down list that appears.
2. The Code Completion feature lets you quickly complete different kinds of statements in the code. For example, start typing a class name and press ⌃Space to complete it. When multiple choices are available, they are shown in the lookup list.
3. To navigate to the declaration of a class, method or variable used somewhere in the code, position the caret at the usage and press ⌘B (Navigate | Declaration). You can also click the mouse on usages with the Ctrl key pressed to jump to declarations.
4. You can quickly navigate in the currently edited file with ⌘F12 (Navigate | File Structure).
It shows the list of members of the current class. Select an element you want to navigate to and press the Enter key or the ⌘↓ key.
To easily locate an item in the list, just start typing its name.
# generate getters and setters quickly for JAVA
right click and choose generate(OR cmd+N) ---> set getter and setter ---> select member variables ---> click ok
# Linux system
# check the number of cpus
$ lscpu
# test network connection: telnet
$ telnet <address> <port>
# fabric
# add the chaincode project under gopath using soft link
$ cd $GOPATH/src/github.com/hyperledger && ln - s <chaincode dir path>
# install the chaincode dependency
$ cd $GOPATH/src/github.com/hyperledger/<chaincode dir path> && goverdor sync
# test the chaincode
$ go test
# tools
## Node
### nrm to change the source