諸多生活和工作中的瑣事,都可以用命令行和腳本化來搞定, 我們常用的 Shell, Python, ruby, groovy 甚至 JavaScript 都是很好的膠水代碼,以及其他curl,fabric ,scons,以及 scapy 等工具都可以加以利用
在寫文檔,畫圖和設(shè)計(jì)方面也是如此, 列舉如下:
用 Markdown 來寫文檔
這個(gè)不多說, 簡(jiǎn)書就支持 markdown, 這篇小文也是用 markdown 寫的
比如我在學(xué) docker 的時(shí)候,打印了一個(gè)速查手冊(cè),就是用如下命令生成文檔的
$ echo "| command| description | example |" > docker_manual.md
$ echo "|---|---|---|" >> docker_manual.md
$ docker help|grep -E "^[ ]+.+[ ]+.+$" | awk '{ a = $1; $1 = ""; print "| " a " | " $0 " | |"}' >> docker_manual.md ????
馬上就生成了如下的表格, 我填了一個(gè)常用命令的例子, 一個(gè)速查手冊(cè)就搞定了
| command | description | example |
|---|---|---|
| checkpoint | Manage checkpoints | |
| container | Manage containers | |
| image | Manage images | |
| network | Manage networks | |
| node | Manage Swarm nodes | |
| plugin | Manage plugins | |
| secret | Manage Docker secrets | |
| service | Manage services | |
| stack | Manage Docker stacks | |
| swarm | Manage Swarm | |
| system | Manage Docker | |
| volume | Manage volumes | |
| attach | Attach to a running container | |
| build | Build an image from a Dockerfile | |
| commit | Create a new image from a container's changes | |
| cp | Copy files/folders between a container and the local filesystem | |
| create | Create a new container | |
| deploy | Deploy a new stack or update an existing stack | |
| diff | Inspect changes to files or directories on a container's filesystem | |
| events | Get real time events from the server | |
| exec | Run a command in a running container | |
| export | Export a container's filesystem as a tar archive | |
| history | Show the history of an image | |
| images | List images | |
| import | Import the contents from a tarball to create a filesystem image | |
| info | Display system-wide information | |
| inspect | Return low-level information on Docker objects | |
| kill | Kill one or more running containers | |
| load | Load an image from a tar archive or STDIN | |
| login | Log in to a Docker registry | |
| logout | Log out from a Docker registry | |
| logs | Fetch the logs of a container | |
| pause | Pause all processes within one or more containers | |
| port | List port mappings or a specific mapping for the container | |
| ps | List containers | |
| pull | Pull an image or a repository from a registry | |
| push | Push an image or a repository to a registry | |
| rename | Rename a container | |
| restart | Restart one or more containers | |
| rm | Remove one or more containers | |
| rmi | Remove one or more images | |
| run | Run a command in a new container | |
| save | Save one or more images to a tar archive (streamed to STDOUT by default) | |
| search | Search the Docker Hub for images | |
| start | Start one or more stopped containers | |
| stats | Display a live stream of container(s) resource usage statistics | |
| stop | Stop one or more running containers | |
| tag | Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE | |
| top | Display the running processes of a container | |
| unpause | Unpause all processes within one or more containers | |
| update | Update configuration of one or more containers | |
| version | Show the Docker version information | |
| wait | Block until one or more containers stop, then print their exit codes |
用 plantuml, websequence 來畫圖
plantuml
用 plantuml 可以畫大多數(shù)的 UML 圖
- 它依賴于 graphviz, 所以先安裝依賴包
brew install libtool
brew install graphviz
- 再?gòu)?http://plantuml.com 下載 plantuml.jar
- 然后寫一個(gè)python 文件封裝一下使用方法
- drawuml.py
import sys,os
def draw_uml(script_file):
print "draw %s" % script_file
cmd = "java -jar plantuml.jar %s" % script_file
print cmd
os.system(cmd)
if __name__ == "__main__":
argc = len(sys.argv)
if( argc > 1):
script_file = sys.argv[1]
draw_uml(script_file)
else:
print "Usage: python {0} <uml_script_file>".format(sys.argv[0])
- 再寫一個(gè) uml 腳本來生成一個(gè)活動(dòng)圖
- activity_example.txt
@startuml
start
:host_start_meeting;
:attendee_join_meeting;
:host_mute_attendee;
:check_attendee_client_screen;
if (Is there "Your audio has been muted"?) then (yes)
:assert pass;
else (no)
:assert error;
endif
:host_end_meeting;
stop
@enduml
- 使用方法
$ python drawuml.py activity_example.txt
draw activity_example.txt
java -jar plantuml.jar activity_example.txt
$ open activity_example.png

activity example
Websequence
https://www.websequencediagrams.com/ 這個(gè)網(wǎng)站幾乎搞定了我所有的序列圖

image.png
腳本如下:
title WebRTC and SIP Interaction
participant Browser as browser
participant WebServer as server
participant SIP Proxy as proxy
participant SIP UA as ua
autonumber
browser->server: HTTPS GET
server-->browser: 200 OK
browser->server: WebSocket (SDP offer)
server->proxy: SIP Invite(SDP offer)
proxy->ua: SIP Invite (SDP offer)
ua-->proxy: SIP 200(SDP answer)
proxy-->server: SIP 200 (SDP answer)
server-->browser: WebSocket (SDP answer)
server->proxy: SIP ACK
proxy->ua: SIP ACK
note over browser,ua: ICE, SRTP
ua->proxy:SIP BYE
proxy->server: SIP BYE
server<->browser: WebSocket(close)
server-->proxy: SIP 200
其它
軟件開發(fā)中的編譯,部署,測(cè)試工作幾乎都可以通過腳本和命令行完成, 這是不做贅述
- Make
- cmake
- scons
- maven
部署
- Ansible
- Puppet
- fabric
測(cè)試與診斷
- cUrl
- Jmeter
- SIPp