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
// Go coding exercise: implement LRU Caching service | |
package main | |
func main() {} | |
type QueueNode struct { | |
next *QueueNode | |
prev *QueueNode | |
key string | |
} |
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
// subtract two sets | |
const s1 = [ 1, 2, 3, 4, 5 ] | |
const s2 = [ 2, 4 ] | |
const subtracted = s1.filter(x => s2.indexOf(x) < 0) | |
console.log(subtracted) |
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
// fromPairs | |
const pairs = [['a', 1], ['b', 2], ['c', 3]] | |
const asObjects = pairs | |
.reduce((res, [key, value]) => ({ ...res, [key]: value }), {}) | |
// Or event smarter (thanks to @nomaed for pointing this one out) | |
const asObjects2 = { ...(new Map(pairs)) } | |
console.log(asObjects) // => { a: 1, b: 2, c: 3 } |
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
// flatten an array of arrays | |
const arrayOfArray = [ [1, 2], [3, 4], [[5, 6]] ] | |
const flattened = arrayOfArray.reduce((res, a) => [...res, ...a], [] ) | |
console.log(flattened) // => [1, 2, 3, 4, [5, 6]] |
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
// merge an array of objects | |
const data = [ {a: 1}, {b: 2}, {c: 3} ] | |
const merged = data.reduce((res, obj) => ({...res, ...obj}), {}) | |
console.log(merged) // => { a: 1, b: 2, c: 3 } | |
// merge an array of objects by property | |
const toMerge = [ | |
{ id: 1, value: 'a', }, | |
{ id: 2, value: 'b', }, | |
{ id: 3, value: 'c' }, |
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
// remove object from array by property | |
const removeId = 3 | |
const without3 = initial.filter(x => x.id !== removeId) | |
console.log(without3) // => [ { id: 1, score: 1 }, { id: 2, score: 2 } ] |
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
// update an object in array by property | |
const initial = [ {id: 1, score: 1}, {id: 2, score: 2}, {id: 3, score: 4}] | |
const newValue = {id: 3, score: 3} | |
const updated = initial.map(x => x.id === newValue.id ? newValue : x) | |
console.log(updated) // => [ { id: 1, score: 1 }, { id: 2, score: 2 }, { id: 3, score: 3 } ] |
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
// get uniq from array | |
const numbers = [1, 2, 1, 1, 2, 1, 3, 4, 1 ] | |
const uniq = [...new Set(numbers)] // => [ 1, 2, 3, 4 ] | |
const uniq2 = Array.from(new Set(numbers)) // => [ 1, 2, 3, 4 ] |
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/bash | |
# Lunatic pre-commit hook | |
echo 'pre-commit hook starting' | |
FLIP=$(($(($RANDOM%10))%2)) | |
if [ $FLIP -eq 1 ] | |
then | |
echo 'Okay, I will accept your commit' | |
exit 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
githook_installer: | |
build: . | |
dockerfile: 'Dockerfile.githooks' | |
volumes: | |
- ./.git:/tmp/.git | |
- ./hooks:/tmp/hooks |
NewerOlder