[{"content":"有时，文章中需要添加视频作为演示内容，而 hugo 默认不支持展示视频。虽然可以使用工具将其转换为 GIF 或者WEBP，但会增加文件大小或者降低画质。好在 hugo 可以使用 shortcodes 来支持视频\n添加模板 在主题目录或项目目录下的 layouts/shortcodes 创建 video.html 文件，向文件中添加下面代码\n{{- $src := .Get \u0026#34;src\u0026#34; | default (.Get 0) -}} \u0026lt;div class=\u0026#34;video-wrapper\u0026#34;\u0026gt; \u0026lt;video src=\u0026#34;{{- $src -}}\u0026#34; autoplay=\u0026#34;true\u0026#34; loop=\u0026#34;true\u0026#34; muted=\u0026#34;true\u0026#34; playsinline=\u0026#34;true\u0026#34; loading=\u0026#34;lazy\u0026#34; controls=\u0026#34;true\u0026#34;\u0026gt; \u0026lt;p\u0026gt; Your browser doesn\u0026#39;t support HTML5 video. Here is a \u0026lt;a href=\u0026#34;{{- $src -}}\u0026#34;\u0026gt;link to the video\u0026lt;/a\u0026gt; instead. \u0026lt;/p\u0026gt; \u0026lt;/video\u0026gt; \u0026lt;/div\u0026gt; 完整语法较为复杂，这里简单介绍如何获取参数。主要分成两种情况：\n有属性名时，使用属性名读取： .Get \u0026quot;src\u0026quot; ； 没有属性名时，通过索引获取：.Get 0。 这样文章才能既支持有属性名 src，又支持没有属性名两种写法。\n嵌入文章 在文章中使用下面代码嵌入视频\n{{\u0026lt; video \u0026#34;/input.mov\u0026#34; \u0026gt;}} 或者 {{\u0026lt; video src=\u0026#34;/input.mov\u0026#34; \u0026gt;}} 类似于 html 语言中的标签语法，取决语模板文件中的代码如何编写\n固定格式：{{}}，代表在当前位置嵌入 shortcode 标签名：\u0026lt;video\u0026gt;，其中 video 为模板名 参数：可以添加属性名，也可以不添加 \u0026quot;/input.mov\u0026quot;、src=\u0026quot;/input.mov\u0026quot; 如果需要在文章中直接显示源码，可以在标签中添加 /**/。完整写法：\n{{\u0026lt;/* video src=\u0026#34;/input.mov\u0026#34; */\u0026gt;}} // 显示注释 {{\u0026lt;/*/* video src=\u0026#34;/input.mov\u0026#34; */*/\u0026gt;}} 参考 shortcodes template","permalink":"https://podul.cn/posts/to-use-shortcode-embed-video-in-hugo/","summary":"有时，文章中需要添加视频作为演示内容，而 hugo 默认不支持展示视频。虽然可以使用工具将其转换为 GIF 或者WEBP，但会增加文件大小或者降低画质。好在 hugo 可以使用 shortcodes 来支持视频","title":"hugo使用shortcode嵌入视频"},{"content":"起因 使用 UITextView 实现富文本编辑器，给一行文本中局部添加不同样式，再继续输入时，局部样式会被自动覆盖。效果如下：\n您的浏览器不支持 HTML5 视频。 检查 textStorage 后发现原有样式被覆盖，怀疑输入文字后，样式在某个时刻发生了改变。\n寻找原因 自定义一个 testStorage，添加断点查看变更时机。代码如下：\nclass TextStorage: NSTextStorage { private let store = NSMutableAttributedString() override var string: String { store.string } override var mutableString: NSMutableString { store.mutableString } override func replaceCharacters(in range: NSRange, with str: String) { beginEditing() store.replaceCharacters(in: range, with: str) edited(.editedCharacters, range: range, changeInLength: str.count - range.length) endEditing() } override func setAttributes(_ attrs: [NSAttributedString.Key : Any]?, range: NSRange) { beginEditing() store.setAttributes(attrs, range: range) edited([.editedAttributes], range: range, changeInLength: 0) endEditing() } override func attributes(at location: Int, effectiveRange range: NSRangePointer?) -\u0026gt; [NSAttributedString.Key : Any] { store.attributes(at: location, effectiveRange: range) } } private let textView: UITextView = { // 创建自定义的 NSTextStorage let customTextStorage = TextStorage() // 创建 NSLayoutManager 和 NSTextContainer let layoutManager = NSLayoutManager() customTextStorage.addLayoutManager(layoutManager) let textContainer = NSTextContainer(size: .zero) layoutManager.addTextContainer(textContainer) return UITextView(frame: .zero, textContainer: textContainer) }() // 初始样式设置 textView.text = \u0026#34;sjldkfsldfkljl\u0026#34; textView.textStorage.addAttribute(.backgroundColor, value: UIColor.purple, range: NSRange(location: 0, length: textView.text.count)) textView.textStorage.addAttribute(.backgroundColor, value: UIColor.red, range: NSRange(location: 0, length: textView.text.count - 1)) 运行后，输入 o，会先执行 replaceCharacters 方法，再执行 setAttributes 方法，看起来一切正常。\n继续执行后，又执行了 replaceCharacters 方法和 setAttributes 方法，而且替换了整个文本？\n第一次执行时能看到是键盘插入了文本，应该是正常运行的。\n第二次是 _performTextCheckingAnnotationOperations 方法，怀疑是哪个属性需要调整，\n到 UITextView 的定义中查找，没有找到\n可能是在协议中定义的，顺着继承链往下找，在 UITextInputTraits 协议中找到了一个可能的属性，查看其默认值为 yes，遂将其改为 no 试试\ntextView.spellCheckingType = .no 修改之后重新运行，发现恢复正常了？\n总结 使用 UITextView 在 iOS 中运行时正常；使用 AppKit 中的 NSTextView 时，也正常。但使用 UITextView 在 Mac Catalyst 环境运行时，却出现问题，一度怀疑是苹果的 BUG，没想到是特性。\n结论 关闭拼写检查textView.spellCheckingType = .no 后，运行正常。\ntextView.spellCheckingType = .no textView.text = \u0026#34;sjldkfsldfkljl\u0026#34; textView.textStorage.addAttribute(.backgroundColor, value: UIColor.purple, range: NSRange(location: 0, length: textView.text.count)) textView.textStorage.addAttribute(.backgroundColor, value: UIColor.red, range: NSRange(location: 0, length: textView.text.count - 1))","permalink":"https://podul.cn/posts/implement-rich-text-editor-on-maccatalyst/","summary":"起因 使用 UITextView 实现富文本编辑器，给一行文本中局部添加不同样式，再继续输入时，局部样式会被自动覆盖。效果如下：\n您的浏览器不支持 HTML5 视频。","title":"在 MacCatalyst 上使用 UITextView 实现富文本编辑器"},{"content":"在学习其它 app 的优秀功能时，可能需要更深入的了解其功能，此时如果能够对其进行调试可能是很好的方式。\n创建证书 打开 keychain（钥匙串） 导航栏-钥匙串访问-证书助理-创建证书 输入证书名，身份类型选择自签名根证书，证书类型选择代码签名， 点击创建 信任证书，保存 重签名 sudo codesign --deep --force --verify --verbose --sign \u0026#34;cer_name\u0026#34; /Applications/appname.app 注意：会给原 app 重签名，建议复制一份.app文件\n创建 mac framework 工程 打开 xcode 创建 macOS framework 打开 target - Signing \u0026amp; Capabilities 取消自动签名 打开 Build Settings，搜索 Code Signing Identity 选择刚刚的证书 Edit Scheme 选择调试的 app 运行 如果出现以下错误，说明 xcode 工程签名与 app 签名不一致，可能是重签名步骤出现问题","permalink":"https://podul.cn/posts/using-xcode-debug-any-mac-app/","summary":"在学习其它 app 的优秀功能时，可能需要更深入的了解其功能，此时如果能够对其进行调试可能是很好的方式。\n创建证书 打开 keychain（钥匙串） 导航栏-钥匙串访问-证书助理-创建证书","title":"使用 Xcode 调试任意 Mac App"},{"content":"Nodejs 在 v20.0.0 开始支持 Single executable applications (简称：sea)，但流程较为复杂，这篇文章将介绍如何使用它，并提供一个脚本方便使用。\n下面核心代码来自官网，不做过多介绍，这里主要对目录做了调整\n打包代码 # 生成的可执行文件名 EXEC_NAME=\u0026#34;hello\u0026#34; # 入口文件 ENTRY=\u0026#34;index.js\u0026#34; # 临时文件目录 SEA_PATH=\u0026#34;.sea\u0026#34; mkdir -p \u0026#34;$SEA_PATH\u0026#34; # 创建配置文件 echo \u0026#34;{ \\\u0026#34;main\\\u0026#34;: \\\u0026#34;$ENTRY\\\u0026#34;, \\\u0026#34;output\\\u0026#34;: \\\u0026#34;$SEA_PATH/sea-prep.blob\\\u0026#34; }\u0026#34; \u0026gt; \u0026#34;$SEA_PATH/sea-config.json\u0026#34; # Generate the blob that contains your application script node --experimental-sea-config \u0026#34;$SEA_PATH/sea-config.json\u0026#34; # Copy the Node.js binary and name it as needed cp $(command -v node) \u0026#34;$SEA_PATH/$EXEC_NAME\u0026#34; # 注意：下面的代码每个平台都有一点区别，由于笔者使用 macOS，所以只测试过 macOS 下的效果 # 如果是mac，使用下面代码 codesign --remove-signature \u0026#34;$SEA_PATH/$EXEC_NAME\u0026#34; npx postject \u0026#34;$SEA_PATH/$EXEC_NAME\u0026#34; NODE_SEA_BLOB \u0026#34;$SEA_PATH/sea-prep.blob\u0026#34; \\ --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 \\ --macho-segment-name NODE_SEA codesign --sign - \u0026#34;$SEA_PATH/$EXEC_NAME\u0026#34; # 其它平台参考：https://nodejs.org/api/single-executable-applications.html echo \u0026#34;生成的可执行文件在：$SEA_PATH/$EXEC_NAME\u0026#34; 存在问题 如果在使用过程中遇到 SyntaxError: Cannot use import statement outside a module，是因为当前只支持 commonjs ，可以使用 babel 将其转换成 commonjs\nset -e # 先安装依赖 # npm install -D @babel/preset-env @babel/cli # 这里为了方便，直接使用命令行，没有生成 .babelrc 文件 SRC_DIR=\u0026#34;src\u0026#34; BABEL_OUT_DIR=\u0026#34;.babel\u0026#34; mkdir -p \u0026#34;$BABEL_OUT_DIR\u0026#34; npx babel \u0026#34;$SRC_DIR\u0026#34; --out-dir \u0026#34;$BABEL_OUT_DIR\u0026#34; --copy-files --presets=@babel/preset-env 如果只是单个js文件，上面就已经可以了；但如果有依赖，就需要使用 webpack 等打包工具合并成一个js文件了，这里为了方便使用@vercel/ncc。\nset -e NCC_OUT_DIR=\u0026#34;.ncc\u0026#34; mkdir -p \u0026#34;$NCC_OUT_DIR\u0026#34; # 使用ncc打包成一个文件 npx ncc build index.js -o \u0026#34;$NCC_OUT_DIR\u0026#34; 最终代码 set -e # 先安装依赖 # 需要转换成 commonjs # npm install --save-dev @babel/preset-env @babel/cli # 需要打包 # npm install --save-dev @vercel/ncc # 这个必需安装 # npm install --save-dev postject # 入口文件 ENTRY=\u0026#34;src/index.js\u0026#34; # 源文件目录，将转换成 commonjs SRC_DIR=\u0026#34;src\u0026#34; BABEL_OUT_DIR=\u0026#34;.babel\u0026#34; # ncc 打包目录 NCC_OUT_DIR=\u0026#34;.ncc\u0026#34; # 生成的可执行文件名 EXEC_NAME=\u0026#34;hello\u0026#34; # 入口文件，因为使用了 ncc，所以入口文件需要调整路径 ENTRY=\u0026#34;$NCC_OUT_DIR/$(basename \u0026#34;$ENTRY\u0026#34;)\u0026#34; # 临时文件目录 SEA_PATH=\u0026#34;.sea\u0026#34; # 开始： mkdir -p \u0026#34;$BABEL_OUT_DIR\u0026#34; mkdir -p \u0026#34;$NCC_OUT_DIR\u0026#34; mkdir -p \u0026#34;$SEA_PATH\u0026#34; # 1. 转换成 commonjs # 这里为了方便，直接使用命令行，没有生成 .babelrc 文件 npx babel \u0026#34;$SRC_DIR\u0026#34; --out-dir \u0026#34;$BABEL_OUT_DIR\u0026#34; --copy-files --presets=@babel/preset-env # 2. 打包 # 生成一个 package.json，相当于把 babel 转换后的目录当做项目目录 echo \u0026#34;{\\\u0026#34;type\\\u0026#34;: \\\u0026#34;commonjs\\\u0026#34;}\u0026#34; \u0026gt; \u0026#34;$BABEL_OUT_DIR/package.json\u0026#34; ORIGINAL_PWD=$PWD # 切换到 babel 转换后的目录 cd \u0026#34;$BABEL_OUT_DIR\u0026#34; # 入口文件切换到 babel 转换后的目录，因为cd到了babel目录，所以只需要文件名即可 ENTRY=\u0026#34;$(basename \u0026#34;$ENTRY\u0026#34;)\u0026#34; npx ncc build \u0026#34;$ENTRY\u0026#34; -o \u0026#34;$ORIGINAL_PWD/$NCC_OUT_DIR\u0026#34; # 切回原目录 cd - # 3. 生成可执行文件 ENTRY=\u0026#34;$NCC_OUT_DIR/$(basename \u0026#34;$ENTRY\u0026#34;)\u0026#34; # 创建配置文件 echo \u0026#34;{ \\\u0026#34;main\\\u0026#34;: \\\u0026#34;$ENTRY\\\u0026#34;, \\\u0026#34;output\\\u0026#34;: \\\u0026#34;$SEA_PATH/sea-prep.blob\\\u0026#34; }\u0026#34; \u0026gt; \u0026#34;$SEA_PATH/sea-config.json\u0026#34; # Generate the blob that contains your application script node --experimental-sea-config \u0026#34;$SEA_PATH/sea-config.json\u0026#34; # Copy the Node.js binary and name it as needed cp $(command -v node) \u0026#34;$SEA_PATH/$EXEC_NAME\u0026#34; # 注意：下面的代码每个平台都有一点区别，由于笔者使用 macOS，所以只测试过 macOS 下的效果 # 如果是mac，使用下面代码 codesign --remove-signature \u0026#34;$SEA_PATH/$EXEC_NAME\u0026#34; npx postject \u0026#34;$SEA_PATH/$EXEC_NAME\u0026#34; NODE_SEA_BLOB \u0026#34;$SEA_PATH/sea-prep.blob\u0026#34; \\ --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 \\ --macho-segment-name NODE_SEA codesign --sign - \u0026#34;$SEA_PATH/$EXEC_NAME\u0026#34; # 其它平台参考：https://nodejs.org/api/single-executable-applications.html echo \u0026#34;生成的可执行文件在：$SEA_PATH/$EXEC_NAME\u0026#34; # mv $SEA_PATH/$EXEC_NAME . # 先把可执行文件移出来 # 再清除临时目录 # rm -rf \u0026#34;$BABEL_OUT_DIR\u0026#34; # rm -rf \u0026#34;$NCC_OUT_DIR\u0026#34; # rm -rf \u0026#34;$SEA_PATH\u0026#34; 示例地址：https://github.com/podul-examples/nodejs-sea-examples\n需要依赖：\n@babel/cli 可选 @babel/preset-env 可选 @vercel/ncc 可选 postject 必需 存在问题：\n目前整个打包流程较为复杂 不支持交叉打包（也许可以通过复制其它平台的node二进制文件实现） 还在实验中，后面可能移除，也可能调整，有待观察。 打包出来的文件较大 总结 目前存在问题较多，可以使用，但不太建议。可以使用 https://github.com/vercel/pkg 等工具先替代。\n参考 Single executable applications https://github.com/vercel/ncc https://github.com/nodejs/postject https://github.com/vercel/pkg","permalink":"https://podul.cn/posts/nodejs-supported-single-executable-applications/","summary":"Nodejs 在 v20.0.0 开始支持 Single executable applications (简称：sea)，但流程较为复杂，这篇文章将介绍如何使用它，并提供一个脚本方便使用。\n下面核心代码来自官网，不做过多介绍，这里主要对目录做了调整","title":"Nodejs 支持 Single executable applications"},{"content":"最近因为重装了系统，需要重新安装cocoapods，在终端运行 sudo gem install cocoapods 时，等了半天也没动静。\n发现不走终端代理，查看进程后发现没有走终端代理，只有ruby🐢的速度。\n只好另寻它法，仔细检查 gem install 命令后发现添加了一个设置代理的参数。\n这样设置后终于开始下载了\nsudo gem install cocoapods -p [http://127.0.0.1:7890](http://127.0.0.1:7890/)","permalink":"https://podul.cn/posts/to-install-cocoapods-using-proxy/","summary":"最近因为重装了系统，需要重新安装cocoapods，在终端运行 sudo gem install cocoapods 时，等了半天也没动静。\n发现不走终端代理，查看进程后发现没有走终端代理，只有ruby🐢的速度。","title":"安装cocoapods"},{"content":"macCatalyst 中，viewDidLayoutSubviews 方法在窗口活跃时会调用，如果在方法中添加断点，再跳过断点，就会出现无限调用的假象。\n触发断点时，xcode会活跃，应用进入后台；跳过断点时，应用活跃，xcode进入后台","permalink":"https://podul.cn/posts/maccatalyst-viewdidlayoutsubview-repeat-forever/","summary":"macCatalyst 中，viewDidLayoutSubviews 方法在窗口活跃时会调用，如果在方法中添加断点，再跳过断点，就会出现无限调用的假象。","title":"MacCatalyst 中 viewDidLayoutSubviews 无限调用"},{"content":"使用 cloudflare 设置定时器，执行一些需要定时执行的脚本，也可以定时部署 cloudflare page。\n创建项目 登录cloudflare\n点击Workers \u0026amp; Pages\n点击create application\n选择workers，默认已经选择\n点击create worker\n自动生成的代码\nexport default { async scheduled(event, env, ctx) { // 这里改成想要执行的代码 ctx.waitUntil(fetch(env.url, { method: \u0026#34;POST\u0026#34; })); }, }; 部署（Deploy） 设置定时器 部署之后进入详情页 点击设置 Settings - Triggers - Add Cron Trigger 设置触发时间\n环境变量 点击设置 - Variables 找到 Environment Variables，点击 Edit variables 添加变量\n可以选择加密或者不加密，选择加密在读取时不需要解密，只是当前页面不可见。\n变量名可在代码中读取，比如我这里的 url 可以用 env.url 读取\n注意事项 触发时间为国际时间","permalink":"https://podul.cn/posts/using-cloudflare-worker-cron/","summary":"使用 cloudflare 设置定时器，执行一些需要定时执行的脚本，也可以定时部署 cloudflare page。\n创建项目 登录cloudflare\n点击Workers \u0026 Pages\n点击create application\n选择workers，默认已经选择\n点击create worker","title":"使用 cloudflare 定时器"},{"content":"在使用 NotionNext 时，发现有些配置和官方文档上的描述不太一致。\n字段 LINK 不支持 NotionConfig，可以设置环境变量：NEXT_PUBLIC_LINK\n文档上写“站点网址，此处填写您上线后的网址。务必在blog.config.js中配置，因为SiteMap和RSS功能无法从此处读取。”\nTHEME 支持 NotionConfig，但是在Notion修改配置后生成的静态页没有填入数据，变成了前端渲染。\nNotionConfig 文档上写NotionConfig有些配置不支持，但没有说明哪些配置支持，哪些不支持。\n比如我想将 POST_URL_PREFIX 改成 post，在配置中修改后没有生效。\n查看源码后发现，没有使用 siteConfig 方法的字段就不支持。文档地址\n文档截图\n附件 文档上写的支持配置附件（参考上面截图），但默认配置中没有这个字段，不确定有没有支持。\n主题配置 使用sample主题时，有些主题字段支持配置，有些不支持。\nSIMPLE_LOGO_IMG 没有找到使用的地方。\nSIMPLE_TOP_BAR 、SIMPLE_MENU_CATEGORY 等字段没有使用 process.env 进行读取，但用了siteConfig 方法。\nconst CONFIG = { SIMPLE_LOGO_IMG: \u0026#34;/Logo.webp\u0026#34;, SIMPLE_TOP_BAR: true, // 显示顶栏 SIMPLE_TOP_BAR_CONTENT: process.env.NEXT_PUBLIC_THEME_SIMPLE_TOP_TIPS || \u0026#34;\u0026#34;, //.. // 菜单配置 SIMPLE_MENU_CATEGORY: true, // 显示分类 SIMPLE_MENU_TAG: true, // 显示标签 // ... }; export default CONFIG; 总结 使用process.env的字段支持环境变量\n使用siteConfig方法的字段支持NotionConfig\n两种都没有支持，只能直接修改源码，不清楚为什么没有支持。","permalink":"https://podul.cn/posts/notion-next-config/","summary":"在使用 NotionNext 时，发现有些配置和官方文档上的描述不太一致。\n字段 LINK 不支持 NotionConfig，可以设置环境变量：NEXT_PUBLIC_LINK","title":"NotionNext 配置问题"},{"content":"问题描述 当尝试打开 .dmg 文件时，遭遇错误提示：“未能完成该操作。权限被拒绝”。\n系统环境 设备类型：Mac mini 系统安装方式：通过外置硬盘安装操作系统 操作系统版本：macOS Sonoma 14.0 解决方法 首先在终端中执行以下命令：sudo xattr -r -d com.apple.quarantine /path/to/dmg。这将移除文件的隔离属性。完成此操作后，再次尝试打开 .dmg 文件即可。","permalink":"https://podul.cn/posts/resolving-permission-issues-when-opening-dmg-files-on-macos/","summary":"问题描述 当尝试打开 .dmg 文件时，遭遇错误提示：“未能完成该操作。权限被拒绝”。\n系统环境 设备类型：Mac mini 系统安装方式：通过外置硬盘安装操作系统 操作系统版本：macOS Sonoma 14.0 解决方法 首先在终端中执行以下命令：sudo xattr -r -d com.apple.quarantine /path/to/dmg。这将移除文件的隔离属性。完成此操作后，再次尝试打开 .dmg 文件即可。","title":"解决 macOS 上无法打开 DMG 文件的权限问题"},{"content":"Go语言中可以使用第三方库github.com/jlaffaye/ftp 库来实现FTP文件上传。\n安装：\ngo get -u github.com/jlaffaye/ftp 然后，使用以下代码进行文件上传：\npackage main import ( \u0026#34;bytes\u0026#34; \u0026#34;fmt\u0026#34; \u0026#34;github.com/jlaffaye/ftp\u0026#34; \u0026#34;os\u0026#34; \u0026#34;time\u0026#34; ) const ( ftpDirectoryExistsErrorCode = 550 ) func main() { // 连接到FTP服务器，注意：不要写协议 ftp://，需要写端口 21 connection, err := ftp.Dial(\u0026#34;ftp.example.com:21\u0026#34;, ftp.DialWithTimeout(5*time.Second)) if err != nil { fmt.Println(err) return } // 登录 err = connection.Login(\u0026#34;username\u0026#34;, \u0026#34;password\u0026#34;) if err != nil { fmt.Println(err) return } // 打开要上传的文件 file, err := os.Open(\u0026#34;local-file.txt\u0026#34;) if err != nil { fmt.Println(err) return } defer file.Close() // 上传文件 destPath := \u0026#34;/path/on/ftp/server/remote-file.txt\u0026#34; err = mkdirAll(connection, destPath) if err != nil { fmt.Println(err) return } err = connection.Stor(destPath, file) if err != nil { fmt.Println(err) return } // 退出 err = connection.Quit() if err != nil { fmt.Println(err) return } fmt.Println(\u0026#34;File uploaded successfully.\u0026#34;) } // 递归创建目录 func mkdirAll(c *ftp.ServerConn, path string) error { paths := strings.Split(path, \u0026#34;/\u0026#34;) currentPath := \u0026#34;\u0026#34; for _, p := range paths { if p == \u0026#34;\u0026#34; { continue } currentPath += \u0026#34;/\u0026#34; + p if err := ftp.connection.MakeDir(currentPath); err != nil { textProtoErr, ok := err.(*textproto.Error) if !ok { return err } if textProtoErr.Code == ftpDirectoryExistsErrorCode { // 已经存在，不需要创建 continue } return err } } return nil }","permalink":"https://podul.cn/posts/golang-uses-ftp-to-upload-files/","summary":"Go语言中可以使用第三方库github.com/jlaffaye/ftp 库来实现FTP文件上传。\n安装：\ngo get -u github.com/jlaffaye/ftp 然后，使用以下代码进行文件上传：\npackage main import ( \"bytes\" \"fmt\" \"github.com/jlaffaye/ftp\" \"os\" \"time\" ) const ( ftpDirectoryExistsErrorCode = 550 ) func main() { // 连接到FTP服务器，注意：不要写协议 ftp://，需要写端口 21 connection, err := ftp.Dial(\"ftp.example.com:21\", ftp.DialWithTimeout(5*time.Second)) if err != nil { fmt.Println(err) return } // 登录 err = connection.Login(\"username\", \"password\") if err != nil { fmt.Println(err) return } // 打开要上传的文件 file, err := os.Open(\"local-file.txt\") if err != nil { fmt.Println(err) return } defer file.Close() // 上传文件 destPath := \"/path/on/ftp/server/remote-file.txt\" err = mkdirAll(connection, destPath) if err != nil { fmt.Println(err) return } err = connection.Stor(destPath, file) if err != nil { fmt.Println(err) return } // 退出 err = connection.Quit() if err != nil { fmt.Println(err) return } fmt.Println(\"File uploaded successfully.\") } // 递归创建目录 func mkdirAll(c *ftp.ServerConn, path string) error { paths := strings.Split(path, \"/\") currentPath := \"\" for _, p := range paths { if p == \"\" { continue } currentPath += \"/\" + p if err := ftp.connection.MakeDir(currentPath); err != nil { textProtoErr, ok := err.(*textproto.Error) if !ok { return err } if textProtoErr.Code == ftpDirectoryExistsErrorCode { // 已经存在，不需要创建 continue } return err } } return nil }","title":"Golang使用ftp上传文件"},{"content":"在使用 Google Pixel 或其他海外品牌的手机，有时可能会遇到连接 Wi-Fi 但无法访问互联网的问题。一种可能的原因是这些手机在检测网络连接状态时使用的 \u0026ldquo;Captive Portal\u0026rdquo; 检测机制可能与您所在区域的网络环境不兼容。在这种情况下，您可以使用 Android Debug Bridge（ADB）命令来手动更改这些设置。\nCaptive Portal 与网络检测 Captive Portal 是一种网络认证机制。当您连接到一个新的 Wi-Fi 网络时，Android 设备会自动访问一个预设的 URL 来检查网络是否需要额外的登录或认证。然而，这个预设的 URL 在某些地区可能是不可达的，导致设备错误地认为网络无法访问互联网。\n解决步骤 命令行工具：ADB 首先，确保您已经下载并安装了 Android Studio，或单独下载了 ADB 工具。\n开启开发者选项 在进行任何操作之前，请确保您在设备上启用了“开发者选项”并开启了“USB 调试”。\nADB 命令 以下 ADB 命令用于删除和更改 Captive Portal 的检测设置：\nadb shell settings delete global captive_portal_https_url adb shell settings delete global captive_portal_http_url adb shell settings put global captive_portal_http_url http://connect.rom.miui.com/generate_204 adb shell settings put global captive_portal_https_url https://connect.rom.miui.com/generate_204 删除现有设置 这两个命令会删除当前设置的 HTTP 和 HTTPS Captive Portal 检测 URL：\nadb shell settings delete global captive_portal_https_url adb shell settings delete global captive_portal_http_url 添加新设置 这两个命令会设置新的 HTTP 和 HTTPS Captive Portal 检测 URL：\nadb shell settings put global captive_portal_http_url http://connect.rom.miui.com/generate_204 adb shell settings put global captive_portal_https_url https://connect.rom.miui.com/generate_204 这里，http://connect.rom.miui.com/generate_204 和 https://connect.rom.miui.com/generate_204 是 miui 使用的，通常在国内表现较好。\n注意事项 在进行上述操作之前，请确保您已经开启了 Android 开发者选项并启用了 USB 调试。 使用 ADB 命令可能需要一定的技术知识，因此请务必谨慎操作。 参考 https://zhuanlan.zhihu.com/p/472074014","permalink":"https://podul.cn/posts/using-adb-to-solve-wi-fi-connection-issues-on-pixel-or-other-overseas-phones/","summary":"在使用 Google Pixel 或其他海外品牌的手机，有时可能会遇到连接 Wi-Fi 但无法访问互联网的问题。一种可能的原因是这些手机在检测网络连接状态时使用的 “Captive Portal” 检测机制可能与您所在区域的网络环境不兼容。在这种情况下，您可以使用 Android Debug Bridge（ADB）命令来手动更改这些设置。","title":"使用 ADB 解决 Pixel 或其它海外版手机的 Wi-Fi 连接问题"},{"content":"如果你想要永久更改 Safari 的默认用户代理，手动设置用户代理只会在当前标签页生效，需要采取其他方法。以下是在新系统/Safari上实现该目标的步骤：\n手动设置 Safari 用户代理\n首先，在老系统/Safari中，可以使用以下命令来修改默认用户代理：\ndefaults read com.apple.Safari CustomUserAgent \u0026quot;xxxx\u0026quot;\n但是，请注意，在新系统/Safari中，这种方法已经不再生效。\n作为替代方法，在新系统/Safari中，可以使用以下命令来修改默认用户代理：\ndefaults read ~/Library/Containers/com.apple.Safari/Data/Library/Preferences/com.apple.Safari.plist CustomUserAgent \u0026quot;xxx\u0026quot;\n注意：可能会出现没有权限的提示。在这种情况下，你需要为 Terminal 和 defaults 添加全盘访问权限。defaults 位于 /usr/bin/defaults 目录下。\n若要添加权限，请按照以下步骤操作：\n打开“系统偏好设置”。 点击“安全性与隐私”。 在左下角锁形图标下面点击“+”按钮。 在弹出窗口中，选择 Terminal 应用程序，然后点击“打开”。 在权限列表中，确保 Terminal 具有“完全磁盘访问权限”。 重复上述步骤，为 defaults 命令添加相同的权限。 添加权限\n参考链接 https://github.com/mathiasbynens/dotfiles/issues/849#issuecomment-429156104","permalink":"https://podul.cn/posts/editing-safari-default-useragent/","summary":"如果你想要永久更改 Safari 的默认用户代理，手动设置用户代理只会在当前标签页生效，需要采取其他方法。以下是在新系统/Safari上实现该目标的步骤：","title":"修改Safari默认用户代理"},{"content":"在使用 Mac Catalyst 开发时遇到一个奇怪的问题，将 UISplitViewController.Style 设置为 doubleColumn 或者 tripleColumn 时，主控制器总是有一部分内容不显示，而出现在 window 外面。\nwindow?.rootViewController = UISplitViewController(style: .doubleColumn) // window?.rootViewController = UISplitViewController(style: .tripleColumn) 如上图，绿色部分超出 window 范围\n不设置 UISplitViewController.Style 时，显示正常。\n// 不设置 style 时，默认值似乎为 unspecified。但是将 style 设置为 unspecified 又会崩溃。 window?.rootViewController = UISplitViewController() 如上图，绿色部分正常显示\n查阅资料后发现，苹果在 iOS 14 修改了 UISplitViewController 的行为。为了在主控制器显示完整内容，需要使用 safeArea 进行适配。 宛如 iOS 13 时，将 modalPresentationStyle 的默认值改为 pageSheet。\ntableView.snp.makeConstraints { $0.top.bottom.trailing.equalToSuperview() //$0.leading.equalToSuperview() $0.leading.equalTo(view.safeAreaLayoutGuide.snp.leading) } 如图，使用 safeArea 后，粉色的 tableView 显示正常，绿色的 self.view 依旧在游离在 window 之外。\n参考资料 UISplitViewController - doubleColumn Style not working iOS 14 UISplitViewController: 5 Issues That You May Run Into","permalink":"https://podul.cn/posts/problems-encountered-when-using-uisplitviewcontroller-in-mac-catalyst/","summary":"在使用 Mac Catalyst 开发时遇到一个奇怪的问题，将 UISplitViewController.Style 设置为 doubleColumn 或者 tripleColumn 时，主控制器总是有一部分内容不显示，而出现在 window 外面。\nwindow?.rootViewController = UISplitViewController(style: .doubleColumn) // window?.rootViewController = UISplitViewController(style: .tripleColumn)","title":"使用 UISplitViewController 时遇到的问题"},{"content":"在使用 Swift Package Manager（SPM）添加依赖时，可能会遇到下载缓慢或下载失败的情况。即使使用代理软件也无法解决问题，因为 Xcode 使用的是内置的 git 而非系统默认的 git。因此，代理软件或者使用 git config --global http.proxy 的方式并不能起作用。\n鉴于此，有以下几个解决方案：\n方案一：代理 Xcode 内置的 git\n可以使用 proxifier 软件，它可以让指定的进程经过代理。使用起来较为复杂，需要进行一些配置。这里主要介绍第二种方案。\n方案二：切换 Xcode 内置的 git，再配置代理\n使用 defaults write com.apple.dt.Xcode IDEPackageSupportUseBuiltinSCM YES 命令，可以全局切换内置 git。\n切换内置默认 git defaults write com.apple.dt.Xcode IDEPackageSupportUseBuiltinSCM YES 设置代理 如果使用 clash 的话，{yourprox} 默认为 socks5://127.0.0.1:7890 或者 http://127.0.0.1:7890，请根据自己实际使用的代理软件进行调整。 --global 为全局设置，如果只设置当前项目，可移除 --global\n# 设置所有 git config --global http.proxy {yourproxy} \u0026amp;\u0026amp; git config --global https.proxy {yourproxy} # 单独给 Github 配置代理 git config --global http.https://github.com.proxy {yourproxy} \u0026amp;\u0026amp; git config --global https.https://github.com.proxy {yourproxy} 查看刚刚的设置 git config --list --global 恢复默认 defaults write com.apple.dt.Xcode IDEPackageSupportUseBuiltinSCM NO # 若第二步中设置所有，则使用以下命令进行还原 git config --global --unset http.proxy \u0026amp;\u0026amp; git config --global --unset https.proxy # 若第二步中单独设置 Github，则使用以下命令进行还原 git config --global --unset http.https://github.com.proxy \u0026amp;\u0026amp; git config --unset --global https.https://github.com.proxy 参考资料： Configure Git to use a proxy","permalink":"https://podul.cn/posts/resolving-slow-download-issue-of-spm-packages-in-xcode/","summary":"在使用 Swift Package Manager（SPM）添加依赖时，可能会遇到下载缓慢或下载失败的情况。即使使用代理软件也无法解决问题，因为 Xcode 使用的是内置的 git 而非系统默认的 git。因此，代理软件或者使用 git config --global http.proxy 的方式并不能起作用。","title":"解决Xocde下载SPM包缓慢问题"},{"content":"操作飞书表格时，需要将数字转换为对应的表格列名来进行操作。如果表格列数少于26列，直接将数字转换成字母即可。但如果表格列数多于26列，就会复杂一些。\n# 将数字转换成表格列名，从 0 开始 def num_to_column_name(num): # 进行输入参数的判断，要求传入的数字必须大于等于0 assert num \u0026gt;= 0, \u0026#34;必需大于 0\u0026#34; # 将输入数字加1，方便后续的计算 num = num + 1 # 存储最终的列名 column_name = None while num != 0: if column_name == None: # 每次取模26得到当前列名对应的字母，并将其转换为ASCII码后转换为字符 column_name = chr((num - 1) % 26 + 65) else: # 将得到的字符拼接到column_name的前面，因为每次得到的字母是当前列名的最低位，所以需要在前面进行拼接 column_name = chr((num - 1) % 26 + 65) + column_name # 将num除以26取整，得到当前列名对应的前一位数字，继续进行计算 num = int((num - 1) / 26) return column_name","permalink":"https://podul.cn/posts/convert-number-to-excel-column-name/","summary":"操作飞书表格时，需要将数字转换为对应的表格列名来进行操作。如果表格列数少于26列，直接将数字转换成字母即可。但如果表格列数多于26列，就会复杂一些。","title":"数字转表格列名"},{"content":"在日常工作中有一些敏感的数据需要在服务器上进行处理和存储，但是不希望远程用户能够访问和操作这些数据以外的内容。可以使用 ssh 的 command 选项来限制远程用户的权限，只允许他们使用特定的命令来处理和操作数据。通过这种方式，可以有效地限制远程用户的权限，保护敏感数据的安全。\n通过在 authorized_keys 文件中设置该选项，可以使得用户只能执行特定的命令而不能执行其他命令。例如：\n限制单个命令 command=\u0026#34;/usr/local/bin/mycommand\u0026#34; ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxxxxx 限制多个命令 # 修改 `authorized_keys` ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxxxxx # 为 command=\u0026#34;/bin/bash ~/.ssh/limit.sh\u0026#34; ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxxxxx # limit.sh 中的内容 if [[ \u0026#34;$SSH_ORIGINAL_COMMAND\u0026#34; =~ ^supported_command\\ || \u0026#34;$SSH_ORIGINAL_COMMAND\u0026#34; == supported_command ]] then # 继续执行 eval $SSH_ORIGINAL_COMMAND else # 提示不支持此命令 echo \u0026#34;not support $SSH_ORIGINAL_COMMAND\u0026#34;; fi 参考资料： 如何将公钥限制为仅sftp登录 - Linux Shell","permalink":"https://podul.cn/posts/restricting-the-permissions-of-remote-users/","summary":"在日常工作中有一些敏感的数据需要在服务器上进行处理和存储，但是不希望远程用户能够访问和操作这些数据以外的内容。可以使用 ssh 的 command 选项来限制远程用户的权限，只允许他们使用特定的命令来处理和操作数据。通过这种方式，可以有效地限制远程用户的权限，保护敏感数据的安全。","title":"限制远程用户的权限"}]