Skip to content

Instantly share code, notes, and snippets.

View daredrum's full-sized avatar

Sergey daredrum

View GitHub Profile
@daredrum
daredrum / mongodb.txt
Last active January 23, 2020 07:55
MongoDb solutions
1. MongoDb combine $facet results into a single result set
db.getCollection('list').aggregate([
{
$facet: {
"events":[{
$match: {
'type': 'Event'
}
}],
"tasks": [{
@daredrum
daredrum / Javascript Interview Tasks
Last active November 17, 2019 12:45
Javascript Interview Tasks
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;
}
@daredrum
daredrum / changelog.sh
Created September 6, 2018 07:02
Bash script for getting change log between two the last "development" tags
#!/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}
@daredrum
daredrum / binary_javascript.js
Last active April 14, 2017 11:20
Binary in Javascript
#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
@daredrum
daredrum / git_methods.txt
Last active August 2, 2016 18:25
Git methods
### 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^'
@daredrum
daredrum / array.js
Created July 4, 2016 13:23
Array techniques
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]
@daredrum
daredrum / rounding_techniques.js
Last active April 14, 2017 11:19
Rounding techniques
n = 10.123456789;
// Bitwise ways
~~n; // 10
n|0; // 10
n^0; // 10
n>>0 // 10
// Native
Math.round(n); // 10