普通视图

发现新文章,点击刷新页面。
今天 — 2025年3月28日首页
昨天以前首页

如何使用 GDB 或 LLDB 调试器重复运行程序直到错误


gdb-debugger 如何使用 GDB 或 LLDB 调试器重复运行程序直到错误 gdb / lldb 小技巧 程序员 编程 计算机 计算机 调试

GDB Debugger 调试器

如何使用 GDB 或 LLDB 调试器重复运行程序直到发生错误

在调试程序时,有时候我们希望一直运行程序直到遇到错误。GDB(GNU 调试器)和 LLDB(LLVM 调试器)都提供了自动化此过程的方法。

这在调试一些不稳定的程序非常有用,例如有时候写的一些单元测试可能随机崩溃SegFault。最近我在调试一个测试每跑1000次就有一次崩溃的时候就发现gdb/lldb调试器非常有用。

简介:GDB vs LLDB

GDB(GNU 调试器)和 LLDB(LLVM 调试器)是用于低级别应用程序调试的强大工具。GDB 传统上用于由 GCC 编译的程序,而 LLDB 是 LLVM 项目的一部分,与 Clang 无缝配合。两者都提供强大的功能,但 GDB 在 Linux 环境中更常见,而 LLDB 在 macOS 上以及处理 Swift 时更受青睐。

自动化执行直到发生错误

调试重复性任务可能很乏味。通过自动化这些任务,直到发生错误,可以节省大量时间和精力。以下是如何在 GDB 和 LLDB 中设置重复执行直到遇到错误的步骤。

GDB 脚本

下面是一个 GDB 脚本,它会重复执行,直到发生错误:

repeat_until_error.gdb

while 1
  run
  if $_exitcode != 0
    echo "发生错误,退出码:$_exitcode\n"
    break
  end
end

要运行此脚本,将其保存为 repeat_until_error.gdb,然后使用以下命令执行 GDB:

gdb -q -x repeat_until_error.gdb ./your_program

或者,当你处于 gdb 提示符时,运行:

source repeat_until_error.gdb

“run” 命令用于启动程序,你可以为它添加参数,例如:

run param1 param2 ...

你也可以使用 “r” 作为 “run” 的简写。

LLDB 脚本

类似地,在 LLDB 中,你可以使用以下脚本实现相同的效果:

repeat_until_error.lldb

while (1)
  run
  process launch
  if (process status != 0)
    script print("发生错误,退出码:", lldb.process.GetExitStatus())
    break
  end
end

要运行此脚本,将其保存为 repeat_until_error.lldb,然后运行:

lldb --source repeat_until_error.lldb ./your_program

或者,在 lldb 提示符处运行:

source repeat_until_error.lldb

在 “run” 命令之后,你还可以通过附加参数来启动程序,例如:

run param1 param2

总结

GDB 和 LLDB 都提供了方便的方法来自动化调试任务,选择使用哪种工具通常取决于你所使用的平台和工具链。GDB 与 GCC 的集成使其成为 Linux 开发者的首选,而 LLDB 在与 Clang 和 macOS 的无缝配合方面同样强大。

自动化重复的调试命令可以为你节省大量时间和精力 —— 无论你使用 GDB 还是 LLDB,这些脚本都能帮助你简化工作流程。

gdb / lldb 调试

英文:How to Repeat Until Errors using GDB or LLDB Debugger?

本文一共 603 个汉字, 你数一下对不对.
如何使用 GDB 或 LLDB 调试器重复运行程序直到错误. (AMP 移动加速版本)

扫描二维码,分享本文到微信朋友圈
75a5a60b9cac61e5c8c71a96e17f2d9c 如何使用 GDB 或 LLDB 调试器重复运行程序直到错误 gdb / lldb 小技巧 程序员 编程 计算机 计算机 调试
The post 如何使用 GDB 或 LLDB 调试器重复运行程序直到错误 first appeared on 小赖子的英国生活和资讯.

