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 / refresh_certificates_on_runtime.go
Last active January 4, 2022 20:41
refresh certificates on runtime
package main
import (
"crypto/tls"
"github.com/fsnotify/fsnotify"
"log"
"net/http"
"sync"
)
@erkanzileli
erkanzileli / cue.go
Created September 8, 2021 18:16
sample cue usage
package main
import (
"cuelang.org/go/cue"
"cuelang.org/go/cue/cuecontext"
cuejson "cuelang.org/go/encoding/json"
"io/ioutil"
)
func main() {
@erkanzileli
erkanzileli / generate_kubeconfig_with_static_token
Created July 20, 2021 14:49
Generates a kubeconfig using the current context. Purpose is use static token instead of certificate files in kubeconfig
#! /bin/sh
kubectl -n kube-system create serviceaccount cluster-admin
cat <<EOF | kubectl apply -f -
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: cluster-admin
roleRef:
const additionalFields = {};
const logger = {
info: loggerWithLevel("info"),
error: loggerWithLevel("error"),
debug: loggerWithLevel("debug"),
};
function loggerWithLevel(level) {
return function log(strings, ...keys) {
#!/bin/bash
IP=$1
PORT_START=$2
PORT_END=$3
for i in $(seq "$PORT_START" "$PORT_END"); do
nc -z "$IP" "$i" 2> /dev/null
exit_code=$?
if [ $exit_code -eq 1 ]; then
@erkanzileli
erkanzileli / concurrent_processing_with_chunks.js
Created January 27, 2021 19:01
concurrent processing with chunks while holding a checkpoint as a file
const R = require("ramda");
// checkpoint, only processed data
const processed = require("./updated.json");
// processed and unprocessed data together, whole data
const toBeProcessed = require("./to_be_updated.json");
// data which will be processed on this execution
const willBeProcessed = R.difference(toBeUpdated, updated);
const chunks = R.splitEvery(10, willBeUpdated);
@erkanzileli
erkanzileli / couchbase_node.js
Created January 27, 2021 18:48
couchbase example with node.js
const couchbase = require("couchbase");
const cluster = new couchbase.Cluster("couchbase://hostname", {
username: "username",
password: "password",
});
const bucket = cluster.bucket("bucket-name");
const collection = bucket.defaultCollection();
async function main() {
@erkanzileli
erkanzileli / websocket.js
Created June 7, 2020 09:49
Sample WebSocket Server with Node.js
const http = require('http')
const WebSocketServer = require('websocket').server
const PORT = process.env.PORT || 8080
const MessageType = {
Join: 'Join',
Left: 'Left',
Message: 'Message'
}
@erkanzileli
erkanzileli / azurevm.tf
Created January 30, 2020 08:01
Example Azure Virtual Machine infra
provider "azurerm" {
version = "=1.38.0"
# subscription_id = "***"
skip_provider_registration = true
}
variable "prefix" {
default = "application"
}
@erkanzileli
erkanzileli / index.js
Last active December 20, 2019 12:38
Run async tasks sequentally and with delay while without blocking event-loop
async function getNumber(number) {
return number
}
let tasks = [
() => getNumber(1),
() => getNumber(2),
() => getNumber(3),
() => getNumber(4)
];