0%

开发利器之PyCharm

在没有遇到Jetbrains的开发套件之前,其实我是犹豫的,比如我会用着成为利器之神的VIM,然后成为神之利器的Emacs,偶尔在用下号称编码人员最爱的Sublime,直到遇到Jetbrains开发套件,套不犹豫地购买License,开始徜徉在Jetbrains的海洋中,云淡风轻,与世无争。

悄悄告诉你一件事情,其实有些套件是有Community版本的,没有License的限制,但是相应地功能也会少一些,可以先试用,感觉性价比可以了在购买。

为什么呢,因为Jetbrains各个系列都拥有高度一致的开发GUI,集成了VIM,让我效率很高,集成了Git,让我在一个开发环境中可以完成需要切换N个终端才能完成的事情,还有自动代码格式化,代码完成、重构,等等。

待我细细讲来。

先来个预览吧,

screenshot

Pycharm

Pycharm特点

如所有其它 JetBrains 集成开发环境一样,PyCharm 具有智能代码编辑器,能理解 Python 的特性并提供卓越的生产力推进工具:自动代码格式化、代码完成、重构、自动导入和一键代码导航等。这些功能在先进代码分析程序的支持下,使 PyCharm 成为 Python 专业开发人员和刚起步人员使用的有力工具。

这些够了吗,这些还不够,还有:

  • 针对 Django 开发的高级支持,包括智能代码完成、检查、重构和特定代码导航
  • 综合 Python 调试器和图形单元测试工具
  • 支持先进 Python 开发工具链,包括 virtualenv 和 buildout
  • 版本控制系统整合——针对 Mercurial、Git、SVN、Perforce 和 CVS 等大多数版本控制系统的统一用户界面 (UI)
  • Google App Engine 支持,能到 App Engine 服务器上运行和部署用户的应用,同时确保代码满足沙盒环境需求
  • REPL 和 Django 控制台,具备胜过标准控制台的众多优势:运行中语法检查;括号和引号匹配和自动配对;以及代码完成。
  • 还有跨平台,通杀三大主流平台Windows,MacOSX和Linux,当然我觉得MacOSX上吗的体验最好。

Pycharm快捷键

调出快捷键的方法很简单,入下图所示:

shortcut

列出的快捷键如下面所示:

shortcut-all

其实我们用到的快捷键远远没有那么多啦,不过作为一个辣么牛的编辑器,一句话,别人可以不用,但是你不能没有,意思就是:

有没有是你的态度,用不用是我的权利。

这一点标明Jetbrains的态度那是杠杠滴OK。

用到的快捷键就那下面几个,一一说来。

代码基本完成快捷键

这个功能但凡能存活到现在的编辑器,都会具有这个功能,就是看代码完成的效率问题了。

这里有一个比较悲催的事情,就是Jetbrains默认的快捷键总是会跟输入法切换键有冲突,所以这个是我们需要比较注意的,我们需要改变这个快捷键,如何修改参考下面的修改默认快捷键,因为默认的快捷键比较多,可以在搜索区域输入basic即可。不要用你使用最多的键,比如可以改为**Ctrl + ,**,这个目前看来还没有跟其他什么主流软件有冲突,所以培养用户的习惯还是很重要的。

其实这个功能我用的不是特别多,这是为什么呢,因为在你输入的过程中,Jetbrains已经会比较快捷方便地给你提示了。如下所示:

hello

霸气的TAB

如果在Linux里面你还是照旧所有的字符都输入进入,我只能说佩服,还有不屑,因为在节省时间的问题上,为什么不用下Tab键呢?

Jetbrains也有这个很好的传统,有两种情况:

  1. 当你什么也没有输入的时候,Tab默认是4个空格的缩进
  2. 但是当你输入前几个字母的时候,Jetbrains会智能地列出所有的候选项,这时候你只要按下Tab,就会默认选择第一个候选项,这对于双手不离开键盘而言,是很好的提高输入速度,以及保证流畅思考编程的一个小技巧。

Shift+Enter 智能换行

如果鼠标位于class function():的任何一个位置,此时(ˇˍˇ) 想~写下一行代码了,小case,直接Shift+Enter切换到下一行正确的位置写代码即可。

修改默认快捷键

打开Preference,或者快捷栏中看起来像扳手的tool图标,会打开如下所示的界面,在左侧中选择keymap即可。