相关文章:

  1. 按揭贷款(房贷,车贷) 每月还贷计算器 去年给银行借了17万英镑 买了20万7500英镑的房子, 25年还清. 前2年是定率 Fix Rate 的合同 (年利率2.49%). 每个月大概是还 700多英镑. 有很多种还贷的计算方式, 定率/每月固定 是比较常用的. 简单来说就是 每个月交的钱是...
  2. 智能手机 HTC One M9 使用测评 虽然我对手机要求不高, 远远没有像追求VPS服务器一样, 但是怎么算来两年内换了四个手机, 先是三星 S4 用了一年多, 然后 Nokia Lumia 635 Windows Phone, 后来又是 BLU, 半年多前换了...
  3. 同一台服务器上多个WORDPRESS站点的一些设置可以移出去 我自从把所有网站都挪到一处VPS服务器上 就发现很多事情省事很多 可以同时管理多个网站 包括 WORDPRESS博客. 比如我有四个WORDPRESS博客 然后我就把通用的一些资料给移出去 移到 HTTP或者HTTPS都不能直接访问的文件夹里这样就更安全许多. 文件 wp-conn.php 存储了 相同的数据库资料. 1 2...
  4. 比特币最近波动有点大: 一天牛市一天熊 比特币10万美金以内都是最后上车的机会! 比特币近期的价格波动可以归因于多个关键因素,包括地缘政治动态、监管变化以及加密行业内的重大安全事件。其中一个主要影响因素是美国前总统唐纳德·特朗普对乌克兰和加密货币监管的立场变化。据报道,特朗普再次当选,他可能会推动减少美国对乌克兰的支持,这可能会影响全球金融市场和风险偏好。同时,特朗普正在将自己塑造为亲加密货币的候选人,表示有意让美国成为一个更加友好的加密货币环境。这一立场引发了市场对监管政策可能发生变化的猜测,导致市场情绪在乐观和不确定性之间波动。 特朗普对俄乌战争的态度 美国第43届总统唐纳德·特朗普已经在2025年1月当选并正式上任(第二次),那么他的政策可能会对比特币价格的波动产生更加直接和显著的影响。他政府对乌克兰和加密货币监管的立场已经不再是猜测,而是正在实际塑造市场的关键力量。 特朗普(Donald Trump)减少美国对乌克兰的支持,全球投资者可能会预期地缘政治稳定性发生变化,从而增加对比特币作为避险资产的需求。同时,他的亲加密货币立场可能正在推动市场的乐观情绪。如果他的政府推出有利于加密行业的监管政策,例如明确的合规指南或减少监管审查,可能会吸引更多机构投资者进入市场,并促进更广泛的加密货币采用。然而,政策的快速变化也可能导致短期市场剧烈波动,因为市场需要时间来消化新的政策动向。 朝鲜黑客盗取Bybit交易所15亿美元的ETH 另一个显著影响比特币价格的事件是近期涉及朝鲜黑客组织“Lazarus”的15亿美元以太坊被盗案件。据报道,Bybit交易所(全球第二)这些被盗的ETH已经被清洗,此次大规模黑客攻击引发了人们对加密行业安全性的担忧。此类安全事件不仅会削弱投资者信心,还可能引发更严格的监管审查,导致短期市场动荡。此外,被盗资金的大规模流动和出售可能对市场流动性造成冲击,进一步加大价格波动。随着这些事件的持续发酵,比特币价格正受到政治决策、监管预期以及安全挑战等多重因素的影响。 与此同时,与朝鲜黑客组织 Lazarus 相关的 15 亿美元以太坊被盗事件仍在影响加密市场。由于这些被盗 ETH 已被清洗,人们对加密行业安全漏洞的担忧持续存在,同时也可能引发更严格的监管审查。政治、监管和安全等多重因素交织在一起,共同导致了比特币近期的剧烈价格波动。...
  5. 公司给配了台高配DELL笔记本 早上例会结束的时候我顺便说了一句 我的笔记本有点慢, 当时我并不知道我的经理远程用电话也参加会议了(他全程在听), senior staff SE 对着电话说, “peter, you hear that? btw, my disks are...
  6. 5美元的 Raspberry PI – Zero 树莓PI Raspberry PI 来自于英国, 从第一代模型 A, 到后来的 B, B+ 甚至 是2代, 休积都很小 价钱也一直在 30美元左右. 当然在英国会贵一点 大概在...
  7. 英国硬盘数据恢复失败的经验和教训 上一周, 不小心触碰了机箱后面的电源线, 接触不良, 结果机器再也开不起来了. 显示 Invalid Disk, Replace. 大概就是主硬盘MBR区坏了. 我以为是接触不良, 于是反复插把硬盘卡槽好几次, 机器认不出, 硬盘也没声音, 于是便网上搜索了一个剑桥评价最高的 硬盘数据恢复公司...
  8. 优化设计 个人主页 并且 PageSpeed Insights 双项 100分 坛子的个人主页 www.tanzhijun.com 不错 很适合个人主页的模板. 而且是手机友好. 于是我照着把 我的主页改了改. https://steakovercooked.com 并且做了几点修改: 0. 使用 google mod_pagespeed 把 JS,...

