Skip to content

Instantly share code, notes, and snippets.

View akarca's full-sized avatar
🏠
Working from home

Serdar Akarca akarca

🏠
Working from home
View GitHub Profile
@akarca
akarca / gist:f0619406f9e808cdb9c1939e674f8cb1
Created March 25, 2018 00:08
getting yesterday's timestamp with date command on mac and linux
#!/bin/bash
unameOut="$(uname -s)"
case "${unameOut}" in
Darwin*) yesterday=$(date -v-1d "+%s");;
*) yesterday=$(date +%s --date="-1 days");;
esac
echo $yesterday
@akarca
akarca / udp_server.py
Created May 10, 2018 18:27 — forked from majek/udp_server.py
Simple python udp server
import logging
import socket
log = logging.getLogger('udp_server')
def udp_server(host='127.0.0.1', port=1234):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
@akarca
akarca / install_ffmpeg.sh
Created May 13, 2018 22:04 — forked from Piasy/install_ffmpeg.sh
brew install ffmpeg with all options
brew options ffmpeg
brew install ffmpeg \
--with-chromaprint \
--with-fdk-aac \
--with-fontconfig \
--with-freetype \
--with-frei0r \
--with-game-music-emu \
--with-libass \
@akarca
akarca / gist:d3a44e2a629d8581179cab086a012fbf
Created September 24, 2018 13:11
credit card formatter
var getFormattedValue = function (value, blocks, delimiter) {
var result = '',
currentDelimiter;
var blocksLength = blocks.length;
// no options, normal input
if (blocksLength === 0) {
return value;
}
#!/usr/bin/env python
list1 = [5, 9, 23, 4, 3, 8, 1, 12, 2, 9, 15, 19, 11, 27, 0]
list2 = [77, 21, 23, 29, 51, 40, 15, 72, 18, 44, 96, 92, 86, 24, 2, 26, 16, 71, 46, 56, 92, 34, 97, 51, 3, 14, 31, 71, 29, 4, 72, 28, 41, 50, 52, 1, 51, 8, 83, 57]
list3 = []
list4 = [1]
list5 = [1, 2]
list6 = [2, 1]
list7 = [1, 2, 3]
list8 = [3, 1, 2]
@akarca
akarca / fish_config_kubernetes.fish
Last active January 8, 2023 22:47
kubectl alias functions with grep for fish shell
# Usage: kg deploy consumer // shows all deploy names containes consumer
# Usage: kg pods listener // shows all pod names containes listener
# Usage: kg pods listener -A // shows all pod names containes listener in all namespaces
function kg
set ARGS (count $argv)
if test $ARGS -gt 2
kubectl get $argv[1] $argv[3..-1] | grep "NAME\|$argv[2]"
else if test $ARGS -gt 1
kubectl get $argv[1] | grep "NAME\|$argv[2]"
else
@akarca
akarca / config.fish
Created April 14, 2021 08:29
Kubernetes Resource Optimizer Tool
#
# Usage: krecommend namespace deployname
# Collect recommendations from vpa, patch cpu and memory resource of a deployment.
#
# usage: patchrequests namespace deploy 250m 500Mi
function patchlimits
set --local pdata (kubectl get deploy -n $argv[1] $argv[2] -o json | jq '.spec.template.spec.containers' | jq '.[0].resources.limits = {"cpu": "'$argv[3]'","memory":"'$argv[4]'"}')
set --local pdata2 (echo "{\"spec\":{\"template\":{\"spec\":{\"containers\":" $pdata "}}}}")
@akarca
akarca / generate_vpa.sh
Last active April 15, 2021 09:07
Automatic VPA generator for all deployments in namespace
#!/bin/bash
#
# Usage: ./generate_vpa.sh namespace
#
# Generates yaml files for vpa and applies.
#
mkdir -p "yaml/"$1"/"
kubectl get deploy -n $1 | grep -v NAME | awk -v namespace=$1 '{print $1" "namespace}' | awk '{ system("sed -e \"s/\{namespace}/"$2"/\" -e \"s/\{name}/"$1"/\" vpa.tpl > yaml/"$2"/"$1".yaml") }'
find "yaml/"$1 -name "*.yaml" -exec kubectl apply -f {} \;
const origSet = XMLHttpRequest.prototype.setRequestHeader;
XMLHttpRequest.prototype.setRequestHeader = function(header, value) {
if(header == "authorization") { window.authorization = value; }
origSet.apply(this, arguments);
};
def grep(text, match, after=0, before=0):
"""
Return matched lines in given text as a list. Similar to grep function but a simple one.
"""
idx = []
lines = text.split("\n")
for i, line in enumerate(lines):
if str(match) not in line:
continue