keymap

PyCharm插件

如何安装插件

同样跟修改快捷键一样,这次要找的是Plugins,顺便力推几个插件。

plugin

VIM插件

效果就是PyCharm的编辑器就是一个VIM开启的终端,各种赞。

顺便提供一个vim的快捷键,供参考。

vim

支持Markdown

写作如果现在你还在用富文本编辑器,估计会被鄙视的,高大上一点,最重要的是有效率一点,那就妥妥滴Markdown吧,会自动解析Markdown的各种标记。

markdown

支持Docker

我下载了一个docker,打开工程的时候,会提示:

docker

Debian 镜像更新源

镜像更新源做的比较好的有网易163、阿里云还有中科大。

方法为编辑/etc/apt/sources.list文件,替换为下述内容即可。

最好做好备份。

网易提供的源

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
## Jessie

deb http://mirrors.163.com/debian/ jessie main non-free contrib
deb http://mirrors.163.com/debian/ jessie-updates main non-free contrib
deb http://mirrors.163.com/debian/ jessie-backports main non-free contrib
deb-src http://mirrors.163.com/debian/ jessie main non-free contrib
deb-src http://mirrors.163.com/debian/ jessie-updates main non-free contrib
deb-src http://mirrors.163.com/debian/ jessie-backports main non-free contrib
deb http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib
deb-src http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib

# Wheezy

deb http://mirrors.163.com/debian/ wheezy main non-free contrib
deb http://mirrors.163.com/debian/ wheezy-updates main non-free contrib
deb http://mirrors.163.com/debian/ wheezy-backports main non-free contrib
deb-src http://mirrors.163.com/debian/ wheezy main non-free contrib
deb-src http://mirrors.163.com/debian/ wheezy-updates main non-free contrib
deb-src http://mirrors.163.com/debian/ wheezy-backports main non-free contrib
deb http://mirrors.163.com/debian-security/ wheezy/updates main non-free contrib
deb-src http://mirrors.163.com/debian-security/ wheezy/updates main non-free contrib

# Squeeze

deb http://mirrors.163.com/debian/ squeeze main non-free contrib
deb http://mirrors.163.com/debian/ squeeze-updates main non-free contrib
deb http://mirrors.163.com/debian/ squeeze-lts main non-free contrib
deb-src http://mirrors.163.com/debian/ squeeze main non-free contrib
deb-src http://mirrors.163.com/debian/ squeeze-updates main non-free contrib
deb-src http://mirrors.163.com/debian/ squeeze-lts main non-free contrib
deb http://mirrors.163.com/debian-security/ squeeze/updates main non-free contrib
deb-src http://mirrors.163.com/debian-security/ squeeze/updates main non-free contrib
deb http://mirrors.163.com/debian-backports/ squeeze-backports main contrib non-free
deb-src http://mirrors.163.com/debian-backports/ squeeze-backports main contrib non-free

如果163的无法更新,可以考虑使用中科大的源

中国科技大学源

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
#(1)squeeze版本

deb http://ftp.cn.debian.org/debian squeezemain

deb-src http://ftp.cn.debian.org/debiansqueeze main

deb http://ftp.cn.debian.org/debiansqueeze-updates main

deb-src http://ftp.cn.debian.org/debiansqueeze-updates main

debhttp://ftp.cn.debian.org/debian-backports squeeze-backports main

deb-srchttp://ftp.cn.debian.org/debian-backports squeeze-backports main

deb http://security.debian.org/squeeze/updates main

deb-src http://security.debian.org/squeeze/updates main

#或:

deb http://ftp.cn.debian.org/debian squeeze main non-free

deb-src http://ftp.cn.debian.org/debiansqueeze main non-free

deb http://ftp.cn.debian.org/debiansqueeze-updates main non-free

deb-src http://ftp.cn.debian.org/debiansqueeze-updates main non-free

debhttp://mirrors.ustc.edu.cn/debian-security/ squeeze/updates main non-free

deb-srchttp://mirrors.ustc.edu.cn/debian-security/ squeeze/updates main non-free



# wheezy版本

deb http://ftp.cn.debian.org/debian/ wheezy main contrib non-free

deb-src http://ftp.cn.debian.org/debian/ wheezy main contrib non-free