The Lack of Mac Games Is Apple’s Own Fault

作者 Sydney Butler
2025年3月15日 04:00

Macs used to have no end of gaming options, until about the turn of the century. Since then, gaming on a Mac has been a bit of a joke at Apple's expense. However, in recent years, things have taken a turn for the better, with Apple making many moves that should result in more games coming to its platform,

PIVOT Vol.13

作者 Dayu
2025年2月27日 22:16

本刊物不定期发布,推荐通过 RSS 订阅:https://anotherdayu.com/feed/

IMG_1488.jpg

「Dokploy」

Vercel 和 Netlify 的替代品,更简单的部署 Docker 应用。

|

「Edouard Klein / falsisign」

很多机构,特别是政府机构,不接受数字签名,而签名扫描的打印件可以。这个开源工具可以让 PDF 文件看起来像打印、签名然后重新扫描过一样。

|

「Shift-Z:键盘上的超级启动按键」

Shift-Z 这个启动键确实挺不错的,用了几天很舒服。

|

JoeanAmier/XHS-Downloader

可以从小红书上下载无水印的作品文件。

|

「Watch to 5K」

这是一个跑步教练软件,帮助用户培养运动习惯,直到能一次性不中断跑5km。

一般会计划每周跑3-4次,散步+跑步交替,一点点加量。2-3个月之后帮助训练者恢复成能单次跑5km的程度。之后还有10km的扩充计划,循序渐进,挺好的。。

| 「Does spatial distribution heterogeneity exist in video games: Evidence from Genshin Impact’s map」

这篇研究论文通过对《原神》游戏地图的空间分布异质性进行定量分析,探讨了虚拟世界中的空间特征。结果表明,虚拟游戏世界确实存在空间分布异质性,但其模式比现实世界更加简单和规整。

关联:PIVOT Vol.9 组会分享什么?一些有趣的科研论文

|

「The Pivot」

发现了一个公共卫生领域的播客也叫 PIVOT,缘分啊。

|

「Gender differences in the relationship between mental health and academic performance among undergraduate students at a medical school in Shanghai: a cross-sectional study」

医学教育学相关研究,探讨性别差异在心理健康与学业表现之间的关系。女大学生心理健康状况不良与学业成绩较差显著相关,SCL-90量表六个维度与学业成绩之间存在剂量依赖关系。相比之下,男性学生中未观察到类似结果。这表明性别在心理健康与学业表现的关系中起着重要作用,需进一步挖掘多维度心理健康对学生学业的影响。

|

「okooo5km/HiPixel」

macOS 原生应用程序,利用AI技术进行图像超分辨率处理。

|

「morriswmz/phd-game」

基于随机事件的文本类游戏引擎,模拟PhD学生的生活经历。

|

「Wittgenstein and Word2vec: Capturing Relational Meaning in Language and Thought」

