Skip to content

Instantly share code, notes, and snippets.

@mhewedy
mhewedy / k8s_alerting.sh
Created October 3, 2020 18:52
Report k8s jobs running for long time
# report jobs is running for more than 60 minutes
sudo kubectl get pods -l job-name -o jsonpath='{range .items[*]}{.metadata.name}{" "}{.status.phase}{" "}{.status.startTime}{"\n"}{end}' | while read line; do
name=$(echo $line | awk '{print $1}')
phase=$(echo $line | awk '{print $2}')
startTime=$(echo $line | awk '{print $3}')
now=$(date +%s)
start=$(date -d $startTime +"%s")
diff=$(( ($now - $start)/60 ))
@mhewedy
mhewedy / README.md
Last active September 30, 2020 15:19
Make release

Usage:

$ mkrel path/to/release
2.02.159

To see the whole list in debug mode, define a DEBUG env var and set it to 1:

package main
import (
"context"
"database/sql"
"fmt"
"github.com/Fs02/rel"
"github.com/Fs02/rel/adapter/postgres"
"github.com/jackc/pgx/v4"
pgxs "github.com/jackc/pgx/v4/stdlib"
@mhewedy
mhewedy / curl
Created August 24, 2020 20:39
my curl
/usr/bin/curl -s -H "content-type: application/json" $(echo " "$@ | perl -pe 's/\s+(:[0-9]+)/localhost$1/g') | jq
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"strings"
"time"
)
@mhewedy
mhewedy / iptv.go
Created May 30, 2020 04:36
group ip tv
package main
import (
"fmt"
"io/ioutil"
"os"
"regexp"
"sort"
"strings"
)
# worker.sh
# find most updated version at: https://github.com/mhewedy/vermin/tree/master/etc/samples-provision/k8s
# HW requirements: 1 CPUS 2 RAM
# OS: Ubuntu focal
set -ex
#should be $(lsb_release -cs) but it appears it is not working on focal yet
docker_ubuntu_release=bionic
k8s_version=1.18.0
# master.sh
# find most updated version at: https://github.com/mhewedy/vermin/tree/master/etc/samples-provision/k8s
# HW requirements: 2 CPUS 2 RAM
# OS: Ubuntu focal
set -ex
#should be $(lsb_release -cs) but it appears it is not working on focal yet
docker_ubuntu_release=bionic
k8s_version=1.18.0
@mhewedy
mhewedy / defer.go
Created May 7, 2020 11:30
Defer trick to around wrap function code
package main
import (
"fmt"
)
type Tnx struct {
}
func main() {
print_vms() {
arr=$1
printf "VM NAME\t\tIMAGE\t\t\tCPU\t\tMEM\t\tTAGS\n"
if [ ${arr} ]; then
for element in "${arr[@]}"; do
spec=($(VBoxManage showvminfo ${element} --machinereadable | grep -E "memory=|cpus=" | cut -d "=" -f2))
printf "%s\t\t$(cat ~/.vms/${element}/image 2>/dev/null || cat <(echo "\t") )\t\t%s\t\t%s MB\t\t%s\n" ${element} ${spec[1]} ${spec[0]} \
"$(echo $(cat ~/.vms/${element}/tags 2>/dev/null))"
done
fi