Skip to content

Instantly share code, notes, and snippets.

View kfitfk's full-sized avatar
😇

Hao Ye kfitfk

😇
View GitHub Profile
From https://forums.macrumors.com/threads/found-a-solution-for-the-macos-mousecursor-hover-focusloss-contextmenu-bug.2450307/post-34609144
The culprit was Apple's iPhone Mirroring app.
The app was running background hooks at the system input level that were corrupting hover state. The tell was seeing it flicker in the menu bar.
Fix:
1. Open the iPhone Mirroring app on your mac and revoke access to your iPhone
2. Go to System Settings > AirDrop & Continuity > iPhone Mirroring and turn off iPhone Widgets
3. Go to Notifications & Live Activities and confirm "Allow notifications from iPhone" and "Allow Live Activities from iPhone" are both off
open -a "Visual Studio Code" --args --disable-blink-features=FontMatchingCTMigration
@kfitfk
kfitfk / json_alphabetic.js
Created December 20, 2023 07:50
parse JSON string and keep the props in alphabetic order
function sortObjectAlphabetically(obj) {
if (typeof obj !== 'object' || obj === null) {
// Base case: obj is not an object, or is null
return obj;
}
if (Array.isArray(obj)) {
// If obj is an array, recursively sort its elements
return obj.map((element) => sortObjectAlphabetically(element));
}
@kfitfk
kfitfk / webm2hevc
Created November 3, 2022 06:04
Convert from webm to hevc using ffmpeg with hevc_videotoolbox
ffmpeg -c:v libvpx-vp9 -i [input_file.webm] -c:v hevc_videotoolbox -q:v 60 -allow_sw 1 -alpha_quality 0.7 -vtag hvc1 -movflags +faststart [output_file.mp4]
# use -q:v to set quality, 60 should suffice
# use -alpha_quality to adjust alpha channel quality
# for more options, check
# ffmpeg -h encoder=hevc_videotoolbox
# ffmpeg version 4.4.1 Copyright (c) 2000-2021 the FFmpeg developers
# built with Apple clang version 13.0.0 (clang-1300.0.29.3)
@kfitfk
kfitfk / m1_accent_colors.md
Last active August 9, 2022 06:32
Use iMac M1 accent colours on any Mac

First, enable NSColorSimulateHardwareAccent

defaults write -g NSColorSimulateHardwareAccent -bool YES

Then choose a color with NSColorSimulatedHardwareEnclosureNumber with a value between 3 and 8 inclusive.

defaults write -g NSColorSimulatedHardwareEnclosureNumber -int 4

  • 3: yellow
  • 4: green
@kfitfk
kfitfk / git_search_history_content.md
Last active May 9, 2022 09:37
Search modified files to see if they include a term; 在 git 文件修改历史内容中查询某个关键词
git log -Sword
git log -Gword
  • -G by default accepts a regex, while -S accepts a string, but it can be modified to accept regexes using the --pickaxe-regex.
  • -S finds commits where the number of occurrences of "word" changed, while -G finds commits where "word" appears in the diff.
  • This means that -S<regex> --pickaxe-regex and -G<regex> do not do exactly the same thing.
@kfitfk
kfitfk / nth_index.js
Created March 22, 2022 02:19
Get nth or last nth index of a pattern from a string
function nthIndex(str, pat, n){
let i= -1;
while (n-- && i++ < str.length) {
i = str.indexOf(pat, i);
if (i < 0) break;
}
return i;
}
function lastNthIndex(str, pat, n) {
@kfitfk
kfitfk / ffmpeg_extract_frame_with_transparency.sh
Last active September 22, 2021 02:59
extract a frame with transparency from a webm file using ffmpeg
# Replace 34 from select=eq(n\,34) with any frame number. Frame starts from 0.
ffmpeg -vcodec libvpx-vp9 -i input_file.webm -pix_fmt rgba -vf "select=eq(n\,34)" -vframes 1 output_file.png
# To generate a png file for each frame, use something like "frames/%04d.png" as the output file name
@kfitfk
kfitfk / build_skia.sh
Created August 16, 2021 11:57
build skia
# 下载安装 depot_tools
git clone 'https://chromium.googlesource.com/chromium/tools/depot_tools.git'
export PATH="${PWD}/depot_tools:${PATH}"
# 下载 skia
git clone https://skia.googlesource.com/skia.git
cd skia
python2 tools/git-sync-deps
@kfitfk
kfitfk / proxy_nested_obj.js
Created July 15, 2021 14:29
javascript proxy for nested object
var traps = {
get(target, propName, receiver) {
const val = Reflect.get(target, propName, receiver);
if (typeof val === 'object' && val !== null) {
return new Proxy(val, traps);
}
else {
return val;
}
},