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 | |
| # This script should be located on each Jenkins slave, and the jenkins user should have permission to run it with sudo | |
| # Attempts to cleanly stop and remove all containers, volumes and images. | |
| docker ps -q | xargs --no-run-if-empty docker stop | |
| docker ps -q -a | xargs --no-run-if-empty docker rm --force --volumes | |
| docker volume ls -q | xargs --no-run-if-empty docker volume rm | |
| docker images -a -q | xargs --no-run-if-empty docker rmi -f | |
| # Stops the docker service, unmounts all docker-related mounts, removes the entire docker directory, and starts docker again. |
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
| const data = ["one", "onehalf", "two", "twohalf", "three", "threehalf"]; | |
| const f1 = item => item !== "one"; | |
| const f2 = item => item !== "two"; | |
| const f3 = item => item !== "three"; | |
| const filters = [f1, f2, f3]; | |
| //first approach (this does filters.length number of iterations) | |
| const filteredData = (filters, data) => filters.reduce((d, f) => d.filter(f) , data) |
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
| //compare the triplets | |
| function compareTriplets(a, b) { | |
| const results = a.reduce((accum, current, index) => { | |
| if (current > b[index]) { | |
| accum.a = accum.a + 1; | |
| } | |
| if (current < b[index]) { | |
| accum.b = accum.b + 1; | |
| } | |
| return accum; |
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
| --Problem 1 | |
| {- | |
| If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. | |
| The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. | |
| -} | |
| sumMults :: Integral a => a -> a | |
| sumMults n = sum $ filter (\x -> mod x 3 == 0 || mod x 5 == 0) [1..(n-1)] | |
| sumMults2 n = sum [x | x <- [1..(n-1)], (\x -> mod x 3 == 0 || mod x 5 == 0) x] |
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
| git config --global alias.l "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" |
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
| // [0,0,10,15,15,15,15,12,12,12,12,12,0,0,10,10,10,10,10] | |
| // | | | |
| // 0, 1,2 | |
| // p1 | |
| // p2 | |
| // p2 index = x value | |
| // p2 value = y value |
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 getTreeHeight = function(tree) { | |
| var counter = 1; | |
| var max = 0; | |
| var position = tree.root; | |
| (function recurse(node){ | |
| if(!node){ |
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
| function Node(value){ | |
| this.value = value; | |
| this.left = null; | |
| this.right = null; | |
| this.parent = null; | |
| } | |
| function BST(){ | |
| this.root = null; | |
| } |
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
| function Tree(value){ | |
| this.value = value || null; | |
| this.parent = null; | |
| this.children = []; | |
| } | |
| Tree.prototype.add = function(value){ | |
| if (this.value === null){ | |
| this.value = value; | |
| }else { |
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
| function Node(value){ | |
| this.value = value; | |
| this.next = null; | |
| this.previous = null; | |
| } | |
| function CDoublyLinkedList(){ | |
| this.head = null; | |
| this.tail = null; | |
| this.length = 0; |
NewerOlder