跳转至

备忘

删除 github 上传的 Mac 上的 .DS_Store 文件

删除项目中的所有.DS_Store。这会跳过不在项目中的 .DS_Store

find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch

将 .DS_Store 加入到 .gitignore

zsh 中使用 mkdocs command not found

设置 alias运行

$ whereis mkdocs # 在 bash 中找到 mkdocs 所在路径
$ mkdocs: /home/anya/.local/bin/mkdocs

$ alias mkdocs=/home/anya/.local/bin/mkdocs # 在 zsh 中设置别名
$ mkdocs serve # 成功运行

TODO:在 PATH 中添加环境变量

模逆运算 离散数学

long hash(long b,long e,long m)
{
  long a;
  long result;

  result = 1;
  for (a = e; a != 0; a = (long)a >> 1) {
    if ((a & 1) != 0) { // a 为奇数
      result = (result * b) % m;
    }
    b = (b * b) % m; 
  }
  return result;
}

$$ (a×b)mod m=((a mod m)×(b mod m))mod m $$ 这意味着在每一步的乘法运算中,你可以提前取模,以确保结果永远不会超过机器的整数限制。

关于快速幂,其基本思想是将指数 \(e\) 表示为其二进制形式。例如,如果我们要计算 \(b^{13}\),13的二进制形式是 11011101。那么我们可以表示这个幂为:

\[ b^{13} = b^8 \times b^4 \times b^1 \]

现在,看看该算法的工作原理:

  1. 初始化结果为 1。
  2. 对于指数的每一位(从最低位开始),检查这一位是否为1。如果是,乘上当前的基数。
  3. 在每一步,基数都会被平方,因为如果你观察上面的示例,你会注意到在从右往左遍历每一位时,基数每次都平方。
  4. 在乘法和平方操作后,立即执行模运算,确保结果不会溢出。

objdump 反汇编

$ gcc -o executable file.c -g
$ objdump -S -d --source executable
# gcc 要生成调试信息,objdump 才能将 c 源码和汇编代码联系起来

LibreOffice 一键将 ppt 导出成 pdf

soffice --convert-to pdf *.ppt 或者 soffice --convert-to pdf *.doc

实验报告封面 html 模板

<div class="cover" style="page-break-after:always;font-family:方正公文仿宋;width:100%;height:100%;border:none;margin: 0 auto;text-align:center;">
    <div style="width:60%;margin: 0 auto;height:0;padding-bottom:10%;">
        </br>
        <img src="https://raw.githubusercontent.com/Keldos-Li/pictures/main/typora-latex-theme/ZJU-name.svg" alt="校名" style="width:100%;"/>
    </div>
    </br></br></br></br></br>
    <div style="width:60%;margin: 0 auto;height:0;padding-bottom:40%;">
        <img src="https://raw.githubusercontent.com/Keldos-Li/pictures/main/typora-latex-theme/ZJU-logo.svg" alt="校徽" style="width:100%;"/>
    </div>
    </br></br></br></br></br></br></br></br>
    <span style="font-family:华文黑体Bold;text-align:center;font-size:20pt;margin: 10pt auto;line-height:30pt;">《数据结构基础》</span>
    <p style="text-align:center;font-size:14pt;margin: 0 auto">实验报告 </p>
    </br>
    </br>
    <table style="border:none;text-align:center;width:72%;font-family:仿宋;font-size:14px; margin: 0 auto;">
    <tbody style="font-family:方正公文仿宋;font-size:12pt;">
        <tr style="font-weight:normal;"> 
            <td style="width:20%;text-align:right;">周  次</td>
            <td style="width:2%"></td> 
            <td style="width:40%;font-weight:normal;border-bottom: 1px solid;text-align:center;font-family:华文仿宋"> </td>     </tr>
        <tr style="font-weight:normal;"> 
            <td style="width:20%;text-align:right;">上课时间</td>
            <td style="width:2%"></td> 
            <td style="width:40%;font-weight:normal;border-bottom: 1px solid;text-align:center;font-family:华文仿宋"> </td>     </tr>
        <tr style="font-weight:normal;"> 
            <td style="width:20%;text-align:right;">授课教师</td>
            <td style="width:2%"></td> 
            <td style="width:40%;font-weight:normal;border-bottom: 1px solid;text-align:center;font-family:华文仿宋">杨子祺 </td> </tr>
        <tr style="font-weight:normal;"> 
            <td style="width:20%;text-align:right;">日  期</td>
            <td style="width:2%"></td> 
            <td style="width:40%;font-weight:normal;border-bottom: 1px solid;text-align:center;font-family:华文仿宋">2023/9/30</td>     </tr>
    </tbody>              
    </table>
</div>

VSCode 使用 markdown 插件导出成 pdf 无法渲染数学公式

md 文档的末尾加上:

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({ tex2jax: {inlineMath: [['$', '$']]}, messageStyle: "none" });
</script>

或找到 .vscode 下的插件路径,在 template.html 中添加

Mac电脑查看本机的 mac 地址和 ip 地址

ifconfig

![[../assets/CS/无线网络应用/ifconfig.png]]

编译运行 c 文件

gcc -c file1.c file2.c file3.c
gcc -o executable file1.c file2.c file3.c
./executable

