0%

OS操作

遍历目录

1
2
3
4
5
6
7
8
9
10
import java.io.File
// 1 depth walk
new File(dir_path).listFiles() //返回一个数组,包含该目录下所有文件/目录的File对象,只做1级深度
new File(dir_path).list() // return the files/directories name below `dir_path`

/** or **/
import scala.reflect.io.Path
val ap = Path(dir_path)
ap.walk.toList // walk recursively, all depth to the leaf files.
ap.walkFilter(cond: Path=>Boolean)

增删查改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import java.io.File
new File("tmp").mkdir() // mkdir tmp
new File("tmp.txt").createNewFile() // touch tmp
new File("tmp").delete() // rm -rf tmp
new File("tmp.txt").renameTo(new File("sht.txt")) //rename tmp.txt fuck.txt

new File("tmp.txt").is* // 查询是否文件、目录
new File("tmp.txt").can* // 查询是否可写可读可执行
new File("tmp.txt").exists //查询是否存在

/** or **/
import scala.reflect.io.Path
Path("tmp").createDirectory() // mkdir tmp
Path("tmp.txt").createFile() // touch tmp.txt
Path("tmp").delete(); Path("tmp").deleteRecursivly()// rm -rf tmp
Path("tmp.txt").renameTo(new File("sht.txt")) //rename tmp.txt fuck.txt
Path("tmp.txt").is* // 查询是否文件、目录
Path("tmp.txt").can* // 查询是否可写可读可执行
Path("tmp.txt").exists

文件名操作

1
2
3
4
5
import scala.reflect.io._

Path("fuck.txt").parent // 拿到父目录
Path("fuck.txt").toAbsolute //拿到绝对路径
Path("fuck.txt").extension //拿到文件后缀

Process

需要调用外部命令时, import scala.sys.process._

正常调用

1
Process("<cmd>") !!

处理命令输出

1
2
3
4
5
6
val logger = ProcessLogger(line => if(line.contain("shit")) println("Got a shit"))
//logger 逐行处理
Process("cat shitgamedamnit").!(logger)

//或者整体处理
val retLog = Process("ls").!!

文件操作

主要利用scala和java提供的标准库。

读文件:

1
2
3
4
5
6
import scala.io.Source
val f = Source.fromFile("a.txt")
f.getLines().foreach{ line=>
println(line)
}//打印每一行
f.close()

写文件:

1
2
3
4
5
6
import java.io.{File, PrintWriter}
val writer = new PrintWriter(new File("a.txt"))
for(i <- 0 to 10) {
writer.println(s"index: $i")
}//写入文件每行"index: 1\nindex: 2..."
writer.close()//一定要记得关闭文件

如何在WSL安装Scala

  1. 购买机场,建立科学上网通道。打开Clash,打开局域网 Allow LAN 功能。鼠标悬浮在该功能的图标上,获得本机的IP地址,通常是一个局域网地址。随后设置WSL的流量代理转发:在Shell配置文件里面加上环境变量
1
2
3
4
export http_proxy = 'http://192.168.3.4:7890'  # 根据本机IP和端口修改地址
export https_proxy = 'http://192.168.3.4:7890'
export all_proxy = 'sock5://192.168.3.4:7890'
export ALL_PROXY = 'sock5://192.168.3.4:7890'
  1. 确保linux机器可以顺畅访问国际互联网后,安装openjdk:
1
sudo apt-get install openjdk-11-jdk
  1. 安装sbt,不必单独安装scala。每个scala项目可能使用不同版本的scala,sbt会根据build.sbt自动安装所需的版本。这里建议使用官网的脚本:
1
2
3
4
5
echo "deb https://repo.scala-sbt.org/scalasbt/debian all main" | sudo tee /etc/apt/sources.list.d/sbt.list
echo "deb https://repo.scala-sbt.org/scalasbt/debian /" | sudo tee /etc/apt/sources.list.d/sbt_old.list
curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | sudo apt-key add
sudo apt-get update
sudo apt-get install sbt

删除GitHub远程库中的文件:

1
2
3
git rm -r --cached <delete-dir/file>
git commit -m "delete <sth>"
git push origin

使用裸git库作为服务器与本地机的中转站

  • 首先在中转服务器上建立新裸的git repo
    1
    2
    3
    cd <repo_path>
    mkdir <repo_name>.git
    git init --bare <repo_name>.git
  • 本地机的repo,添加对应的远程引用
    1
    2
    3
    4
    # 类似GitHub
    git remote add <ref_name> <user_name>@<server_ip>:<repo_path>/<repo_name>.git
    git add -A; git commit -m ".."; # 如果需要提交。。。
    git push <ref_name> # 将当前已经提交的工作区内容提交至中转站
  • 远程服务器上,clone中转站的repo
    1
    git clone <user_name>@<server_ip>:<repo_path>/<repo_name>.git

查看文件提交历史以及修改历史

使用 git log -p 即可。

给git repo打tag

标记版本号以及备注:

1
git tag -a v1.0 -m "release the 1.0 version"

查看已有的tag:

1
git tag 

提交打上tag的包:

1
git push origin --tags

注意,上面这一操作可以在github的release界面看到已经打包的源代码。

Matlab常常作为硬件算法的软件实现平台。数字电路设计相关的算法分析大多在RTL实现之前使用Matlab进行建模分析,其中一个重要环节是将算法中的数据进行定点化,即量化。量化策略影响到算法的性能和精度,并影响到最终结果。如何在Matlab中评估这种影响,确定数据的合理的定点量化策略,我们需要使用 NumericTypeScope 类来做。

1
2
3
4
5
h = NumericTypeScope;
fi_a = fi(a); % a is a floating point matrix
step(h, fi_a); % analysis the a's range and accuracy
reset(h); % reset the storage
release(h); % release the resource

NumericTypeScope 类可以探测某个数据张量的动态范围,并自动评估出一个最好的、尽量没有精度损失的测量策略——即整数位和小数位的位宽各是多少。上述命令只能分析一次定点数,即分析一个变量。分析下一个变量必须release一下h,但并不需要每次都reset。

使用Hexo + Github Page 搭建个人网站

在Windows WSL环境下,直接安装 Node.js 和 npm,作为准备工具和运行环境。直接在Windows环境下安装Node.js 和npm,使用的时候直接报错,Linux环境下比较省心。

不知道是否是翻墙工具的原因,发布博文和访问博文都需要代理工具。

Hexo的安装与使用

Hexo怎么安装,直接百度即可。

阅读全文 »