Skip to content

Instantly share code, notes, and snippets.

View erkanzileli's full-sized avatar
:shipit:
what if

Erkan Zileli erkanzileli

:shipit:
what if
View GitHub Profile
@erkanzileli
erkanzileli / customMergeObjectsWithSameKeys.js
Created January 22, 2019 10:11
Merge objects of the same key name in arrays
var customMergeObjectsWithSameKeys = function (arr, key, mergeFunction) {
var _arr = []
arr.forEach(item => {
var index = _arr.findIndex(_item => _item[key] === item[key])
if (index === -1) {
_arr.push(item)
} else {
_arr[index] = mergeFunction(_arr[index], item)
}
})
@erkanzileli
erkanzileli / orderByKey.js
Created January 23, 2019 07:27
order an array by selected key and choose ascending or descending
function orderByKey (arr, key, asc) {
return arr.sort((a, b) => {
if (a[key] < b[key]) {
return asc === true ? -1 : 1
}
if (a[key] > b[key]) {
return asc === true ? 1 : -1
}
return 0
})
@erkanzileli
erkanzileli / remove-a-node.java
Last active April 4, 2019 14:42
Delete an element from an array
public static Object[] delete(Object[] array, int index) {
Object[] newArray = new Object[array.length - 1];
for (int i = 0; i < array.length; i++) {
if (i == index)
continue;
newArray[i] = array[i];
}
return newArray;
}
@erkanzileli
erkanzileli / chart-museum.values.yaml
Last active April 16, 2019 06:25
ChartMuseum values
ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: nginx
certmanager.k8s.io/cluster-issuer: letsencrypt-prod
certmanager.k8s.io/acme-http01-edit-in-place: "true"
hosts:
- name: chartmuseum.35.202.15.36.nip.io
path: /
tls: true
@erkanzileli
erkanzileli / concourse.installation.md
Last active April 16, 2019 06:25
Concourse 5.0.1 Helm Chart Configuration for Minikube

Installation

Run

minikube addons enable ingress

Wait until default-http-backend pod activate

Learn your node ip

minikube ip
@erkanzileli
erkanzileli / binaryGap.js
Created April 21, 2019 21:40
JavaScript binary gap solution
/**
* Services:
* 1 - Convert integer to binary string
* 2 - Find binary gaps from binary string and add to custom data struct
* 3 - Get biggest binary gaps
*/
function binaryGap(N) {
// get binary string
var binaryString = N.toString(2);
@erkanzileli
erkanzileli / single_node_rancher_installation.md
Last active August 19, 2019 10:53
Single node Rancher installation

docker volume create racher docker run -d --restart=unless-stopped -p 7080:80 -p 7443:443 --name rancher -v rancher:/var/lib/rancher -v pwd/fullchain.pem:/etc/rancher/ssl/cert.pem -v pwd/privkey.pem:/etc/rancher/ssl/key.pem rancher/rancher --no-cacerts

@erkanzileli
erkanzileli / index.js
Created October 4, 2019 22:55
Closure vs. High Order Functions in JavaScript
// A closure does not mean that it necessarily is returned by a function.
// A closure generally is a function that has access to the declaration context's scope.
// A closure example without returning a function
var oddNumber = 3;
function isOddNumberIsReallyOdd() {
return oddNumber % 2 === 1;
}
#! /bin/bash
for i in $(seq 100); do
bash -c "echo '' >/dev/tcp/$IP/8080" 2>/dev/null
if [ $? -eq 0 ]; then
break
fi
echo -n .
sleep 1
done
const redis = require('redis')
const publisher = redis.createClient()
const subscriber = redis.createClient()
subscriber.psubscribe('channel:*')
subscriber.on('psubscribe', console.log)