这篇文章探讨了语言意义的本质,通过比较维特根斯坦的语言游戏理论、Word2vec 自然语言处理模型和细胞生物学中的概念映射,展示了概念间关系性意义的重要性。作者认为,通过在多维空间中测量概念之间的”距离”,我们可以更好地理解和表达意义,这种方法不仅适用于语言,还可能反映了人类思考的基本方式。

PIVOT Vol.11 推荐几个macOS软件

作者 Dayu
2025年1月12日 21:34

本刊物不定期发布,推荐通过 RSS 订阅:https://anotherdayu.com/feed/

IMG_1488.jpg

推荐几个最近用着很舒服的 macOS 软件!

Mailmate,朋友推荐的一款 macOS IMAP 电子邮件客户端,日常价格为每 3 个月 10 美元,前几天可以 1 美元购买 3 个月的使用权限(已过期),就试了试,结果非常惊喜。付费期限结束后,会自动转为免费版,似乎也够日常使用(还未测试)。很踏实的设计风格,比 Apple mail 和 Spark 细节好很多。如下图,如果邮件中提到了 attachment,但没有添加附件,还会提醒。

telegram-cloud-photo-size-5-6334830467156657640-x.jpg

Kinopio,一款画板软件,风格比较独特,可以分享页面,并嵌入网页,示例:第一次中距离徒步 Yr Wyddfa。从 Obsidian 转出后,偶有画板需求,但不想再额外使用一个笔记软件,就会用 Excalidraw,但 Excalidraw 稍有些粗糙。Kinopio 则刚刚好,网页版轻量化,还能导出为 Obsidian 的 JSON Canvas file format 格式和 PDF,易于储存和索引。

CleanShot 2025-01-12 at 19.08.38@2x.png

new file menu,为 macOS 右键菜单增加新建文件的功能。类似的软件有很多,但部分在系统更新后失效,这款则比较稳定简单。

Trickster,快速索引近期访问的文件,优点是能索引 Devonthink 等软件内部的文件。

CleanShot 2025-01-12 at 21.17.34@2x.png

codepiper,自动复制 macOS 中的短信验证码,很易用。

Rapidmg,macOS 安装 DMG 文件时的拖拽流程比较累赘,这个软件则省去了该步骤。

FluentRead,Firefox插件,类似于沉浸式翻译,优点是开源,设置界面简洁舒适。缺点是目前没有一键全网页翻译,只有段落翻译快捷键。

Do not play 100% Orange Juice on Linux or Steam Deck

作者 石樱灯笼
2024年12月14日 21:38

TL;DR: The Developers in charge of Steam Cloud Save File Sync for 100% Orange Juice don’t know how to handle it. They may mess up your save files, and you may be unaware of it until the loss is done.

Notice: This advice may become obsolete in the future.

Notice 2: English isn’t my native tongue.

Developers are stubborn.


I will use 100oj as 100% Orange Juice for short.

100oj is a beloved game. I declare it as the best online board game ever, with no hesitation.

The Beginning of Playing 100oj on Linux

The very original 100oj is surely made for Windows.

The earliest Steam page capture from web.archive.original

screenshot_on_b85m_by_flameshot_at_2024-12-13_17-40-21

Meanwhile, Valve is making Steam OS, and then, Steam Deck. Proton made Playing Windows Games on Linux become a real thing. (Nah, I don’t want to talk about wine. No one would really want to use those for real generic gaming).

So basically, Proton is a fork of Wine, and this software can run Windows games on Linux, and players don’t need to worry about most of the How to run Windows games on Linux things.

It is also very convenient for most game Developers. Proton just works. No need to change anything, unless you use some very unrecommended/unofficial/deprecated/obsoleted Windows API, which may happen in very old days.

100oj v3.3 on Linux Mint.

screenshot_by_flameshot_at_20210119135409

Sora on Linux Mint.

screenshot_by_flameshot_at_20210117104610

Funny thing is, the OP animation is in WMV format (Windows Media Video), which was made by Microsoft and was not kind of an open/free format. So if you play Sora on Linux with Proton, the game will crash if you stay at the start screen long enough, and try to wait for the OP animation to play.