deb http://ftp.cn.debian.org/debian/ wheezy-proposed-updates main contrib non-free

deb-src http://ftp.cn.debian.org/debian/ wheezy-proposed-updates main contrib non-free



deb http://ftp.cn.debian.org/debian/ wheezy-backports main contrib non-free

deb-src http://ftp.cn.debian.org/debian/ wheezy-backports main contrib non-free



# jessie版本

deb http://ftp.cn.debian.org/debian/ jessiemain contrib non-free

deb-src http://ftp.cn.debian.org/debian/ jessiemain contrib non-free

deb http://ftp.cn.debian.org/debian/ jessie-proposed-updates main contrib non-free

deb-src http://ftp.cn.debian.org/debian/ jessie-proposed-updates main contrib non-free

deb-amd64http://ftp.cn.debian.org/debian-security jessie/updates main contrib non-free

阿里云的源

1
2
3
4
deb http://mirrors.aliyun.com/debian/ wheezy main non-free contrib
deb http://mirrors.aliyun.com/debian/ wheezy-proposed-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ wheezy main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ wheezy-proposed-updates main non-free contrib

对于Debian7.8的版本,被归档了,我试了一下只有下面的这个可以用

1
deb http://archive.debian.org/debian/ wheezy main contrib non-free

简介

sysctl命令用于运行时配置内核参数,这些参数位于/proc/sys目录下。sysctl配置与显示在/proc/sys目录中的内核参数.可以用sysctl来设置或重新设置联网功能,如IP转发、IP碎片去除以及源路由检查等。用户只需要编辑/etc/sysctl.conf文件,即可手工或自动执行由sysctl控制的功能。

命令格式

1
2
3
4
5
sysctl [-n] [-e] -w variable=value

sysctl [-n] [-e] -p <filename> (default /etc/sysctl.conf)

sysctl [-n] [-e] -a

命令参数

  • -w 临时改变某个指定参数的值,如 sysctl -w net.ipv4.ip_forward=1
  • -a 显示所有的系统参数
  • -p 从指定的文件加载系统参数,如不指定即从/etc/sysctl.conf中加载

使用范例:

如果仅仅是想临时改变某个系统参数的值,可以用两种方法来实现,例如想启用IP路由转发功能:

1
2
3
#echo 1 > /proc/sys/net/ipv4/ip_forward

#sysctl -w net.ipv4.ip_forward=1

以上两种方法都可能立即开启路由功能,但如果系统重启,或执行了

1
# service network restart

命令,所设置的值即会丢失,如果想永久保留配置,可以修改/etc/sysctl.conf文件将 net.ipv4.ip_forward=0改为net.ipv4.ip_forward=1

还有一种方法设置主机名

sysctl kernel.hostname

简介

Tmux是一个优秀的终端复用软件,类似GNU Screen,但来自于OpenBSD,采用BSD授权。
使用它最直观的好处就是,通过一个终端登录远程主机并运行tmux后,在其中可以开启多个控制台而无需再“浪费”多余的终端来连接这台远程主机;
是BSD实现的Screen替代品,相对于Screen,它更加先进:支持屏幕切分,而且具备丰富的命令行参数,使其可以灵活、动态的进行各种布局和操作。

功能

  • 提供了强劲的、易于使用的命令行界面。
  • 可横向和纵向分割窗口。
  • 窗格可以自由移动和调整大小,或直接利用四个预设布局之一。
  • 支持 UTF-8 编码及 256 色终端。
  • 可在多个缓冲区进行复制和粘贴。
  • 可通过交互式菜单来选择窗口、会话及客户端。
  • 支持跨窗口搜索。
  • 支持自动及手动锁定窗口。

使用

进入tmux面板后,一定要先按ctrl+b,然后松开,再按其他的组合键才生效。

新建会话

第一个启动的 Tmux 窗口,编号是0,第二个窗口的编号是1。
使用编号区分会话,不太直观,更好的方法是为会话起名。
使用下面的指令即可:

1
$ tmux new -s <session-name>

查看会话

查看当前所有的 Tmux 会话

1
2
3
$ tmux ls
# or
$ tmux list-session

分离会话

这个是最常用的方法了,按下Ctrl+b d或者输入tmux detach命令,就会将当前会话与窗口分离。
而此时会话里面的进程依然在后台执行。

参考查看会话来查看所有的会话。

