Skip to content

Instantly share code, notes, and snippets.

View anapsix's full-sized avatar
😺

Anastas Dancha anapsix

😺
View GitHub Profile
@anapsix
anapsix / rmq_passwd_hash.py
Created May 22, 2018 19:33
generate RabbitMQ compatible SHA256 password hash
#!/usr/bin/env python
# details on rabbitMQ password hashing
# https://www.rabbitmq.com/passwords.html#computing-password-hash
from __future__ import print_function
import base64
import os
import hashlib
import struct
import getpass
@anapsix
anapsix / k8s-vault
Last active June 29, 2023 10:33
K8s-Vault, like AWS-Vault, but for cli tools using KUBECONFIG (~/.kube/config), such as helm, kubectl, etc..
#!/usr/bin/env bash
#
# K8s-Vault, like AWS-Vault is a helper for AWS related CLI tools
# is a helper for CLI tools using kubectl config and K8s API.
# Unlike AWS-Vault, vault here is used as a verb,
# synonymous to leap, jump, spring, etc..
# Copyright (C) 2019-2020 Anastas Dancha (aka @anapsix)
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@anapsix
anapsix / docker_pull_remains.sh
Last active May 23, 2023 21:35
Naive script to check how many anonymous pulls from Docker hub remain / allowed from current IP
#!/usr/bin/env sh
for dep in curl jq grep awk; do
if ! which ${dep} >&/dev/null; then
echo >&2 "ERROR: required ${dep} binary is not found, exiting.."
exit 1
fi
done
TOKEN=$(
@anapsix
anapsix / cronjob_with_exec_timeout.yaml
Last active March 30, 2023 19:51
K8s CronJob with execution timeout implemented via livenessProbe
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: do-something-job
namespace: scheduled-tasks
spec:
schedule: "*/2 * * * *"
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 3
@anapsix
anapsix / k8s-oidc-login.sh
Last active January 9, 2023 13:55
K8s-OIDC-LOGIN - helper to simplify multi-cluster OIDC login and related configuration for kubectl. Can be used as kubectl plugin
#!/usr/bin/env bash
#
# K8s-OIDC-LOGIN helper to simplify configuration of OIDC authentication for kubectl
#
# Heavily influenced by oidckube project by @mrbobbytables
# https://github.com/mrbobbytables/oidckube
#
# Copyright (C) 2019 Anastas Dancha (aka @anapsix)
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@anapsix
anapsix / chat.sh
Last active March 18, 2022 18:24
Chat server with Netcat and Bash, inspired by ITA Software 2011 interview challenge
#!/bin/bash
#
# Implementation of BASH + NCAT chat server
#
# Author: Anastas Dancha <anapsix@random.io>
# Contact: anapsix@random.io
#
#debug="true"
@anapsix
anapsix / aws_metadata_proxy.md
Created December 13, 2017 16:47
How to proxy EC2 metadata

How to proxy to EC2 Metadata

Sometimes, you need to use your EC2 instance's credentials to access the AWS resources, for testing, development, etc.. This is how you do it.

Step 1

create 169.254.169.254 on loopback interface

linux

sudo ip a add 169.254.169.254 dev lo
@anapsix
anapsix / rkind.sh
Last active February 23, 2022 18:53
Rancher in KIND (Rancher in Kubernetes-in-Docker)
#!/usr/bin/env bash
#
# RKIND is a naive helper script to start KIND and Rancher Management Server
#
set -u
set -o pipefail
RANCHER_CONTAINER_NAME="rancher-for-kind"
RANCHER_HTTP_HOST_PORT=$[$[RANDOM%9000]+30000]
@anapsix
anapsix / check_dns.sh
Created April 1, 2018 11:14
Watch for DNS changes and reload NGINX (or do something else)
#!/usr/bin/env bash
#
## example running it from cron
# MAILTO=""
# SHELL=/bin/bash
# VERBOSE=1
# CMD_ON_FAILURE='/etc/init.d/nginx reload'
# * * * * * root timeout -k 2 5 /tmp/check_dns.sh upstream.server.com 2>>/var/log/check_dns.log
# * * * * * root sleep 10 && sed -e :a -e '$q;N;501,$D;ba' -i /var/log/check_dns.log
#
@anapsix
anapsix / mouse_latlon.py
Last active November 4, 2020 12:45
mouse position on screen in python
#!/usr/bin/env python
# I didn't write this
# many examples exist on StackOverflow, etc..
#
# Note: you'll need python-xlib, python-gtk
# sudo apt-get install python-xlib python-gtk2
#
import sys
import os