Skip to content

Instantly share code, notes, and snippets.

Avatar
🇿🇦

Ruan Bekker ruanbekker

🇿🇦
View GitHub Profile
@ruanbekker
ruanbekker / use_curl_to_send_discord_messages.md
Last active June 27, 2022 08:35
Send messages to Discord using curl
View use_curl_to_send_discord_messages.md
View site-maintenance.html
<!doctype html>
<title>Site Maintenance</title>
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
</style>
@ruanbekker
ruanbekker / open_port.py
Created June 25, 2022 21:00 — forked from jdavis/open_port.py
Find an open port in Python.
View open_port.py
import socket
def find_open_port():
"""
Use socket's built in ability to find an open port.
"""
sock = socket.socket()
sock.bind(('', 0))
View 137-karpenter.sh
########################################################
# How To Auto-Scale Kubernetes Clusters With Karpenter #
# https://youtu.be/C-2v7HT-uSA #
########################################################
# Referenced videos:
# - GKE Autopilot - Fully Managed Kubernetes Service From Google: https://youtu.be/Zztufl4mFQ4
#########
# Setup #
@ruanbekker
ruanbekker / loki_nginx_regex_access_logs.md
Last active June 4, 2022 08:18
Loki Regex LogQL Query for Nginx Access Logs
View loki_nginx_regex_access_logs.md

Access Log:

172.16.4.86 - - [04/Jun/2022:07:58:38 +0000] "GET / HTTP/2.0" 301 280 "-" "curl"

Query in Grafana / Loki:

{job="prod/nginx"} |= "GET / " 
@ruanbekker
ruanbekker / prometheus_relabel_configs.md
Created May 28, 2022 12:19
Prometheus Relabel Config Example
View prometheus_relabel_configs.md

Prometheus Relabling

Using a standard prometheus config to scrape two targets:

  • ip-192-168-64-29.multipass:9100
  • ip-192-168-64-30.multipass:9100
global:
  scrape_interval:     15s
 evaluation_interval: 15s
@ruanbekker
ruanbekker / ship_logs_to_loki.py
Created May 27, 2022 14:34
Python Requests to ship logs to Loki API
View ship_logs_to_loki.py
#!/usr/bin/env python3
# docs: https://grafana.com/docs/loki/latest/api/#post-lokiapiv1push
import requests
import time
# variables
LOKI_USERNAME="x"
LOKI_PASSWORD="x"
LOKI_ENDPOINT="https://loki-api.example.com/loki/api/v1/push"
@ruanbekker
ruanbekker / mysqldump_anonamize_column_values.md
Last active May 28, 2022 14:00
Very basic bash script to sanitize a mysql table column from a database dump
View mysqldump_anonamize_column_values.md

This is a basic example with a dirty bash script on how to create a copy of a production database and update the column values of the new (test / staged) database, which might be sensitive or which is not suitable for test environments.

This test is intentional for small datasets.

The flow:

  • mysqldump of the production database to a sql file
  • create the staging database
  • import the production data from the sql file into the staging database
  • run the bash script which loops through each record and updates the selected column value (creditcard_num)
@ruanbekker
ruanbekker / install_geth_ropsten_fast.sh
Last active March 15, 2022 04:57
Boostrap Geth Ropsten Installation
View install_geth_ropsten_fast.sh
#!/usr/bin/env bash
export GOVERSION="1.17.2"
export GETHVERSION="1.10.9"
apt update
apt install wget tar locales-all -y
touch /var/lib/cloud/instance/locale-check.skip
mkdir -p /blockchain/ethereum/data
mkdir -p /usr/local/geth/${GETHVERSION}/bin
@ruanbekker
ruanbekker / aws_sns_sms_python.md
Created October 6, 2021 13:38
Send SMS with AWS SNS using Python
View aws_sns_sms_python.md

Sending SMS's with AWS SNS:

import boto3
sms_number='+27000000000'

sns = boto3.Session(profile_name='default', region_name='eu-west-1').client('sns')

response = sns.publish(
 PhoneNumber=sms_number,