Skip to content

Instantly share code, notes, and snippets.

View srkiNZ84's full-sized avatar

Srđan (Serge) Đukić srkiNZ84

View GitHub Profile
@srkiNZ84
srkiNZ84 / gke_users.csv
Last active March 16, 2021 01:14
Script to make GCP service accounts and generate kubernetes authentication files for them
John Wayne john.wayne@example.com GKE service account for John
Barbara Streisand barbara.streisand@example.com GKE service account for Barbara
@srkiNZ84
srkiNZ84 / bash-child-cgroups.sh
Last active October 7, 2020 22:12
Simple demonstration of using Linux cgroups to set limits on the number of processes
#!/bin/bash
# PREREQUISITES: On Ubuntu 18.04 need to make sure that the "libcgroup1" and "cgroup-tools" packages are installed
MAXNUMPROCS=11
MAXNUMCHILDPROCS=8
PARENTGROUP=sandwich
# Create the parent cgroup
##OPTIONAL: This part should be already there on more recent Linux distributions
@srkiNZ84
srkiNZ84 / copy-ssm-params.py
Created September 22, 2020 03:12
Copy SSM parameters from one path in SSM to another
#!/usr/bin/python3
import boto3
session = boto3.Session(profile_name='foobar')
client = session.client('ssm')
fromPath = "/production/"
toPath = "/uat/"
@srkiNZ84
srkiNZ84 / update_elb_certificate_letsencrypt_route53.sh
Last active August 17, 2021 15:21
Bash script to automate the renewal of LetsEncrypt certificates using DNS authentication with Route53 and then updating the load balancers
#!/usr/bin/bash
# pre-requisites:
# apt install python3-pip awscli
# pip3 install certbot certbot-dns-route53 awscli
# mkdir .certbot/{config,work,logs}
# IAM policy attached to EC2 instance with:
# - route53:ListHostedZones
# - route53:GetChange
# - route53:ChangeResourceRecordSets
@srkiNZ84
srkiNZ84 / check_acm_cert_duplicates.sh
Last active August 4, 2020 08:54
Bash script to check whether the certificate you've got locally is already in AWS Certificate Manager or not (based on md5sum and tags)
#!/bin/bash
CURRENT_CERT_MD5SUM=af375610c480018271caa1b624c838b3
for acmCertificate in $(aws acm list-certificates | jq -r .CertificateSummaryList[].CertificateArn)
do
echo "Cert ARN is $acmCertificate"
ACM_CERT_MD5SUM=$(aws acm list-tags-for-certificate --certificate-arn $acmCertificate | jq -r '.Tags[] | select(.Key | contains("Md5SumCert")) | .Value')
if [[ "$CURRENT_CERT_MD5SUM" == "$ACM_CERT_MD5SUM" ]]
then
@srkiNZ84
srkiNZ84 / archive_repos_git.sh
Last active July 28, 2020 02:44
Couple of bash scripts I wrote to archive Cloudforge repos
#!/bin/bash
filename="git_repo_list.txt"
while read repo
do
echo "Starting to Archive repository '$repo'"
echo "Git checking out repository '$repo'"
git clone $repo
repoShortName=$(echo $repo | grep -E -o '([^\/\.]+).git$')
@srkiNZ84
srkiNZ84 / github_commit.py
Created July 1, 2020 05:06
Python code to commit to GitHub
import base64
import json
import time
import requests
import os
def push_to_github(filename, repo, branch, token):
url="https://api.github.com/repos/" + repo + "/contents/" + filename
fileContents = """Last timestamp: """
#!/bin/bash
KUBECOMMAND="kubectl --kubeconfig ~/.kube/mycluster --namespace dev"
for each in $($KUBECOMMAND get deployments -o jsonpath="{.items[*].metadata.name}" | tr " " "\n" | grep -v tiller-deploy);
do
#kubectl delete ns $each
echo "Deleting deployment $each"
$KUBECOMMAND delete deployment $each
done
@srkiNZ84
srkiNZ84 / Dockerfile-fbprophet
Created March 3, 2020 10:01
Dockerfile to generate docker image with fbprophet and jupyter installed
FROM ubuntu:19.10
RUN apt update && apt install -y python3 python3-dev python3-pip vim wget
RUN pip3 install numpy plotly pandas
RUN pip3 install fbprophet
RUN pip3 install jupyter
RUN mkdir /fbprophet
WORKDIR /fbprophet
RUN wget https://raw.githubusercontent.com/facebook/prophet/master/examples/example_wp_log_peyton_manning.csv
ENTRYPOINT jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root
@srkiNZ84
srkiNZ84 / catchall.py
Created February 18, 2020 09:07
Python script demonstrating using annotations to catch all errors
#!/usr/bin/python3
def catch(function):
def wrapper(*args, **kwargs):
try:
return function(*args, **kwargs)
except Exception as error:
return {'error': error}
return wrapper