This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1. MongoDb combine $facet results into a single result set | |
| db.getCollection('list').aggregate([ | |
| { | |
| $facet: { | |
| "events":[{ | |
| $match: { | |
| 'type': 'Event' | |
| } | |
| }], | |
| "tasks": [{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1. add(2,4)(5,3)(2)(3,1); // 20 | |
| function add(...argA) { | |
| const getSum = (arg) => arg.reduce((s, n) => s += n, 0); | |
| let sum = getSum(argA); | |
| const f = (...argB) => { | |
| sum += getSum(argB); | |
| return f; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| firstTag=$(git tag --list --sort=-taggerdate 'development-*' | head -1) | |
| secondTag=$(git tag --list --sort=-taggerdate 'development-*' | head -2 | awk '{split($0, tags, "\n")} END {print tags[1]}') | |
| echo "Changes between ${secondTag} and ${firstTag}\n" | |
| git log --pretty=format:'%h -%d %s (%cd) <%an>' ${secondTag}..${firstTag} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Value swap without a third variable (^ XOR) | |
| var a = 1, b = 2; | |
| a ^= b; | |
| b ^= a; | |
| a ^= b; | |
| // a = 2, b = 1 | |
| #Condition for indexOf | |
| !~array.indexOf(value); // -1 -> 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### Override local branch from remote | |
| git fetch origin feature_branch | |
| git reset --hard origin/feature_branch | |
| ### Remove branch remotely and locally | |
| git push origin feature_branch | |
| git branch -D feature_branch | |
| ### Edit old commits | |
| git rebase --i 'bbc643cd^' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var arr = [1,2,3,4,5,6,7,8,9,10]; | |
| var arr2 = arr.slice(0, 3); // => arr2 = [1,2,3] | |
| var arr3 = arr.splice(0, 3); // => arr3 = [1,2,3] arr = [4,5] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| n = 10.123456789; | |
| // Bitwise ways | |
| ~~n; // 10 | |
| n|0; // 10 | |
| n^0; // 10 | |
| n>>0 // 10 | |
| // Native | |
| Math.round(n); // 10 |