screenshot_on_b85m_by_flameshot_at_2024-12-14_17-57-13

Funnier thing is, the OP animation WMV file is actually

  • Container: WebM
  • Video Coding: VP9
  • Audio Coding: Opus

All of them are open and royalty-free.

screenshot_on_b85m_by_flameshot_at_2024-12-13_18-24-57

Well, let’s not talk about Sora right now.


The Official announcement: Support for 100oj on Linux?

I don’t remember when it was exactly.

The wiki says it was Sep 20th, 2024, v3.23 Versioned Hotfix 1, but the official Discord announcement is Oct 6th, 2024.

screenshot_on_b85m_by_flameshot_at_2024-12-13_18-42-57

screenshot_on_b85m_by_flameshot_at_2024-12-13_18-39-08

screenshot_on_b85m_by_flameshot_at_2024-12-13_18-37-55

100oj now officially has a Linux native build.

This is where/when/how a nightmare begins.


The first time when an inexperienced programmer gives a name without knowing case-sensitive

Here it is. You can read the paragraph heading, and if you know Linux, you already know what I am talking about.

On Oct 7th, 2024, while I was checking on the Linux side, I found my save file on the Linux side is kinda outdated compared to the save on the Windows side, despite Steam already saying Cloud Status is Up to date. Also, the Free Weekly Character is different from the Windows side.

Turned out there were two directories.

screenshot_on_b85m_by_flameshot_at_2024-10-07_15-55-32

I posted this on the official Discord Support Channel.

screenshot_on_b85m_by_flameshot_at_2024-12-13_22-29-34

After that, a developer from 100oj Official replied:

screenshot_on_b85m_by_flameshot_at_2024-12-13_22-21-26

So basically, the old Steam-Play, aka the Proton one worked fine, but when the Linux native build came out, they messed up the path because of case-sensitive.

That’s kinda acceptable for a developer who doesn’t have much experience on Linux.

Well, the easiest way to fix my problem is, because I play 100oj on Windows most, I just wanted to keep the Windows savefile, so just delete both Save and save on my Linux side, and let Steam re-sync from the steam-cloud. That worked well.

I thought this case-sensitive crisis was over.


Major update 3.24

Well the most recent major update of 100oj is 3.24, released on Nov 24th, 2024.

Talking from my point of view, it was a terribly stupid idea to accomplish all these at one time.

  • Adding new play mode
  • Graphics engine changing
  • New Platform MacOS support
  • Dropping support for 32bit

I mean, what are they? Fresh inexperienced just-graduated noob programmers? What are they thinking?

100oj game crashed, a lot, after that release. The Discord support channel became a total mess.

Look at the Version 3.24 release note on orangejuice.wiki. There are one versioned hotfix and 4 unversioned hotfixes, lasting for 16 days. You should know it was a mess.


Linux Steam Overlay Issue

I mean, look at this one:

screenshot_on_b85m_by_flameshot_at_2024-12-13_22-58-08

This was reported by me, and what’s the first reply I received?

screenshot_on_b85m_by_flameshot_at_2024-12-13_23-01-01

“You are not doing that right that’s your fault lmao bronze you noob gamer trash.”

Well funny thing: the 100oj start-entry is a shell script. It looked like this:

screenshot_on_b85m_by_flameshot_at_2024-11-27_20-59-32-2

To no programmers, I will explain it: The script wants to load a file, and it should be at ‘/home/rapha/.steam/debian-installation/ubuntu12_64/gameoverlayrenderer.so’. The path is formed with:

  • Prefix ‘/home/’
  • User name ‘rapha’
  • Steam installation directory ‘/.steam’
  • Steam file ‘/debian-installation/ubuntu12_64/gameoverlayrenderer.so’

There are two problems.

The first one: Who is rapha? It’s not me, obviously.

The second one: in the Steam installation directory ‘/.steam’, the file ‘ameoverlayrenderer.so’ is actually located at ‘/ubuntu12_64/gameoverlayrenderer.so’, thus there is no such a prefix ‘/debian-installation/’.

After some tests, I figured out there were some useful variables when starting something from steam client.

 

https://www.bilibili.com/video/BV1R6BRYmEoD/

Both STEAM_BASE_FOLDER and STEAM_COMPAT_CLIENT_INSTALL_PATH are reliable. I also searched on Google but didn’t find any official valve/steam document about how to locate where the steam client is installed.

I recommended “$HOME/.local/share/Steam/ubuntu12_64/gameoverlayrenderer.so” and “${STEAM_COMPAT_CLIENT_INSTALL_PATH}/ubuntu12_64/gameoverlayrenderer.so”, but got refused.

screenshot_on_b85m_by_flameshot_at_2024-12-14_00-01-24

Well of course he didn’t know what a symbolic link is.

During the discussion, a new unversioned hotfix was released:

  • Fixed Steam Overlay not working on Linux.

screenshot_on_b85m_by_flameshot_at_2024-12-14_00-04-30

Fixing by this:

screenshot_on_b85m_by_flameshot_at_2024-11-27_20-59-32-1

So they removed the ‘/home/rapha/’ part but still kept the ‘/debian-installation/’ there. I don’t know why.

screenshot_on_b85m_by_flameshot_at_2024-12-14_00-03-37

I asked. No response.

Thankfully, some Linux users are aware of that and they know how to search and read.

screenshot_on_b85m_by_flameshot_at_2024-12-14_00-04-04

Turns out there is no need to  load the steam overly library manually when start from Steam.

Well, at least I helped someone.

Note: Right now they have fixed it stealthily, with no release notes. The entry script is just like this:

screenshot_on_b85m_by_flameshot_at_2024-12-14_00-27-59

 

Well. No credit to me.


The save path issue continues

Now they supported MacOS.

New platform, new steam cloud sync issues.

They even made a post on How to deal with save problems.

screenshot_on_b85m_by_flameshot_at_2024-12-14_00-15-16

But there isn’t any of the cross-platform savefile case-sensitivity issue information. I had to ask for adding that part.

screenshot_on_b85m_by_flameshot_at_2024-12-14_00-17-31


Mess up steam cloud sync again

I think it’s about Unversioned Hotfix 4 when they tried to fix the macOS saves sync issue.

After that update, my Linux 100oj couldn’t sync saves anymore.

screenshot_on_b85m_by_flameshot_at_2024-12-10_01-13-03

I tried the old way, removing all save files on Linux, expecting that steam client could just download the saves from steam cloud.

screenshot_on_b85m_by_flameshot_at_2024-12-14_00-29-54

Nope, that was not happening.

After a lot of trying and testing, I figured out what is happening.

screenshot_on_b85m_by_flameshot_at_2024-12-11_23-29-04

On Linux, 100oj is using both Save and save at the same time. When there are no save files:

  1. Try to convert old format saves user.dat into the new format at save/{userid}/, which the file should be very old before steam family sharing
  2. Uploading save files at Save/{userid}/
  3. If anything is missing when uploading, steam will call Unable to sync / Cloud Conflict
  4. Stuck.

screenshot_on_b85m_by_flameshot_at_2024-12-14_00-53-13

And here is the official response.

screenshot_on_b85m_by_flameshot_at_2024-12-14_00-48-47

See, that’s why I didn’t even bother explaining it.

screenshot_on_b85m_by_flameshot_at_2024-12-14_00-50-43

And you thought at least they managed to make macOS work? Too bad. Look at this screenshot of a macOS user’s Steam Cloud Storage, and see what a mess they had made.

screenshot_on_b85m_by_flameshot_at_2024-12-14_00-53-24

screenshot_1316429008703062187


Conclusion?

Well for now, they could still change anything stealthily with no release note. May become better, or become worse. I don’t know.

I even talked about this to the guy who was taking charge of 100oj Chinese localization.

screenshot_on_b85m_by_flameshot_at_2024-12-13_22-32-42

Developers are stubborn.

Well I don’t want to care about it anymore. I get no paid nor credit.

 


