skip to content
声控烤箱 | KazooTTT 博客

Notes(102) RSS feed
preview

41. 最近状态比较差

Updated:

分析自己不开心的原因

第一是太过依赖外界获取快乐,当关注的事物出现的频次降低时就会产生焦虑。➡️分离焦虑

第二是身体自身问题,缺乏锻炼,睡眠不足,且最近 debuff,因此可能出现很多负面情绪

第三是过于消极并且在意他人看法,喜欢预设最坏的事情走向,给自己带来不必要的压力 ​​​

第四是欲望与现实不匹配,感觉想要的生活与现实差距比较大。

能让自己开心的事情

追星,需排除其中的不开心因素,例如和他人吵架

产出,拍到满意的照片,剪出满意的视频,写出满足需求的软件等

运动,运动完以后确实会开心很多

挣钱,喜欢看到存款变多的情况。

夸赞和感谢,一直都不会掩饰自己是个虚荣心很强的人,他人的夸赞和感谢会让我开心很久。

目前能做什么

既然关注的人出现的频次无法预测和掌控,因此只能处于有饭就吃,没饭可以扒拉两口别的饭,拓展兴趣点

由于目前比较忙,吃完晚饭回家已 8 点,没有太多时间做自己的事情和锻炼,因此尽量在自己身体和精神条件尚可的情况下,安排锻炼(更优先),然后在产出兴趣内的东西

其他的随缘吧,保持分享的欲望,实践费曼学习法,不刻意追求什么,慢慢积累就行。

42. search params 请求参数的获取与更新

Updated:

react router useSearchParams

useSearchParams | React Router

interface URLSearchParams {
/** Appends a specified key/value pair as a new search parameter. */
append(name: string, value: string): void;
/** Deletes the given search parameter, and its associated value, from the list of all search parameters. */
delete(name: string): void;
/** Returns the first value associated to the given search parameter. */
get(name: string): string | null;
/** Returns all the values association with a given search parameter. */
getAll(name: string): string[];
/** Returns a Boolean indicating if such a search parameter exists. */
has(name: string): boolean;
/** Sets the value associated to a given search parameter to the given value. If there were several values, delete the others. */
set(name: string, value: string): void;
sort(): void;
/** Returns a string containing a query string suitable for use in a URL. Does not include the question mark. */
toString(): string;
forEach(callbackfn: (value: string, key: string, parent: URLSearchParams) => void, thisArg?: any): void;
}

它提供了内建的 API,允许直接获取查询参数的值,比如 .get().set().append() 等。

const [queryParams, setQueryParams] = useSearchParams();
console.log('%c Line:52 🍿 queryParams', 'color:#33a5ff', queryParams.get('medicalRecordID'));

qs + window.location

GitHub - ljharb/qs: A querystring parser with nesting support

image.png

使用 window.location.search 获取到请求参数对应的字符串(需要注意的是:字符串是带有?的)

然后使用 qs.parse 方法来解析查询字符串

案例:localhost?medicalRecordID=1

错误使用:

const getQueryParam = (): QueryParams => {
// use qs to parse the query params
const queryParams: QueryParams = qs.parse(window.location.search);
return queryParams;
};

正确使用:

const getQueryParam = (): QueryParams => {
// use qs to parse the query params
const queryParams: QueryParams = qs.parse(window.location.search.slice(1));
return queryParams;
};
image.png

43. 使用cursor生成git commit msg

Updated:

原文参考:

x.com

