0%

通过dnsmasq 实现了本地 DNS 服务的功能,这大大加速的域名解析速度。但是最近在连接校园网时,发现每次连网配置文件/etc/resolv.conf都会被修改为校园网默认的配置,但是这样就无法设置为自动dnsmasq接管服务。

一、问题

Shell下有时需要使用随机数,在此总结产生随机数的方法。计算机产生的的只是“伪随机数”,不会产生绝对的随机数(是一种理想随机数)。伪随机数在大量重现时也并不一定保持唯一,但一个好的伪随机产生算法将可以产生一个非常长的不重复的序列。

由于 linuxqq 是用 electron 写的,而且目前还有一些 bug, 当点击关闭按钮后程序仍然在后台运行。但是,想重新登录一下,却提示已经登录,而原来的聊天界面又找不到,所以必须完全关闭,然后再重新启动才行。 解决方法是借助pgrep打印所有相关进程,然后一同kill, 命令为

由于工作和学习的需要,可能需要同时在一台电脑上维护多个 github 帐号,这时使用 Github-cli 同时使用多个帐号的 Token 认证后,然后就可以随时切换了。具体方法为:

登录认证帐号

1
gh auth login -p ssh --skip-ssh-key --with-token < your_token_here >
注意: 这条命令选择了 ssh的认证方式,所以需要提前配置好 ssh. 同时按 使用Github-Cli管理仓库 取得 Token.

切换帐号

1
gh auth switch -u < your_name_here >

gh auth 选项详解

 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
Authenticate with a GitHub host.

The default hostname is `github.com`. This can be overridden using the `--hostname`
flag.

The default authentication mode is a web-based browser flow. After completion, an
authentication token will be stored securely in the system credential store.
If a credential store is not found or there is an issue using it gh will fallback
to writing the token to a plain text file. See `gh auth status` for its
stored location.

Alternatively, use `--with-token` to pass in a personal access token (classic) on standard input.
The minimum required scopes for the token are: `repo`, `read:org`, and `gist`.

Fine-grained personal access tokens are not supported.

Alternatively, gh will use the authentication token found in environment variables.
This method is most suitable for "headless" use of gh such as in automation. See
`gh help environment` for more info.

To use gh in GitHub Actions, add `GH_TOKEN: ${{ github.token }}` to `env`.

The git protocol to use for git operations on this host can be set with `--git-protocol`,
or during the interactive prompting. Although login is for a single account on a host, setting
the git protocol will take effect for all users on the host.

Specifying `ssh` for the git protocol will detect existing SSH keys to upload,
prompting to create and upload a new key if one is not found. This can be skipped with
`--skip-ssh-key` flag.

For more information on OAuth scopes, <https://docs.github.com/en/developers/apps/building-oauth-apps/scopes-for-oauth-apps/>.


USAGE
  gh auth login [flags]

FLAGS
  -p, --git-protocol string   The protocol to use for git operations on this host: {ssh|https}
  -h, --hostname string       The hostname of the GitHub instance to authenticate with
      --insecure-storage      Save authentication credentials in plain text instead of credential store
  -s, --scopes strings        Additional authentication scopes to request
      --skip-ssh-key          Skip generate/upload SSH key prompt
  -w, --web                   Open a browser to authenticate
      --with-token            Read token from standard input

INHERITED FLAGS
  --help   Show help for command

EXAMPLES
  # Start interactive setup
  $ gh auth login
  
  # Authenticate against github.com by reading the token from a file
  $ gh auth login --with-token < mytoken.txt
  
  # Authenticate with specific host
  $ gh auth login --hostname enterprise.internal

LEARN MORE
  Use `gh <command> <subcommand> --help` for more information about a command.
  Read the manual at https://cli.github.com/manual
  Learn about exit codes using `gh help exit-codes`

参考文章

在编写脚本时避免不了使用密码,所以为了增强安全性,需要使用加密解密技术。本文记录几种加密解密的方法。

Python 与 Bash Shell 的结合

这个命令会让你输入一个字符串,然后会再输出一串加密了的数字.

在 Markdown 中添加目录(Table of Contents, ToC)并不是直接支持的功能,但是你可以手动创建一个简单的目录,使用链接和锚点来指向文档中的各个部分。首先,在你想链接到的标题或段落前设置一个锚点(ID),然后在目录部分创建指向这些锚点的链接。例如:

在 Shell 脚本中避免输入 sudo 密码的方法有几种,但每种方法都有其适用场景和安全考量。以下是几种常见的方法:

1. 修改 /etc/sudoers 文件

你可以编辑 /etc/sudoers 文件(推荐使用 visudo 命令以确保语法正确),为特定用户或用户组添加不需要密码的权限。

GitHub CLI 简介

GitHub CLI 是一个用于通过命令行与 GitHub 进行交互的强大工具。它允许开发者和用户管理存储库、拉取请求、问题和其他 GitHub 资源,而无需离开终端。

主要功能

  1. 仓库管理:创建、克隆、列出和删除仓库。
  2. 拉取请求:查看、创建、合并和关闭拉取请求。
  3. 问题跟踪:创建、列表、评论和关闭问题。
  4. 项目管理:管理和操作 GitHub Projects。
  5. 代码审查:检查更改、提交评论和批准或拒绝拉取请求。
  6. 扩展性:支持通过脚本和插件进行扩展。

安装 Github-Cli

1
sudo pacman -S github-cli

基本使用

在 GitHub 上取得 Personal Access Token

1. 登录 GitHub 账户

  • 打开 GitHub 并使用你的凭据登录。

2. 进入开发者设置

  • 点击右上角的头像图标。
  • 从下拉菜单中选择 Settings。

3. 导航到“Developer settings”

  • 在左侧边栏中找到并点击 Developer settings。

4. 生成新的个人访问令牌

  • 在 Developer settings 中,点击 Personal access tokens。

  • 点击 Tokens (classic) 或 Fine-grained tokens,具体取决于你需要的权限范围。

    • 如果选择 Tokens (classic):
      • 点击 Generate new token。
      • 填写令牌描述。
      • 选择所需的权限范围(例如,repo 表示对仓库的完全控制)。
      • 点击 Generate token。
    • 如果选择 Fine-grained tokens:
      • 点击 Generate new token。
      • 填写令牌名称和描述。
      • 配置资源访问权限(例如,特定组织或仓库)。
      • 配置所需的作用域(例如,读取和写入仓库)。
      • 点击 Generate token。
  • 如果您需要取得对仓库的所有权限,则选择Tokens(classic), 如果仅需要有限的权限,则选择Fine-grained tokens。 一般只有自己使用系统时,使用所有权限更方便。

安装好 Pandoc

详细可以参考 Pandoc - Installing pandoc 。

先安装依赖软件wkhtmltopdf

1
paru -S wkhtmltopdf

官网上给出的简单的不修改格式的将 Markdown 转换为 PDF 命令如下:

1
pandoc file.md -f markdown -t html -o index.pdf

参考文章