Skip to content

Instantly share code, notes, and snippets.

View kfitfk's full-sized avatar
😇

Hao Ye kfitfk

😇
View GitHub Profile
@kfitfk
kfitfk / group_pinyin.js
Created November 28, 2013 03:16
group pinyin array
/** 把中文转换成拼音数组后,如果有多音字,枚举所有可能的组合
* 示例:
* [ [ 'a' ],
* [ 'b', 'c', 'd' ],
* [ 'e', 'f' ],
* [ 'g' ] ]
* 使用getResult方法将会返回:
* ["abeg", "abfg", "aceg", "acfg", "adeg", "adfg"]
*/
@kfitfk
kfitfk / git_history_email.sh
Created November 28, 2013 03:18
Change git commit email
git filter-branch -f --commit-filter '
if [ "$GIT_COMMITTER_NAME" = "yehao" ];
then
GIT_COMMITTER_NAME="Lingzheng";
GIT_AUTHOR_NAME="Lingzheng";
GIT_COMMITTER_EMAIL="lingzheng.yh@taobao.com";
GIT_AUTHOR_EMAIL="lingzheng.yh@taobao.com";
git commit-tree "$@";
else
git commit-tree "$@";
@kfitfk
kfitfk / img_to_base64.js
Created May 5, 2016 03:39
Convert an image to base64 encoding
/**
* Convert an image to a base64 encoded value
* @param {string} url - The url of the image which has correct Access-Control-Allow-Origin response header
* @param {function} callback - callback with one parameter containing the base64 encoded value
* @param {string} [outputFormat] - image/png or image/jpeg or image/webp(Chrome)
*/
function convertImgToBase64(url, callback, outputFormat){
var img = new Image()
img.crossOrigin = 'Anonymous'
img.onload = function() {
@kfitfk
kfitfk / rgb_to_lab.js
Created March 18, 2016 07:17
Convert RGB color to CIE LAB color
function rgbToXyz(r, g, b) {
r /= 255
g /= 255
b /= 255
if (r > 0.04045) r = Math.pow(((r + 0.055) / 1.055), 2.4)
else r = r / 12.92
if (g > 0.04045) g = Math.pow(((g + 0.055) / 1.055), 2.4)
else g = g / 12.92
@kfitfk
kfitfk / qmelt.sh
Created March 13, 2020 03:21
Using MLT/qmelt
# vb, minrate, maxrate are optional
# also there're other options, check the man page
qmelt path_to_mlt.xml -consumer avformat:output.mp4 vb=1200k minrate=500k maxrate=1900k
@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;
}
},
@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.