接入会话

attach命令用于重新接入某个已存在的会话,可以通过编号或者会话名来接入

1
2
3
4
5
# 使用会话编号
$ tmux attach -t 0

# 使用会话名称
$ tmux attach -t <session-name>

杀死会话

可以通过tmux kill-session命令用于杀死某个会话,与attach类似,可以通过会话编号与session名来kill

1
2
3
4
5
# 使用会话编号
$ tmux kill-session -t 0

# 使用会话名称
$ tmux kill-session -t <session-name>

切换会话

tmux switch命令用于切换会话。

1
2
3
4
5
# 使用会话编号
$ tmux switch -t 0

# 使用会话名称
$ tmux switch -t <session-name>

重命名会话

tmux rename-session命令用于重命名会话。

1
$ tmux rename-session -t 0 <new-name>

上面命令将0号会话重命名。

最简操作流程

综上所述,以下是 Tmux 的最简操作流程。

  1. 新建会话tmux new -s session_name
  2. 在 Tmux 窗口运行所需的程序
  3. 按下快捷键Ctrl+b d将会话分离
  4. 下次使用时,重新连接到会话tmux attach-session -t session_name

窗格操作

Tmux 可以将窗口分成多个窗格(pane),每个窗格运行不同的命令。以下命令都是在 Tmux 窗口中执行。

划分窗格

tmux split-window命令用来划分窗格。

1
2
3
4
5
# 划分上下两个窗格
$ tmux split-window

# 划分左右两个窗格
$ tmux split-window -h

移动光标

tmux select-pane命令用来移动光标位置。

1
2
3
4
5
6
7
8
9
10
11
# 光标切换到上方窗格
$ tmux select-pane -U

# 光标切换到下方窗格
$ tmux select-pane -D

# 光标切换到左边窗格
$ tmux select-pane -L

# 光标切换到右边窗格
$ tmux select-pane -R

交换窗格位置

tmux swap-pane命令用来交换窗格位置。

1
2
3
4
5
# 当前窗格上移
$ tmux swap-pane -U

# 当前窗格下移
$ tmux swap-pane -D

窗口管理

除了将一个窗口划分成多个窗格,Tmux 也允许新建多个窗口。

新建窗口

tmux new-window命令用来创建新窗口。

1
2
3
4
$ tmux new-window

# 新建一个指定名称的窗口
$ tmux new-window -n <window-name>

切换窗口

tmux select-window命令用来切换窗口。

1
2
3
4
5
# 切换到指定编号的窗口
$ tmux select-window -t <window-number>

# 切换到指定名称的窗口
$ tmux select-window -t <window-name>

重命名窗口

tmux rename-window命令用于为当前窗口起名(或重命名)。

1
$ tmux rename-window <new-name>

七、其他命令
下面是一些其他命令。

列出所有快捷键,及其对应的 Tmux 命令

$ tmux list-keys

列出所有 Tmux 命令及其参数

$ tmux list-commands

列出当前所有 Tmux 会话的信息

$ tmux info

重新加载当前的 Tmux 配置

$ tmux source-file ~/.tmux.conf

常用到的几个组合键:

快捷键 说明
ctrl+b ? 显示快捷键帮助
ctrl+b 空格键 采用下一个内置布局,这个很有意思,在多屏时,用这个就会将多有屏幕竖着展示
Ctrl+b , 窗口重命名
ctrl+b ! 把当前窗口变为新窗口
ctrl+b “ 模向分隔窗口
ctrl+b % 纵向分隔窗口
Ctrl+b ; 光标切换到上一个窗格
Ctrl+b { 当前窗格与上一个窗格交换位置
Ctrl+b } 当前窗格与下一个窗格交换位置
ctrl+b 空格键 采用下一个内置布局,这个很有意思,在多屏时,用这个就会将多有屏幕竖着展示
ctrl+b ! 把当前窗口变为新窗口
ctrl+b “ 模向分隔窗口
ctrl+b % 纵向分隔窗口
ctrl+b q 显示分隔窗口的编号
ctrl+b o 跳到下一个分隔窗口。多屏之间的切换
ctrl+b 上下键 上一个及下一个分隔窗口
ctrl+b C-方向键 调整分隔窗口大小
ctrl+b & 确认后退出当前tmux
ctrl+b [ 复制模式,即将当前屏幕移到上一个的位置上,其他所有窗口都向前移动一个。
ctrl+b c 创建新窗口
ctrl+b d 脱离当前会话;这样可以暂时返回Shell界面,输入tmux attach能够重新进入之前的会话
ctrl+b n 选择下一个窗口
ctrl+b l 最后使用的窗口
Ctrl+b o 光标切换到下一个窗格
ctrl+b n 选择下一个窗口
ctrl+b l 最后使用的窗口
ctrl+b p 选择前一个窗口
ctrl+b w 以菜单方式显示及选择窗口
ctrl+b s 以菜单方式显示和选择会话。这个常用到,可以选择进入哪个tmux
ctrl+b t 显示时钟。然后按enter键后就会恢复到shell终端状态
Ctrl+b q 显示窗格编号
Ctrl+b x 关闭当前窗格
Ctrl+b z 当前窗格全屏显示,再使用一次会变回原来大小
Ctrl+b 光标切换到其他窗格。是指向要切换到的窗格的方向键,比如切换到下方窗格,就按方向键↓
Ctrl+b Ctrl+o 所有窗格向前移动一个位置,第一个窗格变成最后一个窗格
Ctrl+b Alt+o 所有窗格向后移动一个位置,最后一个窗格变成第一个窗格
Ctrl+b Ctrl+ 按箭头方向调整窗格大小
Ctrl+b 切换到指定编号的窗口,其中的是状态栏上的窗口编号

基本概念

tmux有三个基本概念:

  • 会话(Session)
  • 窗口(Window)
  • 面板(Pane)

窗格(Pane)操作

  • % 左右平分出两个窗格
  • “ 上下平分出两个窗格
  • x 关闭当前窗格
  • { 当前窗格前移
  • } 当前窗格后移
  • ; 选择上次使用的窗格
  • o 选择下一个窗格,也可以使用上下左右方向键来选择
  • space 切换窗格布局,tmux 内置了五种窗格布局,也可以通过 ⌥1 至 ⌥5来切换
  • z 最大化当前窗格,再次执行可恢复原来大小
  • q 显示所有窗格的序号,在序号出现期间按下对应的数字,即可跳转至对应的窗格

窗口(window)操作

tmux 除了窗格以外,还有窗口(window) 的概念。依次使用以下快捷键来熟悉 tmux 的窗口操作:

  • c 新建窗口,此时当前窗口会切换至新窗口,不影响原有窗口的状态
  • p 切换至上一窗口
  • n 切换至下一窗口
  • w 窗口列表选择,注意 macOS 下使用 ⌃p 和 ⌃n 进行上下选择
  • & 关闭当前窗口
  • , 重命名窗口,可以使用中文,重命名后能在 tmux 状态栏更快速的识别窗口 id
  • 0 切换至 0 号窗口,使用其他数字 id 切换至对应窗口
  • f 根据窗口名搜索选择窗口,可模糊匹配

Session操作

刚说完flag就倒了,本地使用还好,SSH的时候session真的必不可少。

下面列出一些session的操作

启动新会话:

1
tmux [new -s 会话名 -n 窗口名]

恢复会话:

1
tmux at [-t 会话名]

列出所有会话:

1
tmux ls

关闭会话:

1
tmux kill-session -t 会话名

关闭所有会话:

1
tmux kill-server

载入数据

现在我们已经在Difmap环境中了,将有一个如下的提示符:

1
0>

现在我们开始输入第一个命令,用于载入数据。

1
0> observe YOUR_DATA

提示:这里可以简单地输入obs然后使用Tab即可补全剩余的命令。这项技术有助于在整个Difmap的使用过程中节省宝贵的时间。随时随地掌握这些技巧,可以提升软件使用体验^_^。
此时应该可以看到下述输出了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Reading UV FITS file: 3C219.L(A.butDefinitelyB).postProc.uvf
AN table 1: 2454 integrations on 406 of 406 possible baselines.
Apparent sampling: 0.732128 visibilities/baseline/integration-bin.
Found source: 3C219

There are 2 IFs, and a total of 2 channels:

IF Channel Frequency Freq offset Number of Overall IF
origin at origin per channel channels bandwidth
------------------------------------------------------------- (Hz)
01 1 1.385e+09 2.5e+07 1 2.5e+07
02 2 1.665e+09 2.5e+07 1 2.5e+07

Polarization(s): RR LL RL LR

Read 307 lines of history.

Reading 5835496 visibilities.

该命令详细列出了源的相关信息。检查所有的Ifs,通道、频率等都是正确的。如果出现了诸如“”的错误,你可能需要返回AIPS来确定输出了正确的数据。如果需要得到更多的信息,可以输入下述命令:

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

0> header
UV FITS miscellaneous header keyword values:
OBSERVER = "AC149"
DATE-OBS = "1986-05-18"
ORIGIN = "AIPSlocalhost LOCALHOST 31DEC11"
TELESCOP = "VLA"
INSTRUME = "VLA"
EQUINOX = 2000.00

Sub-array 1 contains:
406 baselines 29 stations
2454 integrations 4 scans

Station name X (m) Y (m) Z(m)
01 VLA:_N28 -1.600864e+06 -5.041770e+06 3.557965e+06
02 VLA:_W28 -1.604866e+06 -5.046527e+06 3.552962e+06
03 VLA:_N16 -1.601062e+06 -5.041898e+06 3.556058e+06
04 VLA:_W24 -1.604009e+06 -5.045468e+06 3.553404e+06
05 VLA:_W12 -1.602045e+06 -5.043040e+06 3.554428e+06
06 VLA:_W04 -1.601316e+06 -5.042139e+06 3.554808e+06
07 VLA:_W20 -1.603250e+06 -5.044530e+06 3.553798e+06
08 VLA:_W36 -1.606842e+06 -5.048973e+06 3.551913e+06
09 VLA:_W08 -1.601614e+06 -5.042508e+06 3.554652e+06
10 VLA:_E32 -1.597053e+06 -5.036606e+06 3.553059e+06
11 VLA:_OUT -1.601185e+06 -5.041978e+06 3.554876e+06
12 VLA:_N36 -1.600691e+06 -5.041658e+06 3.559632e+06
13 VLA:_E36 -1.596128e+06 -5.035403e+06 3.552652e+06
14 VLA:_W16 -1.602593e+06 -5.043718e+06 3.554141e+06
15 VLA:_N32 -1.600781e+06 -5.041716e+06 3.558761e+06
16 VLA:_N20 -1.601005e+06 -5.041861e+06 3.556610e+06
17 VLA:_E12 -1.600416e+06 -5.040979e+06 3.554536e+06
18 VLA:_E20 -1.599341e+06 -5.039580e+06 3.554065e+06
19 VLA:_E28 -1.597900e+06 -5.037707e+06 3.553432e+06
20 VLA:_E24 -1.598663e+06 -5.038699e+06 3.553767e+06
21 VLA:_N08 -1.601148e+06 -5.041953e+06 3.555236e+06
22 VLA:_N04 -1.601174e+06 -5.041970e+06 3.554987e+06
23 VLA:_E08 -1.600802e+06 -5.041479e+06 3.554706e+06
24 VLA:_E16 -1.599926e+06 -5.040341e+06 3.554320e+06
25 VLA:_E04 -1.601069e+06 -5.041826e+06 3.554825e+06
26 VLA:_N12 -1.601110e+06 -5.041929e+06 3.555597e+06
27 VLA:_N24 -1.600930e+06 -5.041813e+06 3.557330e+06
28 VLA:_W32 -1.605809e+06 -5.047694e+06 3.552459e+06
29 VPT:_OUT -1.601185e+06 -5.041978e+06 3.554876e+06

There are 2 IFs, and a total of 2 channels:

IF Channel Frequency Freq offset Number of Overall IF
origin at origin per channel channels bandwidth
------------------------------------------------------------- (Hz)
01 1 1.385e+09 2.5e+07 1 2.5e+07
02 2 1.665e+09 2.5e+07 1 2.5e+07

Source parameters:
Source: 3C219
RA = 09 21 08.548 (2000.0) 09 20 14.260 (apparent)
DEC = +45 38 57.920 +45 42 30.877
Antenna pointing center:
OBSRA = 09 21 08.548 (2000.0)
OBSDEC = +45 38 57.920

Data characteristics:
Recorded units are UNCALIB.
Recorded polarizations: RR LL RL LR
Phases are rotated 0 mas East and 0 mas North.
UVW coordinates are rotated by 0 degrees clockwise.
Scale factor applied to FITS data weights: 1
Coordinate projection: SIN

Summary of overall dimensions:
1 sub-arrays, 2 IFs, 2 channels, 2454 integrations
4 polarizations, and up to 406 baselines per sub-array

Time related parameters:
Reference date: 1986 day 249/00:00:00 (1986 Sep 06)
Julian Date: 2446679.50, Epoch J1986.678
GAST at reference date: 22 59 10.041
Coherent integration time = 0.0 sec
Incoherent integration time = 0.0 sec
Sum of scan durations = 26460 sec
UT range: 249/09:51:21 to 249/23:30:22
Mean epoch: JD 2446680.195 = J1986.680

此时在启动目录会生成一个log文件difmap.log,这个文件记录了你在DIFMAP交互环境中输入的所有命令。 It will also include selected output lines though they will be preceded by a ! in order to comment them out.
这个log文件可以通过一种脚本的形式来使用,可以通过在交互命令中输入 @difmap.log来执行这个脚本。
但需要注意的是这个脚本无法与PGPLOT进行交互,所以交互式的flagging都不会发生。所以要特别注意这一点。

The next step is to choose the Stokes parameter you are interested in:

1
2
3
4
0> select i

Where i refers to the Stokes I parameter. You can select any Stokes parameter (e.g. select q or u) to work with.

代码参考 https://www.github.com/shaoguangleo/radio_astronomy

启动difmap

服务器已经安装了Difmap2.4l版本,只需要在环境变量PATH中加入/usr/local/difmap即可,详细安装步骤可以参考DIFMAP安装手册。

安装好DIFMAP后,打开一个终端,然后进入到数据所在的目录。输入difmap即可得到如下提示信息:

TODO : Adding difmap startup terminal

这个示例我们使用源J1036+1326的C Band C Array的数据,
This is from Project AT0205, Seg A, source TEX1033+137, taken on 7/20/97 with 370 seconds TOS.

代码参考 https://www.github.com/shaoguangleo/radio_astronomy

引言

Difmap是一个强有力的处理多维数组成像的程序。
Difmap起初是为了处理VLBI连续谱数据,后来开始处理VLA数据集。
DIFMAP通过使用现代计算机日益增加的RAM容量来最小化加载数据和重构模型所花费的时间。
这个手册会带你畅游DIFMAP的基本操作,来进行CLEAN及自校准你的数据。

所有的测试数据位于/home/share/data/difmap中,请拷贝到自己的文件夹进行操作。

代码参考 https://www.github.com/shaoguangleo/radio_astronomy

Linux 的htop命令

htop可以查看每个进行的内存负载。

htop提供的信息与top类似,不过htop提供了更好的交互、彩色显示以及控制。

远程登录不需要密码

  1. 在本机上操作ssh-keygen
  2. ssh-copy-id -i .ssh/id_rsa.pub remote_username@remote_ipaddress
  3. ssh remote_username@remote_ipaddress

背景

最近参加了一个培训,分配了很多的账号,随便找个账号的密码,如下所示gyDYKdf39dk*dfs@&,关键操作的过程中,你还需要打开多个终端。

那么问题来了,如何才能缩短这个浪费生命的无聊过程呢,方法很简单,只有3步。

远程登录不需要密码

1 在本机上操作ssh-keygen,会在目录.ssh种生成一个id_rsa.pub文件 2 ssh-copy-id -i .ssh/id_rsa.pub remote_username@remote_ipaddress 3 ssh remote_username@remote_ipaddress

比如,来个实际操作:

打开一个终端 $ ssh-keygen 拷贝 $ ssh-copy-id -i .ssh/id_rsa.pub hero@192.168.2.3 愉快登录 $ ssh hero@192.168.2.3

此时即可无密码登陆remote了

在.ssh/config中输入下述信息,即可快捷将ssh remote_username@remote_ipaddress精简为ssh remote了

1
2
3
4
5
Host   remote
HostName 192.168.254.123
Port 22
User hero
IdentityFile ~/.ssh/id_rsa

The Ultimate Guide to SSH - Setting Up SSH Keys

The Ultimate Guide to SSH - Setting Up SSH Keys

Welcome to our ultimate guide to setting up SSH (Secure Shell) keys. This tutorial will walk you through the basics of creating SSH keys, and also how to manage multiple keys and key pairs.

Create a New SSH Key Pair

Open a terminal and run the following command:

1
ssh-keygen

You will see the following text:

1
2
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa):

