Skip to content

Instantly share code, notes, and snippets.

View davydany's full-sized avatar

David Daniel davydany

View GitHub Profile
#/usr/bin/env python3
"""
LogScan - by David Daniel ([email protected])
===================================================
Usage
-----
usage: logscan.py [-h] [--end_time end_time] [--start_time start_time]
directory [directory ...] date pattern
@davydany
davydany / curl_to_django_httprequest.py
Last active January 25, 2023 17:15
A simple function that can take any cURL statement and creates a Django HTTP Request object from it.
import django.http
def convert_curl_to_httprequest(curl_statement):
import re
# Split by spaces
curl_parts = curl_statement.split(' ')
# Get method
method = curl_parts[1]
@davydany
davydany / docker_topography.py
Created February 6, 2023 22:18
Generate a list of docker nodes that are in the swarm, and the services running inside each of them.
import subprocess
import json
# Get a list of all nodes in the Docker swarm
result = subprocess.run(["docker", "node", "ls", "--format", "{{json .}}"], stdout=subprocess.PIPE, text=True)
nodes = json.loads("[" + result.stdout.strip().replace("}\n{", "},\n{") + "]")
# Iterate over the nodes and print their hostname and IP address
for node in nodes:
print("Node:", node['Hostname'])
@davydany
davydany / logging_to_human.py
Created May 2, 2023 02:42
A simple function that analyzes your logging configuration in Django and prints it out in human readable terms so your management can understand the logging policy of your application.
import os
def print_logging_params(logging_dict):
# Print handlers
if 'handlers' in logging_dict:
print('* Handlers:')
for name, handler in logging_dict['handlers'].items():
print(f" * {name.capitalize()} '{name}'")
if 'class' in handler:
@davydany
davydany / django_generate_http_request.py
Last active June 20, 2023 20:49
Generate a HTTP Request that you can use to testing purposes with a view.
import json
from django.test import RequestFactory
from django.http import QueryDict
def generate_http_request(url, user, method='GET', query_params=None, data=None, headers=None, request_attrs=None):
"""
Generate an HTTP request for a given URL and user.
Args:
url (str): The URL for the request.