Update in 2024-12-23

100oj Official admitted they messed up the steam cloud setting for savefile sync.

They also said they fixed it.

 

I’m not buying it. Anyway, there is no credit to me.

The post Do not play 100% Orange Juice on Linux or Steam Deck first appeared on 石樱灯笼博客.

Devonthink 出品的免费软件

作者 Dayu
2024年11月4日 20:42

DEVONtechnologies 是一个 macOS 软件公司,其最知名的产品 Devonthink,用于文件和信息管理。

每次逛 Devonthink 的社区 —— DEVONtechnologies Community,都能给我不小的惊喜。前段时间发现 DEVONtechnologies 原来还发布了很多功能强大的免费软件/插件:

WordService,针对选择文本的小工具,比如转成繁体中文、格式化文本等。

CalcService,是一款公式计算插件,在文本界面都可以使用。

EasyFind,用于替代 Spotlight 的文件检索软件,适合更高级的精确文件搜索需求。相似的软件还有 GoToFileFoxTrot Search

Neo Network Utility,网络工具,用于获取网络适配器信息并诊断常见的网络问题。

PhotoStickies,将喜欢的图片直接展示在桌面上。桌面相册(photoalbum)也有相似地功能,样式稍微好看一些。

ThumbsUp,设置好参数后,将图像拖拽到该软件的图标上,即可调整图片分辨率和大小。

XMenu,在菜单栏添加程序、文件、文档、文本的快速访问窗口。

DEVONagent Lite,网页检索工具,可以提前配置一些搜索习惯。完整付费版为:DEVONagent Express 和 DEVONagent Pro。

成也流量,败也流量。

作者 Dayu
2024年11月1日 17:25

检索的时候,在关键词后加 “Reddit”,总能搜到一些有趣的讨论帖。

过去知乎、小红书也能起到这个功能,但随着它们商业化价值变高,越来越多功利性比较强的信息进入,如广告和 AI 生成的文字,内容的真实性变的越来越难判断。

论坛和社区的流量相对较小,其中的信息还显得有些人味,也往往更深入。

成也流量,败也流量,不知道小红书还能坚持多久。

Reddit 之外,其实还有很多偏好性强的小论坛,以下是我偶尔会逛逛的:

如想发掘更多论坛,可以试试这两个渠道:ListOfSubredditsDiscourse Discover

主动寻找,才能找到更符合自己兴趣和性格的内容。

4个步骤让 MacOS 13 以下版本支持 AVIF 格式预览

作者 Jeff
2024年8月28日 10:36

如果你使用的是 macOS Ventura(MacOS 13),系统已默认支持 AVIF 格式打开和预览。对于更旧的系统版本,需要通过安装第三方图片浏览软件或拖到浏览器中查看。

AVIF QuickLook 插件可以通过4个简单的步骤,实现在系统直接预览 AVIF 格式,该插件由国内一个作者 DreamPiggy 开发。

要求:

1、macOS 10.11+ (Big Sur+) 以上版本
2、M1/Intel Mac 都支持

步骤:

1、在 Github Release Page 下载最新的 AVIFQuickLook.qlgenerator
2、打开 访达.app (Finder);
3、通过快捷键 Shift + Command + G 打开“前往文件夹”窗口,输入 ~/Library/QuickLook/ 然后回车。 macOS Catalina 以上版本, 使用 /Library/QuickLook/
4、把下载的 AVIFQuickLook.qlgenerator 复制到该文件夹内,可能需要输入电脑密码确认。

如果你已经安装了 Homebrew,只需要一行命令即可。

brew install avifquicklook

安装完,系统就支持直接预览 AVIF 格式了。

利用 Mac 快速操作实现图片批量转换为 AVIF 格式

作者 Jeff
2024年8月26日 23:43

继上一文介绍了我“利用 Mac 快速操作实现图片批量转换为 WebP 格式”捣腾成功后,希望通过同样的方法实现利用 Mac 快速操作实现图片批量转换为 AVIF 格式,捣腾结果分享如下。