Press enter to save your keys to the default /home/username/.ssh directory.

Then you’ll be prompted to enter a password:

1
Enter passphrase (empty for no passphrase):

It’s recommended to enter a password here for an extra layer of security. By setting a password, you could prevent unauthorized access to your servers and accounts if someone ever gets a hold of your private SSH key or your machine.

After entering and confirming your password, you’ll see the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:/qRoWhRcIBTw0D4KpTUyK6YepyL6RQ2CQrtWsaicCb4 username@871e129f767b
The key's randomart image is:
+---[RSA 2048]----+
| .o=+.... |
|+.*o+o . |
|+X.=o o |
|@.=.oo . |
|=O ...o S |
|o.oo . . |
|.E+ . . . . |
|oo . ... + |
|=.. .o. . . |
+----[SHA256]-----+

You now have a public and private SSH key pair you can use to access remote servers and to handle authentication for command line programs like Git.

Manage Multiple SSH Keys

Though it’s considered good practice to have only one public-private key pair per device, sometimes you need to use multiple keys or you have unorthodox key names. For example, you might be using one SSH key pair for working on your company’s internal projects, but you might be using a different key for accessing a client’s servers. On top of that, you might be using a different key pair for accessing your own private server.

Managing SSH keys can become cumbersome as soon as you need to use a second key. Traditionally, you would use ssh-add to store your keys to ssh-agent, typing in the password for each key. The problem is that you would need to do this every time you restart your computer, which can quickly become tedious.

