Skip to content

Instantly share code, notes, and snippets.

View kfitfk's full-sized avatar
😇

Hao Ye kfitfk

😇
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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));
}
open -a "Visual Studio Code" --args --disable-blink-features=FontMatchingCTMigration