Skip to content

Instantly share code, notes, and snippets.

View davydany's full-sized avatar
💭
Check out my app: The Civic Press! https://www.thecivicpress.com/

David Daniel davydany

💭
Check out my app: The Civic Press! https://www.thecivicpress.com/
View GitHub Profile
@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.
@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 / 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 / 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]
#/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 / capture_stdout.go
Created November 9, 2022 23:16
Go - Capture Stdout from your tests
func startCapturingStdout() {
// capture things from stdout
suite.Old = os.Stdout // keep backup of the real stdout
r, w, _ := os.Pipe()
suite.R = r
suite.W = w
os.Stdout = suite.W
@davydany
davydany / getting-started-with-go-project.md
Created August 31, 2022 18:20
Getting Started with a Go Project

Getting Started with a Go Project

Install Go

MacOS X

brew install go
@davydany
davydany / AppleSigninCheck.dart
Created December 21, 2019 11:49
Check for iOS 13 for Apple Signin
// IMPORTANT: I'll need to fix this when we go past iOS 13.
// Assume the following logic is inside a State<StatefulWidget>
supportsAppleSignIn = false;
@override
void initState() {
super.initState();
// initialize the AuthAgent
this.authAgent = AuthAgent();
@davydany
davydany / getting-started-mysql.md
Last active August 18, 2024 08:38
Getting Started with MySQL

Getting Started with MySQL

I swap between databases all the time for various projects, and end up Googling on how to do the inital setup all the time, so the purpose of this document is to list a set of commands that anyone would end up using in getting started.

Getting Started with the MySQL Client Console

Login to the MySQL console as the root user, with your password for the root user.

@davydany
davydany / README.md
Last active November 21, 2019 16:17
Setting up Django and MySQL Server on a Mac (2019)

Setting up Django and MySQL Server on a Mac (2019)

The following will show how to setup MySQL Server first, and setup Django to work with MySQL. This works with the Mac OS only.

Setup MySQL

Install MySQL with Homebrew