A better solution is to automate adding keys, store passwords, and to specify which key to use when accessing certain servers.

SSH config

Enter SSH config, which is a per-user configuration file for SSH communication. Create a new file: ~/.ssh/config and open it for editing:

1
nano ~/.ssh/config

Managing Custom Named SSH key

The first thing we are going to solve using this config file is to avoid having to add custom-named SSH keys using ssh-add. Assuming your private SSH key is named ~/.ssh/id_rsa, add following to the config file:

1
2
3
4
5
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes

Next, make sure that ~/.ssh/id_rsa is not in ssh-agent by opening another terminal and running the following command:

1
ssh-add -D

This command will remove all keys from currently active ssh-agent session.

Now if you try closing a GitHub repository, your config file will use the key at ~/.ssh/ida_rsa.

Here are some other useful configuration examples:

1
2
3
4
5
Host bitbucket-corporate
HostName bitbucket.org
User git
IdentityFile ~/.ssh/id_rsa_corp
IdentitiesOnly yes

Now you can use git clone git@bitbucket-corporate:company/project.git

1
2
3
4
5
Host bitbucket-personal
HostName bitbucket.org
User git
IdentityFile ~/.ssh/id_rsa_personal
IdentitiesOnly yes

Now you can use git clone git@bitbucket-personal:username/other-pi-project.git