为什么使用 AVIF 格式?

AVIF 是一种基于AV1 视频格式的现代图片格式,实现卓越的压缩效率,同时保持高图像质量。AVIF 通常比WebP、JPEG、PNG 和 GIF 具有更好的压缩效果,并且旨在取代它们。AVIF 对宽色域、高动态范围 (HDR) 和渐进式渲染的支持增强了视觉体验,预示着图像细节精美且高效交付的未来。号称 Web 开发人员和摄影师的首选。据统计,AVIF 全球使用情况为 92.95%,除 IE 浏览器、Opera Mini、QQ 浏览器、KaiOS 浏览器外都已支持,WordPress 6.5+ 已支持 AVIF 格式

利用 Mac 快速操作实现图片批量转换为 AVIF 格式-雅余

通过 AVIF 格式其开发组织“开放媒体联盟”(AOMedia),顺藤摸瓜在其 Github 账号上找到了 libavif 这个用于编码和解码 AVIF 格式的库和使用文档。

我的操作步骤如下:

一、安装 Homebrew

这部分就不重复介绍了,见“利用 Mac 快速操作实现图片批量转换为 WebP 格式”一文。

二、使用 Homebrew 命令安装 libavif 包

在终端中运行一下命令:

brew install libavif

回车直至安装完成。注意是否有出错或文件无授权的提示,按需对文件夹进行可操作授权。注意 libavif 包的安装路径,后面需要用到。

三、添加 Mac 快速操作 Workflow

1、在 Mac 上打开“自动操作”,选取“快速操作”; 利用 Mac 快速操作实现图片批量转换为 AVIF 格式-雅余

2、在工作流的顶部,它显示“工作流程收到当前”,选择“图像文件”,然后在“位于”下选择“访达.app”;

利用 Mac 快速操作实现图片批量转换为 AVIF 格式-雅余

3、接下来,在“自动操作”的左侧面板,在“资源库”下选择“实用工具”,然后将“运行 Shell 脚本”,拖放到右侧工作流程面板中;

4、对于“运行 Shell 脚本”,“Shell”选择“/bin/zsh”,“传递输入”选择“作为自变量”。

把以下代码片段粘贴到下面文本框中:

for f in "$@"
do
fname="${f%.*}.avif"
/usr/local/Cellar/libavif/1.1.1/bin/avifenc -s 10 -q 85 "$f" "${f%.*}.avif"
done

然后在“文件”菜单选择“储存”,保存文件名为“转换为 AVIF”,保存到默认地址即可。

注意:
1)libavif 的路径是为通过 Homebrew 安装的 libavif 设置的,如果您手动安装了 libavif,那么它可能在 /usr/bin 中,您需要相应地调整路径(我的最终路径是 /usr/local/Cellar/libavif/1.1.1/bin/avifenc );

2)-q 质量标志当前设置为 85,默认为 60,但您可以将其设置为 1-100 之间的任何值(越高将产生更高质量的图像,但压缩较少);-s 代表速度,默认为6;默认不删除照片 exif 信息,需删除则加上 --ignore-exif 参数。

5、选择你需要转换格式的图片,可多选,右键菜单的“快速操作”中选择“转换为 AVIF”选项,图片将在当前文件夹中自动生成 AVIF 格式文件。

利用 Mac 快速操作实现图片批量转换为 AVIF 格式-雅余

至此,教程结束。

下图为 WebP 和 AVIF 格式压缩率都设置为 85 所得到的压缩结果,结果是 WebP 的文件更小一些,有点困惑。不知道是不是我设置的压缩率太高了,libavif 官方默认值是 60。本文方法大致如上,至于多少压缩率更好,大家自己摸索吧。

利用 Mac 快速操作实现图片批量转换为 AVIF 格式-雅余

另外,我通过 AVIFQuickLook 插件,已经实现了在老苹果中直接预览 AVIF 格式。使用 Brew 进行安装,命令如下:

brew install avifquicklook

如有误,或有更好的方案,欢迎指正和交流。

❌
❌