Skip to content

Instantly share code, notes, and snippets.

View eakray's full-sized avatar

Eugene Krayni eakray

View GitHub Profile
@eakray
eakray / cleanup_docker.sh
Created March 29, 2023 18:37 — forked from ralphtheninja/cleanup_docker.sh
Cleanup and reset docker on Jenkins workers / slaves
#!/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.
@eakray
eakray / multifolds.js
Created September 30, 2019 19:19
approaches to multiple folds
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)
@eakray
eakray / problems.js
Last active July 8, 2022 05:37
hackerrank
//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;
@eakray
eakray / euler.hs
Last active July 8, 2022 05:37
Project Euler problems
--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]
@eakray
eakray / gitLogFormatting.txt
Created August 9, 2016 17:33
Git Log Formatting
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"
@eakray
eakray / skyline.js
Created February 1, 2016 01:50
Skyline Problem
// [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
@eakray
eakray / treeHeight.js
Last active February 1, 2016 01:48
Tree height function
var getTreeHeight = function(tree) {
var counter = 1;
var max = 0;
var position = tree.root;
(function recurse(node){
if(!node){
@eakray
eakray / BST.js
Last active January 30, 2016 00:21
Binary Search Tree
function Node(value){
this.value = value;
this.left = null;
this.right = null;
this.parent = null;
}
function BST(){
this.root = null;
}
@eakray
eakray / Tree.js
Created January 20, 2016 01:41
Tree implementation
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 {
@eakray
eakray / CDoublyLinkedList.js
Created January 12, 2016 08:18
A simple implementation of a circular doubly linked list
function Node(value){
this.value = value;
this.next = null;
this.previous = null;
}
function CDoublyLinkedList(){
this.head = null;
this.tail = null;
this.length = 0;