Skip to content

Instantly share code, notes, and snippets.

View whq731's full-sized avatar
🇨🇳
Busy

汉清 whq731

🇨🇳
Busy
  • Meituan
  • Beijing
View GitHub Profile
@whq731
whq731 / prepare-commit-msg.sh
Created August 6, 2019 03:24 — forked from bartoszmajsak/prepare-commit-msg.sh
How to automatically prepend git commit with a branch name
#!/bin/bash
# This way you can customize which branches should be skipped when
# prepending commit message.
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master develop test)
fi
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_NAME="${BRANCH_NAME##*/}"
@whq731
whq731 / array-to-object-or-map
Last active August 24, 2018 13:16
array-to-object-or-map
// 枚举值List转枚举对象
this.Obj = {};
this.Obj = list.reduce((obj, item) => {
obj[item.id] = item.name;
return obj;
}, {})
// list 转 Map
this.newMap = new Map(list.map(item => [item.id, item.name]))
var censor = function(key,value){
if(typeof(value) == 'function'){
return Function.prototype.toString.call(value)
}
return value;
}
var foo = {bar:"new property",baz:3,o:{name:'warjiang',age:23,info:{sex:'male',getSex:function(){return 'sex';}}}};
console.log(JSON.stringify(foo,censor,4))
@whq731
whq731 / consume.js
Created January 20, 2016 04:07
set array's elements between array[start] and array[index] to 0
function consume(start, end, arr) {
if (end === start) return arr;
arr[end - 1] = 0;
end--;
return consume(start, end, arr);
}