Skip to content

Instantly share code, notes, and snippets.

View NIXKnight's full-sized avatar

Saad Ali NIXKnight

View GitHub Profile
@NIXKnight
NIXKnight / check_cloudflare_token.py
Created April 1, 2024 07:29
Check if a Cloudflare Token is valid by using Cloudflare API
import requests
# Replace 'your_cloudflare_api_token_here' with your actual Cloudflare API token
api_token = "your_cloudflare_api_token_here"
# The URL for the Cloudflare API endpoint to check user details
url = "https://api.cloudflare.com/client/v4/user/tokens/verify"
# The headers including the API token for authentication
headers = {
@NIXKnight
NIXKnight / vaultRecursiveSecretsFetcher.py
Created March 22, 2024 11:09
vaultRecursiveSecretsFetcher.py recursively fetches all secrets on a given path and prints them on the terminal in a tabulated format
import hvac
import os
from tabulate import tabulate
from hvac.exceptions import VaultError
# Initialize the HashiCorp Vault client using environment variables for address and token
client = hvac.Client(
url=os.environ['VAULT_ADDR'], # Vault server address
token=os.environ['VAULT_TOKEN'] # Authentication token
)
@NIXKnight
NIXKnight / mem-con.py
Created February 15, 2024 05:23
Get a list of top memory consumers on a Linux system
import sys
import psutil
from tabulate import tabulate
def get_top_memory_processes(n=10):
# Fetch all processes
processes = [p.info for p in psutil.process_iter(attrs=['pid', 'name', 'memory_percent', 'memory_info'])]
# Sort the processes based on memory percentage used
processes.sort(key=lambda x: x['memory_percent'], reverse=True)
@NIXKnight
NIXKnight / test-pod.yaml
Created April 11, 2023 18:10
Pod for Testing
apiVersion: v1
kind: Pod
metadata:
name: default-test
namespace: argoproj
spec:
containers:
- name: default-test
image: debian:bullseye
command:
@NIXKnight
NIXKnight / ansible-wrapper.sh
Last active January 16, 2023 11:04
Passing PostgreSQL Users and Passwords to Ansible via Hashicorp Vault in a Kubernetes Pod
#!/usr/bin/env bash
# +------------------------------------------------------------------------------------------+
# + FILE: ansible-wrapper +
# + +
# + AUTHOR: Saad Ali (https://github.com/NIXKnight) +
# + To be used with https://github.com/NIXKnight/Docker-Kube-Utils.git +
# +------------------------------------------------------------------------------------------+
export K8S_SERVICEACCOUNT_DIR="/var/run/secrets/kubernetes.io/serviceaccount"
@NIXKnight
NIXKnight / django-elb-healthcheck-settings.py
Last active May 14, 2020 07:30
ELB HealthCheck with Django ALLOWED_HOSTS on EC2
import requests
AWS_ELB_META_IPV4_URL = "http://169.254.169.254/latest/meta-data/local-ipv4"
ELB_HEALTHCHECK_HOSTNAME = requests.get(AWS_ELB_META_IPV4_URL, timeout=5).text
ALLOWED_HOSTS += [ELB_HEALTHCHECK_HOSTNAME]

Keybase proof

I hereby claim:

  • I am nixknight on github.
  • I am nixknight (https://keybase.io/nixknight) on keybase.
  • I have a public key ASBNYm02rM6ZSFXJKlx89D2pI-7JB9eit7zmusFDsHh74wo

To claim this, I am signing this object:

@NIXKnight
NIXKnight / PostfixAdminHash.py
Last active November 7, 2018 10:21
Generate PostfixAdmin Compatible MD5 Password Hash
from passlib.hash import md5_crypt
# Suppose that password hash for PostfixAdmin admin user is $1$deceb114$ABCDefghIJKLmN09Q4sTn/
# The salt will be the part between $1$ and $. Hence:
salt = 'deceb114'
# The print command below will generate a PostfixAdmin compatible MD5 hash of the password (which is KNIGHT)
print md5_crypt.using(salt=salt).hash('KNIGHT')