笔记

🌟 不积跬步,无以至千里 🌟

Alpine Linux 更改时区

查看时区 date -R 安装tzdata依赖 apk add --no-cache tzdata 查看tzdata包含的时区 ls /usr/share/zoneinfo 输出 ls /usr/share/zoneinfo Africa CET Egypt GMT+0 Iran MST7MDT Poland UTC zone.tab America CST6CDT Eire GMT-0 Israel Mexico Portugal Universal zone1970.tab Antarctica Canada Etc GMT0 Jamaica NZ ROC W-SU Arctic Chile Europe Greenwich Japan NZ-CHAT ROK WET Asia Cuba Factory HST Kwajalein Navajo Singapore Zulu Atlantic EET GB Hongkong Libya PRC Turkey iso3166.tab Australia EST GB-Eire Iceland MET PST8PDT UCT posixrules Brazil EST5EDT GMT Indian MST Pacific US right 复制时区文件 如果localtime文件已经存在,可以先备份后删除。...

March 26, 2024 · 1 min · ZhaoGuibin

Github通过sshkey的方式拉取代码报错kex_exchange_identification

Git生成密钥 设定Git的username和email git config --global user.name "你的用户名" git config --global user.email "你的邮箱" 创建SSH key cd ~/.ssh ssh-keygen -t rsa -C "你的邮箱" 会出现以下的提示 Generating public/private rsa key pair. Enter file in which to save the key (~/.ssh/id_rsa): 一路回车默认就可以了,这样你的公钥和私钥就同时保存在了~/.ssh/下了。 获取SSH key cat id_rsa.pub Github添加SSH key 以上都配置了还不行就执行这一步 将 Github 的连接端口从 22 改为 443 即可 编辑 ~/.ssh/config 文件(没有就新增),windows在用户目录下的.ssh目录,添加如下内容 Host github.com HostName ssh.github.com User git Port 443 验证: ssh -T git@github.com 输出 Enter passphrase for key '~/....

March 26, 2024 · 1 min · ZhaoGuibin

ios上使用iSH的git同步iRime

安装软件 安装好以下软件:git、vim、openssh apk add git vim openssh 打开ish设置 设置git git config --global user.name "你注册GitHub账号的名字" git config --global user.email "你注册GitHub账号用的邮箱" 查看公钥 cat ~/.ssh/id_ed25519.pub 如果没有就生成公钥 ssh-keygen -t ed25519 -C "<注释内容>" 再次查看显示公钥,公钥添加到GitHub的SSH keys cat ~/.ssh/id_ed25519.pub 挂载文件夹 会弹出文件夹选择框,选择你要挂载的目录,比如下载目录,确定后即挂载到 /mnt 目录中 mount -t ios . dir_name git设置 #禁用安全目录 git config --global --add safe.directory /path

March 26, 2024 · 1 min · ZhaoGuibin

mac使用fswatch监控文件夹修改并执行shell脚本

安装 fswatch 需要安装 fswatch。可以使用 Homebrew 来安装: brew install fswatch 创建启动脚本 创建一个脚本来启动 fswatch 并执行相应的操作。创建一个脚本文件,比如 watch_files.sh,并添加以下内容: #!/bin/bash # 监视目录中的文件更改并执行脚本 fswatch -0 /path/to/directory | xargs -0 -n 1 /path/to/script.sh 将 /path/to/directory 替换为要监视的目录,将 /path/to/script.sh 替换为要在文件更改时执行的 shell 脚本的路径。 创建启动项 创建一个 Launchd 启动项,以便在系统启动时运行脚本。创建一个 .plist 文件,比如 com.example.watchfiles.plist,并将以下内容添加到文件中: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.example.watchfiles</string> <key>ProgramArguments</key> <array> <string>/bin/bash</string> <string>/path/to/watch_files.sh</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist> 将 com.example.watchfiles 替换为自己的标识符,并将 /path/to/watch_files.sh 替换为您创建的脚本的路径。 安装启动项 将 ....

February 22, 2024 · 1 min · ZhaoGuibin

Golang base64转图片