终端设置代理

cat  /etc/resolv.conf # 获取 IP
export https_proxy=http://172.22.240.1:7890
export http_proxy=http://172.22.240.1:7890
export all_proxy=socks5://172.22.240.1:7890

git

基础命令

新建

  • git init:让当前文件夹变成 git 仓库(创建 .git 文件夹)
  • git init folder:创建一个新的文件夹并初始化为 git 仓库

git 账号配置

  • 全局配置:
    • git config --global user.name "name"
    • git config --global user.email "email"

加入文件

  • git add file/folder:将文件加入暂存区
  • git status:查看暂存区和工作区状态
提交
  • git commit (编辑器编辑)
  • git commit -m "xxx"
  • git log :查看提交历史
    • --oneline:每一个提交一行
    • --graph:显示分支结构
    • --stat:显示文件删改信息
    • -p:显示详细的修改内容

分支

  • git checkout -b <branch_name>:创建分支,并切换过去
  • git checkout master:回到主分支
  • git push origin <branch_name>:将分支推送到远程仓库
  • git pull:将本地仓库更新
  • git diff <branch_name> master:显示差别

克隆分支

  • git clone -b <branch_name> <repo_url>:克隆单个分支
  • git branch -a:查看所有分支
  • git checkout -b <branch_name> origin/<branch_name>:关联分支

清除命令git rm --cached <file>:已 add 未 commit 的文件退回未 add 状态

  • git checkout -- <file>:已修改的文件撤销修改
  • git reset --soft HEAD^:撤销 commit(不更改文件)
  • git reset --hard HEAD^:撤销 commit(文件回退到上一版本)
  • git update-ref -d HEAD:撤销第一条 commit(不更改文件)
  • git push -f:强制推送,覆盖 commit

删除提交的某条 commit 记录

git log # 找到需要删除的上一条的 commit_id
git rebase -i <hash>

端口占用

  1. 打开终端。
  2. 输入命令 lsof -i :端口号,例如 lsof -i :8080 来查看 8080 端口是否被占用。
  3. 查看结果,如果端口被占用,则会显示进程名和PID,否则会显示"COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME"

Github.io

java

brew install temurin

🍺 temurin was successfully installed!

java --version
javac xxx.java
java xxx

emacs

To start emacs now and restart at login:
  brew services start emacs
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/emacs/bin/emacs --fg-daemon

保存退出:按下Ctrl + X,接着按下Ctrl + S,这样就会保存当前文件。 然后按下Ctrl + X,接着按下Ctrl + C,这样就会退出Emacs

Unix GUI 孤儿进程

How can I run a command which will survive terminal close Subshell difference-between-a-subshell-and-a-child-process

command &
# 开启后台:&
# 开启 subshell: ()
(command &)
# subshell 中开启后台,可以脱离 shell

加了 & 以后,subshell 不会等后台进程就直接退了,后台再跑的进程就成孤儿进程了

subshell:

bash -c "command1; command2; command3"
( command1 ; command2 ; command3 )

difference between command & and (command &)

$ xpdf &
$ ps --forest
    PID TTY             TIME CMD
2198400 pts/0       00:00:00 zsh
2198461 pts/0       00:00:00  \_xpdf
2198549 pts/0       00:00:00  \_ps

$ (xpdf &)
$ ps --forest
    PID TTY             TIME CMD
2198595 pts/0       00:00:00 zsh
2198674 pts/0       00:00:00  \_ps
2198658 pts/0       00:00:00 xpdf

reveal-md

使用自定义主题覆盖显示主题。在此示例中,文件位于 ./theme/my-custom.css

$ reveal-md slides.md --theme theme/my-custom.css

Override reveal theme with a remote one (use rawgit.com because the url must allow cross-site access): 使用远程主题覆盖显示主题(使用 rawgit.com,因为 url 必须允许跨站点访问):

$ reveal-md slides.md --theme https://rawgit.com/puzzle/pitc-revealjs-theme/master/theme/puzzle.css

Highlight Theme 亮点主题

Override highlight theme (default: zenburn): 覆盖突出显示主题(默认: zenburn ):

$ reveal-md slides.md --highlight-theme github

See available themes. 查看可用主题。

Exiftool

binwalk

binutils

$ brew install binutils
ghidra requires Java 17+. You can install the latest version with:
  brew install --cask temurin
  ...
==> Installing Cask ghidra
==> Linking Binary 'ghidraRun' to '/opt/homebrew/bin/ghidraRun'

🍺 ghidra was successfully installed!

运行:

ghidraRun

无法打开

sudo spctl --master-disable

Ghidra

MaxOS 反汇编工具

brew install ghidra

rosetta

softwareupdate --install-rosetta

TO DO

Docker

brew install --cask --appdir=/Applications docker

🍺 docker was successfully installed!

什么是 docer:https://www.redhat.com/zh/topics/containers/containers-vs-vms

Homebrew

网址:https://brew.sh/

安装:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

添加到路径:

(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/anya/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

error

Error: Non-checksummed download of binutils- formula file from an arbitrary URL is unsupported! `brew extract` or `brew create` and `brew tap-new` to create a formula file in a tap on GitHub instead.
~/Downloads
$ brew install --cask react-native-debugger worked

foremost