1
2
3
4
5
6
7
Host myserver
HostName ssh.username.com
Port 1111
IdentityFile ~/.ssh/id_rsa_personal
IdentitiesOnly yes
User username
IdentitiesOnly yes

Now you can SSH into your server using ssh myserver. You no longer need to enter a port and username every time you SSH into your private server.

Password management

The last piece of the puzzle is managing passwords. It can get very tedious entering a password every time you initialize an SSH connection. To get around this, we can use the password management software that comes with macOS and various Linux distributions.

For this tutorial we will use macOS’s Keychain Access program. Start by adding your key to the Keychain Access by passing -K option to the ssh-add command:

1
ssh-add -K ~/.ssh/id_rsa_whatever

Now you can see your SSH key in Keychain Access:

But if you remove the keys from ssh-agent with ssh-add -D or restart your computer, you will be prompted for password again when you try to use SSH. Turns out there’s one more hoop to jump through. Open your SSH config file by running nano ~/.ssh/config and add the following:

1
2
3
Host *
AddKeysToAgent yes
UseKeychain yes

With that, whenever you run ssh it will look for keys in Keychain Access. If it finds one, you will no longer be prompted for a password. Keys will also automatically be added to ssh-agent every time you restart your machine.

Now that you know the basics of creating new SSH keys and managing multiple keys, go out and ssh to your heart’s content!