package main import ( "encoding/base64" "fmt" "io/ioutil" "os" "path/filepath" "strings" ) func main() { // 从命令行参数获取文件夹路径 if len(os.Args) < 2 { fmt.Println("请提供要处理的文件夹路径") return } folderPath := os.Args[1] // 检查文件夹是否存在 _, err := os.Stat(folderPath) if os.IsNotExist(err) { fmt.Println("指定的文件夹路径不存在") return } // 获取上级目录路径 parentFolderPath := filepath.Dir(folderPath) // 获取原始文件夹名称并创建保存图片的文件夹 imageFolderName := filepath.Base(folderPath) + "_image" imageFolderPath := filepath.Join(parentFolderPath, imageFolderName) err = os.Mkdir(imageFolderPath, 0755) if err != nil { fmt.Println("无法创建图片文件夹:", err) return } // 遍历文件夹 err = filepath....

January 3, 2024 · 1 min · ZhaoGuibin

Golang图片转base64

package main import ( "encoding/base64" "fmt" "io/ioutil" "os" "path/filepath" ) func main() { // 从命令行参数获取文件夹路径 if len(os.Args) < 2 { fmt.Println("请提供要处理的文件夹路径") return } folderPath := os.Args[1] // 检查文件夹是否存在 _, err := os.Stat(folderPath) if os.IsNotExist(err) { fmt.Println("指定的文件夹路径不存在") return } // 获取上级目录路径 parentFolderPath := filepath.Dir(folderPath) // 获取原始文件夹名称 base64FolderName := filepath.Base(folderPath) + "_base64" // 创建保存 base64 文件的文件夹 base64FolderPath := filepath.Join(parentFolderPath, base64FolderName) err = os.Mkdir(base64FolderPath, 0755) if err != nil { fmt.Println("无法创建 base64 文件夹:", err) return } // 遍历文件夹 err = filepath....

January 3, 2024 · 1 min · ZhaoGuibin

linux任务按秒执行

#!/bin/bash path=$(dirname "$PWD") php_bin="/usr/local/php/bin/php" while true; do cd $path && $php_bin think crontab_1 && $php_bin think crontab_2 # 等待五秒钟 sleep 5 done

January 3, 2024 · 1 min · ZhaoGuibin

图片转base64

<?php /** * Describe: 图片转base64 * 使用方法: php imgtobase64.php path=/www/projects/test/20220623171931.png * Author: ZhaoGuibin * Date: 2022-06-23 */ class ImgToBase64 { static private $instance; private function __construct() { } static public function getInstance() { if (!self::$instance instanceof self) { self::$instance = new self(); } return self::$instance; } /** * 获取命令行输入参数 * @return array */ function getClientArgs() { global $argv; array_shift($argv); $args = array(); array_walk($argv, function ($v, $k) use (&$args) { @list($key, $value) = @explode('=', $v); $args[$key] = $value; }); return $args; } /** * 图片转为base64 * @param $img_path * @return string|void */ function imgToBase64($img_path = '') { $img = isset($img_path['path']) ?...

July 20, 2022 · 1 min · ZhaoGuibin

迭代器模式

概念 迭代器模式是遍历集合的成熟模式,迭代器模式的关键是将遍历集合的任务交给一个叫做迭代器的对象,它的工作是遍历并选择序列中的对象,而客户端程序员不必知道或关心该集合序列底层的结构。 说明 迭代器模式(Iterator),又叫做游标(Cursor)模式,提供一种方法访问一个容器(Container)对象中各个元素,而又不需要暴露该对象的内部细节。 当你需要访问一个聚合对象,而且不管这些对象是什么都需要遍历的时候,就应该考虑使用迭代器模式。另外,当需要对聚集有多种方式遍历时,可以考虑去使用迭代器模式。迭代器模式为遍历不同的聚合结构提供如开始、下一个、是否结束、当前哪一项等统一的接口。 作用 我们想要像遍历数组那样,遍历对象,或是遍历一个容器。 迭代器模式可以隐藏遍历元素所需的操作 应用场景 访问一个聚合对象的内容而无需暴露它的内部表示 支持对聚合对象的多种遍历 为遍历不同的聚合结构提供一个统一的接口。 角色 Iterator(迭代器):迭代器定义访问和遍历元素的接口 ConcreteIterator(具体迭代器):具体迭代器实现迭代接口,对该聚合遍历时跟踪当前位置 Aggregate(聚合):聚合定义创建相应迭代器对象的接口。 ConcreteAggregate(具体聚合):具体聚合实现创建相应迭代器的接口,该操作返回ConcreteIterator的一个适当的实例。 <?php //自定义迭代器实现系统定义迭代器接口 class MyIterator implements Iterator { protected $data = []; protected $index; public function __construct($data) { $this->data = $data; $this->index = 0; } //返回第一个元素 public function rewind() { $this->index = 0; } //下一个元素 public function next() { $this->index++; } //验证是否继续 public function valid() { return $this->index < count($this->data); } //返回key值 public function key() { return $this->index; } //返回当前元素 public function current() { return $this->data[$this->index]; } } $arr = [1, 2, 3, 4, 5, 6]; $iterate = new MyIterator($arr); foreach ($iterate as $dynasty) { echo 'the obj == ' ....

March 26, 2022 · 1 min · ZhaoGuibin

命令模式

概念 将一个请求封装(命令的封装)为一个对象,从而使用你可用不同的请求对客户进行参数化;对请求排队或记录请求日志,以及支持可撤销的操作。 命令模式是对命令的封装。命令模式把发出命令的责任和执行命令的责任分隔开,委派给不同的对象。 请求的一方发出请求要求执行一个操作;接收的一方收到请求,并执行操作。命令模式允许请求的一方和接收的一方独立开来,使得请求的一方不必知道接收请求的一方的接口,更不必知道请求是怎么被接收,以及操作是否被执行、何时被执行,以及是怎么被执行的。 角色 命令(command)角色:声明了一个给所有具体命令类的抽象接口。这是一个抽象角色。 具体命令(ConcreteCommand)角色:定义一个接收者和行为之间的弱耦合;实现Execute()方法,负责调用接收到的相应操作。Execute()方法通常叫做执行方法。 客户(client)角色:创建了一个具体命令(ConcreteCommand)对象并确定其接收者。 请求者(Invoker)角色:负责调用命令对象执行请求,相关的方法叫做行动方法。 接收者(Receiver)角色:负责具体实施和执行一个请求。任何一个类都可以成为接收者,实施和执行请求的方法叫做行动方法。 优点和缺点 优点: 命令模式把请求一个操作的对象与知道怎么执行一个操作的对象分离开。 命令类与其他任何别的类一样,可以修改和推广。 可以把命令对象聚合在一起,合成为合成命令。 可以很容易的加入新的命令类。 缺点: 可能会导致某些系统有过多的具体命令类。 应用场景 抽象出待执行的动作以参数化对象。Command模式是回调机制的一个面向对象的替代品。 在不同的时刻指定、排列和执行请求。 支持取消操作 支持修改日志 用构建在原语操作上的高层操作构建一个系统。Command模式提供了对事务进行建模的方法。Command有一个公共的接口,使得你可以用同一种方式调用所有的事务。同时使用该模式也易于添加新事务以扩展系统。 <?php //抽象命令接口 interface Command { //命令执行 public function execute(); } //宏命令(命令的组合) //宏命令接口 interface MacroCommand extends Command { //宏命令聚集管理方法,可以删除一个命令 public function remove(Command $command); //宏命令聚集管理方法,可以添加一个命令 public function add(Command $command); } //命令的实现 //复制命令 class CopyCommand implements Command { private $receiver; public function __construct(Receiver $receiver) { $this->receiver = $receiver; } public function execute() { $this->receiver->copy(); } } //粘贴命令 class PasteCommand implements Command { private $receiver; public function __construct(Receiver $receiver) { $this->receiver = $receiver; } public function execute() { $this->receiver->paste(); } } //命令接收者执行命令 class Receiver { private $name; public function __construct($name) { $this->name = $name; } public function copy() { echo $this->name ....

March 26, 2022 · 2 min · ZhaoGuibin