Skip to content

Instantly share code, notes, and snippets.

View srkiNZ84's full-sized avatar

Srđan (Serge) Đukić srkiNZ84

View GitHub Profile
class Dog:
def __init__(self, name, age):
self.name = name
self.age = age
pass
def bark(self):
print("bark bark!")
def doginfo(self):
@srkiNZ84
srkiNZ84 / read_qr.py
Last active January 10, 2024 21:26
Python script to decode a QR code using OpenCV
import cv2
filename = "/path/to/some_image.png"
image = cv2.imread(filename)
# Docs are here: https://docs.opencv.org/3.4/de/dc3/classcv_1_1QRCodeDetector.html
detector = cv2.QRCodeDetector()
data, vertices_array, binary_qrcode = detector.detectAndDecode(image)
if vertices_array is not None:
@srkiNZ84
srkiNZ84 / aft_delete_recovery_points.sh
Created October 17, 2023 01:55
Bash script to delete all AWS backup recovery points in a vault
#!/bin/bash
# Run:
# aws backup list-recovery-points-by-backup-vault --backup-vault-name aft-controltower-backup-vault | jq --raw-output ".RecoveryPoints[].RecoveryPointArn" > /tmp/aft_recovery_point_arns.txt
# first to get the list of recovery points to delete. Then run this script with the filename as the argument
# e.g.
# aft_delete_recovery_points.sh /tmp/aft_recovery_point_arns.txt
while read -r line; do
echo "deleting recovery point: $line"
@srkiNZ84
srkiNZ84 / get_tf_cloud_vars.sh
Last active July 30, 2023 23:34
Get TF Cloud vars
#!/bin/bash
curl \
--header "Authorization: Bearer $TOKEN" \
--header "Content-Type: application/vnd.api+json" \
"https://app.terraform.io/api/v2/workspaces/$WORKSPACE_ID/vars" > temp_vars_file.json
cat temp_vars_file.json | jq -r '.data[].attributes | "\(.key)=\(.value)"' > myvars.tfvars
# Ensure we have quotes around values
@srkiNZ84
srkiNZ84 / .bash_custom
Created April 6, 2022 02:34
Custom bash bits
#!/bin/bash
# Add git branch name to end of the shell prompt
source /etc/bash_completion.d/git-prompt
# Git bit is just '\[\033[02;03;31m\]$(__git_ps1 " (%s)")\[\033[00m\]' and explained below
# [033 - Set the terminal colours and formatting
# [02;03; - light font (not bold)
# 03; - italic
# 31m - red colour
@srkiNZ84
srkiNZ84 / checksum_demo.sh
Created March 14, 2022 03:06
Generate md5sum on all files and subdirs
#!/usr/bin/bash
# Setup our files
mkdir hashtest
echo hello > hashtest/file1.txt
echo foo > hashtest/file2.txt
echo bar > hashtest/file3.txt
mkdir hashtest/subdir
echo baz > hashtest/subdir/file4.txt
echo hello > hashtest/subdir/file5.txt
@srkiNZ84
srkiNZ84 / list-upgradable.py
Last active March 11, 2022 04:48
Python script to get list of installed packages that have upgrades and output in JSON
#!/usr/bin/python3
# NOTE: Requires the python3-apt package
import apt
import apt_pkg
import json
need_upgrade = []
@srkiNZ84
srkiNZ84 / get_instance_ips.sh
Created June 11, 2021 02:04
Get AWS EC2 instances using AWS CLI query param
#!/bin/bash
aws --profile dev \
ec2 describe-instances \
--query 'Reservations[].Instances[].[InstanceId,Tags[?Key==`Name`].Value[],NetworkInterfaces[].Association.{IP:PublicIp}]'

Bash Snippets

Find AWS EC2 instance by id

aws --profile dev ec2 describe-instances | jq '.Reservations[].Instances[] | select(.InstanceId == "i-0abcdefe412345678")'
@srkiNZ84
srkiNZ84 / app.js
Created May 3, 2021 11:25
NodeJS HelloWorld
const express = require('express')
const app = express()
const port = 3000
const NAME = process.env.NAME || "World"
app.get('/', (req, res) => {
res.send('Hello ' + NAME + '!')
})
app.listen(port, () => {