piken

DeepOps的工具小笔记-IntelliJ IDEA 三个简化代码的小技巧(3 ways to simplify your code )

今天看到了一个讲简化代码的几个小TIPS,记录一下,懒得看的只看最上面的总结就行了

1.1 Methods(方法)

Command+option+M(macOS)
Ctrl+Alt+M(windows/linux) 

1.2 Constants 常量

Command+option+C(macOS)
Ctrl+Alt+C(windows/linux)  

1.3 Fields

Command+option+F(macOS)
Ctrl+Alt+F(windows/linux) 

1.4 Variables变量

Command+option+V(macOS)
Ctrl+Alt+V(windows/linux)  

1.5 Parameters参数

Command+option+P(macOS)
Ctrl+Alt+P(windows/linux)  

1.6 Inline(内嵌)

Command+option+N(macOS)
Ctrl+Alt+N(windows/linux)  

2.Change Signature

Command+F6(macOS)
Ctrl+F6(windows/linux) 

3.Rename(重命名)

Shift+F6(macOS)
Shift+F6(windows/linux)

1.Extract / Inline(提取/内联)

1.1 Methods(方法)

Command+option+M(macOS)
Ctrl+Alt+M(windows/linux)

第一步 选中需要提取的代码块
在这里插入图片描述

第二步 按下Ctrl+Alt+M 会将选中代码提取到一个方法中,重新命名方法名即可
在这里插入图片描述

1.2 Constants 常量

Command+option+C(macOS)
Ctrl+Alt+C(windows/linux)

提取常量,选择需要提取的数值,按Ctrl+Alt+C
在这里插入图片描述

修改常量的名称,完成常量提取。

在这里插入图片描述

1.3 Fields

Command+option+F(macOS)
Ctrl+Alt+F(windows/linux)

将重复使用的文本提取出来,增加代码的可读性
选中需要提取的文本内容
在这里插入图片描述

按 Ctrl+Alt+F 在对话框中设置好文本field的名称,访问权限,以及替换的选项
在这里插入图片描述

点击ok后会将这些文本内容提取出来,如下图红框所示。
在这里插入图片描述

1.4 Variables变量

Command+option+V(macOS)
Ctrl+Alt+V(windows/linux)

挺长的一段代码,在使用的时候,可读性要差一些,这个方法就是教大家如何把一段代码提取为变量。
首先选择需要提取的内容,按Ctrl+Alt+V,再提示框中选择需要提取的内容。可以根据自己需要选择提取的内容(算上length方法,还是不算length方法,都看个人喜好)。
在这里插入图片描述

确认后,需要重命名一下变量名称,IDEA会自动重构相关代码。
在这里插入图片描述

1.5 Parameters参数

Command+option+P(macOS)
Ctrl+Alt+P(windows/linux)

提取参数,将代码中重复使用的内容,提取为方法的参数。
选中需要提取的内容,按Ctrl+Alt+P
在这里插入图片描述

再提示框中,选择好参数名称以及替换的范围。点击重构。
在这里插入图片描述

重构后的代码,会在方法中增加一个参数,替换方法提中的内容,另外调用该方法的代码也会相应调整。
在这里插入图片描述

1.6 Inline(内嵌)

Command+option+N(macOS)
Ctrl+Alt+N(windows/linux)

如果想将提取出来的方法内嵌回去,则可以使用这个快捷键进行操作。
选中需要内嵌的方法,按Ctrl+Alt+N,选择相应的内嵌方式(所有都内嵌进来还是单个内嵌?是否移除方法?这些都可以自己选择)
在这里插入图片描述

重构后,方法的实现就会被内嵌到调用的方法中。
在这里插入图片描述

2.Change Signature (这个不知道怎么翻译合适,更改方法的参数特征?)

Command+F6(macOS)
Ctrl+F6(windows/linux)

选中参数,按下Ctrl+F6,出现下面的对话框后
在这里插入图片描述

上述步骤操作结束之后,方法会增加一个season的参数。
在这里插入图片描述

IDEA会自动重构所有调用的方法,对于增加的参数,会直接赋予一个默认值,如下图所示,新增加的参数使用summer作为默认值。
在这里插入图片描述

3.Rename(重命名)

Shift+F6(macOS)
Shift+F6(windows/linux)

选中方法名,然后按Shift+F6 之后修改方法名
在这里插入图片描述

修改后方法名点击后面的图标,会弹出重命名的选项框,选择之后回车即完成重构。
在这里插入图片描述

也可以点击上图中的more options,弹出框中可以选择更多内容。重命名“类”和“方法”,可以点击“preview”按钮预览重命名内容。也可以点击“refactor”直接重构(这个图是本机器截图,跟官方视频有点不一样)
在这里插入图片描述在这里插入图片描述

点击预览按钮,可以查看到都有哪些内容会被重构
在这里插入图片描述

重构之后,会替换掉类的名字和注释中的名字,也会替换掉其他调用这个类的名字。另外这个替换是大小写敏感的。
在这里插入图片描述

DeepOps的macOS小笔记-macOS启动virtualBox虚拟机报错

1 报错内容如下

Kernel driver not installed (rc=-1908)

Make sure the kernel module has been loaded successfully.

where: suplibOsInit what: 3 VERR_VM_DRIVER_NOT_INSTALLED (-1908) – The support driver is not installed. On linux, open returned ENOENT.

2 处理方法:

官方解释

go to the System Preferences » Security&Privacy » General, and “Allow Oracle” to install kernel extensions.

系统-安全与隐私 的 通用标签页,如果阻拦了oracle安装,在页面最下方会有一行文字,大意是阻止了oracle 安装插件,把这个调整为允许就行了。

3 实际上我的问题与解决方案是

本来应该是双击打开进行安装,我直接拖拽到application的,so…

我重新双击安装,并且像上面那个步骤里说的“允许了oracle安装扩展”,之后在运行就ok了

DeepOps的ubuntu小笔记-ubuntu20.04lts更换阿里云的源

首先备份本地的源

cp /etc/apt/sources.list /etc/apt/sources.list.bak

编辑源文件

vi /etc/apt/sources.list

删除原有内容,添加下面内容

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal universe
deb http://mirrors.aliyun.com/ubuntu/ focal-updates universe
deb http://mirrors.aliyun.com/ubuntu/ focal multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-security universe
deb http://mirrors.aliyun.com/ubuntu/ focal-security multiverse

更新源

sudo apt-get update
sudo apt-get upgrade

DeepOps的macOS小笔记-macOS安装openvpn

因为公司远程办公需要使用到vpn,手头上只有一台mac,需要安装一下openvpn。

#如果没有安装brew,在安装一下homebrew 选择aliyun的源速度比较快
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)" 

使用brew 直接安装
brew install openvpn

#启动openvpn
sudo openvpn --config /openvpn-2.5.0/config/你的.ovpn

下面是我没有尝试成功的一个方案:

1、下载openvpn,我2021.1.7下的是 openvpn-2.5.0.zip 因为我喜欢zip

2、解压后得到,openvpn-2.5.0

3、进入openvpn-2.5.0文件夹,打README文件,根据上面操作即可

	tar -zxf openvpn-<version>.tar.gz
	cd openvpn-<version>
	./configure
	make
	make install

4、执行 ./configure 出现错误

checking additionally if OpenSSL is available and version >= 1.0.2... configure: error: OpenSSL version too old

看样子是我的openssl 版本过旧

执行下面语句安装或者更新一下openssl

#安装opensslbrew install openssl
#更新opensslbrew upgrade openssl

重新安装了openssl还是不行,到此以失败告终,然后我是用了brew安装了openvpn然后就成功了。