Skip to content

Instantly share code, notes, and snippets.

View ruanbekker's full-sized avatar
🇿🇦

Ruan Bekker ruanbekker

🇿🇦
View GitHub Profile
@ruanbekker
ruanbekker / python_github_discussions_graphql.py
Created March 10, 2024 15:54
How to Create Github Discussions via GraphQL API using Python Requests
"""
This script uses the GraphQL API to create discussions programatically using Python and Requests.
"""
import os
import time
import json
import requests
def url_builder(path):
@ruanbekker
ruanbekker / index.html
Created April 21, 2023 12:51
Simple User Card #1
<div class="card">
<img class="avatar" src="https://pbs.twimg.com/profile_images/1610149927455178752/JuWuMNUw_400x400.jpg">
<div class="follow-btn" onclick="followBtn()">Follow</div>
<p class="name">Frank Eno</p>
<p class="username">@xsgames</p>
<p class="info">Game Developer, Web designer<br>Guitar player, father of 4</p>
<div class="bottom-data">9.7K <span>Followers</span> • 240 <span>Following</span> • <span>Since May 2018</span>
</div>
@ruanbekker
ruanbekker / use_curl_to_send_discord_messages.md
Last active June 27, 2022 08:35
Send messages to Discord using curl
<!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.
import socket
def find_open_port():
"""
Use socket's built in ability to find an open port.
"""
sock = socket.socket()
sock.bind(('', 0))
########################################################
# 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 January 22, 2024 07:51
Loki Regex LogQL Query for Nginx Access Logs

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

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
#!/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

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)