太懒了不想写 Commit message,
@cursor_ai
帮你写👇:
1⃣ 按住 [Control ⌃ + `] 打开终端输入 git add 暂存更改。
2⃣ 按住 [Command ⌘ + K] 对话框输入 "git commit message" 然后提交请求,搞定!简洁明了。
IMG-20241112141124094

我是这样,在暂存前使用 command

x.com

@Commit (Diff of Working State)
Please generate a commit message with English. Below is the commit message template: <type>(<scope>): <subject>
@Commit (Diff of Working State)
Please generate a commit message with CN. Below is the commit message template: <type>(<scope>): <subject>
Pasted image 20241112141218

44. 2024-10-28 18分05秒 craft原来要收费

Updated:

对于第三方链接的解析,craft 的兼容性和美观程度是更好的。

IMG-C58CD0BCE8298B39A32CF9B5698EF4DC IMG-19B31E2B37A4ADD4C3F65725068BCAC4 IMG-330ABC2555F1F3E34E3D9FBB55B9C8F9

我一直以为 Craft 是免费的,今天才发现是最开始免费 10 个 doc,后面每周可以免费创建 2 个 doc。

45. 2024-10-25 13分11秒 Tapedeck

Updated:
IMG-50A2519769D27745F083E18F4D48FC55

Tapedeck.org 提供了从 60 年代初的功能型磁带到 90 年代的各种形状变化的磁带盒设计。

  • 记录了丰富的磁带设计历史和信息,从早期的功能性设计到后来的色彩丰富和形状变化。
  • 网站鼓励用户分享自己的磁带收藏,提供了详细的提交指南。
  • 网站还提供了一个在线商店销售与磁带相关的周边。

47. 在react中不要滥用 short-circuit &&

Updated:

错误现象

代码如下:

{camera_id && (
<div>{camera_id}号相机</div>
)}

当 camera_id>0 的时候,正常显示 x 号相机

当 camera_id=0 的时候,异常显示 0,而不是 0 号相机

错误原因

这是因为在 JavaScript 中,0 被视为 falsy 值,因此当 camera_id0 时,条件判断 camera_id && 会返回 false。所以后面的内容不被渲染。

但是 0 是可以被 react 渲染的,所以最后显示的是 0,而不是不显示。

解决方法

涉及到数字且可能为 0 的时候,不要直接使用&&来判断,而是使用

{camera_id !== undefined && (
<div>{camera_id}号相机</div>
)}

参考

reactjs - React showing 0 instead of nothing with short-circuit (&&) conditional component - Stack Overflow

48. 对于a标签的download属性

Updated:

对于 a 标签的 download 属性

image.png

<a>: The Anchor element - HTML: HyperText Markup Language | MDN


如何定义没有值?

<a download> 或者 <a download="">


在设置的需要注意类型转换:

let temp1 = document.createElement('a');
temp1.download = null;
console.log(temp1.download); // 输出 undefined

但是如果先设置了 download = ”, 再设置 download = null, 就会被转化为 ‘null’

image.png

所以要么直接设置 download = null,要么直接设置 download = ”

不要设置了 download = ” 之后去设置 download = null

49. 我自己常用的ffmpeg批处理

Updated:

720x1080 批量转 1920x1080(两边黑屏)

手机直播的时候录播机录出来的分辨率是 720x1080,使用 ffmpeg 转成横屏的 1920x1080。这样 xml 转 ass 弹幕的时候,就不需要另外处理了,看起来很更舒服。

macos 的写法:

Terminal window
input_folder="" # 要转化的录播的文件夹路径
output_folder="" # 要输出的文件夹路径
# Create the output folder if it does not exist
mkdir -p "$output_folder"
for f in "$input_folder"/*.flv; do
ffmpeg -i "$f" -vf "scale=720:1080,pad=1920:1080:(ow-iw)/2:(oh-ih)/2" -c:a copy "$output_folder/$(basename "${f%.*}.mp4")"
done

windows 的写法:

Terminal window
$input_folder = "Z:\\rec\\48743-hanser\\20240731-又来画画了!" # 要转化的录播的文件夹路径
$output_folder = "Z:\\rec\\48743-hanser\\20240731-又来画画了!" # 要输出的文件夹路径
# Create the output folder if it does not exist
If (-Not (Test-Path $output_folder)) {
New-Item -ItemType Directory -Path $output_folder | Out-Null
}
Get-ChildItem -Path $input_folder -Filter *.flv | ForEach-Object {
$input_file = $_.FullName
$output_file = Join-Path $output_folder ($_.BaseName + ".mp4")
$ffmpeg_args = @("-i", $input_file, "-vf", "scale=720:1080,pad=1920:1080:(ow-iw)/2:(oh-ih)/2", "-c:a", "copy", $output_file)
& ffmpeg $ffmpeg_args
}

效果

image.png

弹幕压制

windows 版 (使用 cuda)

Terminal window
@echo off
set input_folder=YourInputFolderPath
set output_folder=YourOutputFolderPath
for %%a in ("%input_folder%\\*.flv") do (
ffmpeg -hwaccel cuda -c:v h264_cuvid -i "%%a" -vf subtitles="%%~na.ass" -c:v h264_nvenc -b:v 6000k -c:a copy "%output_folder%\\%%~na_压制.mp4" -y
)

macOS 版

#!/bin/bash
input_folder="/path/to/input" # Replace with your input folder path
output_folder="/path/to/output" # Replace with your output folder path
mkdir -p "$output_folder" # Create the output folder if it doesn't exist
for f in "$input_folder"/*.mp4; do
subtitle_file="${f%.*}.ass" # Assumes subtitle file name is same as video file name but with .ass extension
output_file="$output_folder/$(basename "${f%.*}_压制.mp4")" # Output file name with _ass suffix
ffmpeg -i "$f" -vf "ass=$subtitle_file" "$output_file"
done

帧截图

Terminal window
ffmpeg -i inputfilepath %d.jpg

根据视频的帧率来提取截图,每帧都会被提取,并保存为 JPEG 图像文件

Terminal window
ffmpeg -i inputfilepath -vf "fps=1" %d.jpg

每隔 1 秒从视频中提取一帧,并保存为 JPEG 图像文件 ​​​

50. Perplexity系列产品

Updated: