navigation side bar issue
发现一个 Hexo 的 bug. 使用版本
1 | hexo version |
问题描述:
Outline 中的中文导航会失败,英文的可以正常工作
怎么修还不清楚,简单搜索了一下并没有查到解决方案,有机会的话可以看看 Hexo 源码再提一个 fix 的 PR ╮( ̄▽ ̄””)╭
发现一个 Hexo 的 bug. 使用版本
1 | hexo version |
问题描述:
Outline 中的中文导航会失败,英文的可以正常工作
怎么修还不清楚,简单搜索了一下并没有查到解决方案,有机会的话可以看看 Hexo 源码再提一个 fix 的 PR ╮( ̄▽ ̄””)╭
Man 帮助文档操作方式
以下实验均基于 bas
$
表示普通用户, #
表示 root 用户#!
开头指定 shell 版本的语句bash /path/to/file.script.sh
.bash_history
文件中;
隔开, echo a ; echo b
等价于 echo a \n echo b
什么是 login shell
A login shell is the shell which you get just after logging in to a machine. However, if you open up a shell while logged in to a graphical environment (such as GNOME, KDE, and so on), then it is not a login shell.
1 | # 打印,自带结尾换行效果 |
从上面效果看,都能打印,而且结果都一致,但是这几种使用方式还是有区别的
1 | # " 中不能以 ! 结尾, 在 bash 中 !有特殊含义,表示前一个 |
echo 的几种用法的副作用:
;
不然命令断裂了echo 的其他用法:
echo -n "hi"
使用 -n
取出换行echo -e "1\t2\t3"
使用 -e
打印转义符echo 输出变色:
1 | # \e[1;31m 设置字体为红色, \e[0m 重制 |
1 | # printf 和 C 语言中用法一致,默认不带换行 |
PS: -5, 左对齐,占 5 个位置
赋值语句 var=value
,需要注意的是,var = value
是不对的,后者是等于运算。如果 value 中间没有空格,则直接写,不然需要用引号包裹。当使用 echo 或者 prinf 输出变量时,需要用双引号
1 | name=jack |
假设我们安装了新的应用到 /opt/myapp
,这个应用包含 bin
和 lib
目录。为了使他生效,我们需要做如下设置
1 | export PATH=/opt/myapp/bin:$PATH |
如果想简化上面的设置的话,我们可以在 .bashrc
里自定义一些函数
1 | prepend() { [ -d "$2" ] && eval $1=\"$2':'\$$1\" && export $1; } |
但是上面的脚本有瑕疵,当原始 PATH 为 null 时,新生成的 PATH 就会以 :
结果,我们可以改进如下
1 | prepend() { [ -d "$2" ] && eval $1=\"$2\$\{$1:+':'\$$1\}\" && export $1 ; } |
PS: shell 中定义变量的格式 ${parameter:+expression}
1 | # 如何定义函数? |
体验下来就一个感觉,bash 下的计算略微繁琐
1 | # 准备变量 |
如果想要有精度的计算,可以使用 bc
, bc 是basic calculator/bench calculator的简称。其语法类似于C语言,支持加减乘除还有更多复杂的运算。
1 | >>> bc |
man page 说明如下:
There are four special variables, scale, ibase, obase, and last. scale defines how some operations use digits after the decimal point. The default value of scale is 0.
ibase and obase define the conversion base for input and output numbers. The default for both input and output is base 10.
last (an extension) is a variable that has the value of the last printed number. These will be discussed in further detail where appropriate.
All of these variables may have values assigned to them as well as used in expressions.
文件描述符:
1 | # 基操,输入到文件,如果原来有值,会覆盖 |
>
Vs >>
: 前者是覆盖,后者是续接
./dev/null is a special device file where any data received by the file is discarded. The null device is often known as a black hole as all the data that goes into it is lost forever.
/dev/null 是一个特殊的设备,可以将它看作一个黑洞,所有进去的东西都没了
1 | # 终端多行输入 |
自定义文件描述符
可用模式:Read mode, Write with truncate mode, Write with append mode
1 | # `<` 用于将文件导向 stdin |
为写操作自定义文件描述符
1 | exec 4> output.txt |
为 append 模式的 write 定义文件描述符
1 | exec 5>>out.txt |
PS: >>
自带会车,如果不想要,需要用可以用 echo -n
或者 printf "%s" "$(value)"
1 | # 数组声明及调用 |
Associative arrays: 关系型数组,普通数组只能存整形,但是关系型数组可以存储混合的,任何 text 格式的数据。这种数据类型是在 Bash 4.0 引入的
Mac 升级 Bash 版本
1 | # 查看当前版本 |
Associative arrays 使用案例
1 | declare -A fruits_value |
PS: 感觉被骗了,这 TM 叫数组?!!命名就是字典嘛
alias: 将很长的命令用一个简写来代替, 声明形式 alias new_command='command sequence'
, 例如 alias install='sudo apt-get install'
终端声明的 alias 是零时的,重启终端后失效,可以将其写入 rc 文件 echo 'alias cmd="command seq"' >> ~/.bashrc
1 | # 显示所有可用的别名 |
There is no mechanism for using arguments in the replacement text, as in csh. If arguments are needed, a shell function should be used (see Shell Functions).
Java util 包中自带了 base 64 的编码/解码方法,示例如下
1 | import java.util.Base64; |
git pull 算是开发时经常用到的一个命令了,但是更新代码之后,时常会遇到最新版本的代码不 work 的情况。由此,打算对 pull 命令做一个优化,每次 pull 的时候,将当前 repo 的信息写到历史记录中,类似 .zsh_history
的功能。
1 | function git { |
1 | function git { |
PS: 为了重复测试脚本,可以使用 git reset --hard xxx
回退版本,再次测试 pull
任务描述:
有一个 git repo 存储了所有的测试文件(java 格式),已知需要筛选的文件列表,筛选出所有文件中包含 ‘DB’ (忽略大小写)的文件。并列出包含关键字的列,以便人工删选。
原始文件名列表格式如下:
1 | <?xml version="1.0" encoding="UTF-8"?> |
使用编辑器的快捷功能将 #-
去掉
PS: 查询一下 sed, awk 和内置的字符串处理方式
repo 中文件名格式如下:PLT123457725UTF8ExportTemplateUserRecordWithUTF8UserImportAndShownCorrectEncoding
使用 find + grep 删选哪些文件包含 db 操作
1 | find . -iname 'PLT123457726*.java' -exec grep -i "dbUtil\|DB" {} \; |
将文件中的 case name 删选出来 grep -E -o 'PLT.*[0-9]+' bulk.xml >> bulk2.xml
遍历每一行,做 query
1 | file="./bulk2.xml" |
PS: 由于技术手段的缺失,很多函数我都不清楚怎么调用,对 shell 还是很不熟悉,需要更多的实践练习
echo -n ','
会把 -n
也写进去?通过这个关键字,我们可以进行一组数据的测试,共能上类似于 TestNG 的 dataProvider
Scenario Outline 需要和 Examples 搭配使用,写了前者,IDEA 会给提示的
1 | Feature: user creation related tests |
对应的 Java 代码
1 | public class CreateUserImpl { |
这个 scenario 会运行 4 遍,每一行测试一次
和上面的概念很类似的还有一个叫 DataTable 的概念,他的作用是在一个 Step 中创建多组数据
格式上的区别:DataTable 是不需要 table header 的, 而且不需要 Examples 关键字,在 annotation 里面也不需要占位符
1 | Scenario: Show my fruits |
java 实现代码
1 | @When("I have kinds of fruits") |
从知乎上扒来的通俗解释,我觉得很形象
1 | POSIX是Unix的标准。当年最早的Unix,源代码流传出去了,加上早期的Unix不够完善,于是之后出现了好些独立开发的与Unix基本兼容但又不完全兼容的OS,通称Unix-like OS。局面非常混乱,为了提高兼容性和应用程序的可移植性,标准化Unix-like OS,提出了大家都应该遵守的POSIX标准。后来,Unix这个名字成为了商标,只有花钱进行POSIX标准兼容性测试并通过了的OS,才能称为Unix,其余的OS,最多称为Unix-like OS或者*nix OS。Windows从WinNT开始就有兼容POSIX的考虑。这是因为当年在要求严格的领域,Unix地位比Windows高。为了把Unix用户拉到Windows阵营,搞的。现在情况当然有变化,与当年大不相同了。现在最新的Win10对 Linux/POSIX 支持好,则是因为Linux已经统治了廉价服务器市场。为了提高Windows的竞争力搞的。 |
终端如何测试一个正则表达式
1 | echo 'aaabbbccc' | grep -E bc # bc 会被标红 |
man grep
可以看到它支持的一些可选正则模式, 这几种模式有什么区别?
1 | -E, --extended-regexp PATTERN is an extended regular expression (ERE) |
In GNU sed, the only difference between basic and extended regular expressions is in the behavior of a few special characters: ‘?’, ‘+’, parentheses(‘()’), braces(‘{}’), and ‘|’.
Type | Desc |
---|---|
BRE | character like () {} + ? | need use escape character |
ERE | no need to use escape caharcter before + ? ( ) { } | |
PRE | same as ERE, and add other func |
BRE、ERE可以使用 POSIX 字符集来操作
使用支持
grep
支持BRE,通过参数控制,默认BRE, -P开启PRE, -E开启ERE
sed
支持BRE,默认BRE,-r开启ERE
awk
支持ERE,默认ERE。
元字符(Metacharacter), 指SHELL直译器或正则表达式(regex)引擎等计算机程序中具有特殊意义的字符。
在 POSIX 扩展正则表达式里,定义了14个元字符,它们被作为一般的字符使用时,必须要通过 “转义”(前面加一个反斜杠”")来去除他们本身的特殊意义,这些元字符包括:
开和闭方括号:”[“和”]”
反斜线:”"
脱字符:”^”
美元符号:”$”
句号/点:”.”
竖线/管道符:”|”
问号:”?”
星号:”*”
加号:”+”
开和闭 花括号:”{“和”}”
开和闭 小括号:”(“和”)”
算法描述:
稳定,时间复杂度 O(d*2n)
java 中的 n 次方计算
1 | System.out.println(Math.pow(2,3)); |
1 | public class RadixSort { |
这种从低位开始的排序叫做:Least significant digital
Most signficat digital
在 VSCode 上写代码的时候,终端突然不能做 int 到 String 的转化了
1 | # TypeError Traceback (most recent call last) |
查了下,str 是一个 global 的函数,如果之前有类似 str = 'asdf'
的赋值语句的话,后面对这个函数的调用就会出问题。。。。
回忆一下,貌似终端 debug 的时候有做过类似的操作 (; ̄ェ ̄)
The Factory Method Pattern defines an interface for creating an object, but lets subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.
工厂方法 模式,这个名字可以说是很形象了,哈哈。它定义一个方法来创建对象,并把创建对象的逻辑托付给子类。
简单工厂,工厂只是一个其他的对象,而 工厂方法 这个设计模式中,工厂是一个子类
SimpleFactory, which gives you a way to encapsulate object creation, but not give you the flexibility of the Factory Method