Skip to content

Instantly share code, notes, and snippets.

View deangrant's full-sized avatar

Dean Grant deangrant

View GitHub Profile
@deangrant
deangrant / get_client_ip.py
Last active January 5, 2023 14:03
Returns client IP address of a user in Flask
def get_client_ip(
request: list
) -> str:
"""
Returns the client's IP address from an HTTP request object.
Parameters:
request (list): A list representing the HTTP request object.
@deangrant
deangrant / __init__.py
Created January 3, 2023 04:38
dictConfig() to create a logging configuration for Flask (https://flask.palletsprojects.com/en/1.1.x/logging/#basic-configuration)
import os
from logging.config import (
dictConfig
)
from flask import (
Flask
)
def create_app(
@deangrant
deangrant / .env
Last active December 18, 2022 11:42
Initializes cross origin resource sharing for the application in Flask-Cors
CORS_ORIGINS=
CORS_METHODS=
CORS_ALLOW_HEADERS=
CORS_EXPOSE_HEADERS=
CORS_SUPPORTS_CREDENTIALS=
CORS_MAX_AGE=
@deangrant
deangrant / az_network_application_gateway_rewrite_rule_set_show.sh
Created December 10, 2022 09:37
Get the details of a azure application gateway rewrite rule set.
GATEWAY_NAME={{ The name of the application gateway }}
REWRITE_RULE={{ The name of the rewrite rule set }}
RESOURCE_GROUP={{ The name of the resource group }}
az network application-gateway rewrite-rule set show --gateway-name $GATEWAY_NAME \
--name $REWRITE_RULE \
--resource-group $RESOURCE_GROUP
@deangrant
deangrant / hash_csp.sh
Created December 10, 2022 08:03
Generate a hash to allow the execution of inline scripts in a Content Security Policy (CSP)
# The below code snippet will output the expected hash of the script in the console
# error message to use as a hash in a Content Security Policy (CSP). The CSP Level
# 2 specification allows, sha256, sha384, and sha512 hash algorithms.
#
# Example:
#
# echo -n 'doSomething();' | openssl sha256 -binary | openssl base64
# RFWPLDbv2BY+rCkDzsE+0fr8ylGr2R2faWMhq4lfEQc=
#
# Add the following to the script-src directive for your Content Security Policy.
@deangrant
deangrant / Dockerfile
Last active November 30, 2022 08:30
Dockerfile to deploy themes as an archive to Keycloak
FROM alpine:latest AS themes
ADD /themes /themes
WORKDIR /themes
RUN apk add openjdk11 && \
jar cf custom.jar META-INF/ theme/
# Example dockerfile from https://www.keycloak.org/server/containers.
FROM quay.io/keycloak/keycloak:latest as builder
ENV KC_HEALTH_ENABLED=true
@deangrant
deangrant / graylog.conf.j2
Created November 24, 2022 08:36
Template configuration to configure nginx reverse proxy for graylog
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name {{ nginx_server_name }};
rewrite ^ https://$server_name$request_uri? permanent;
#return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
@deangrant
deangrant / az_network_application_gateway_start_stop.sh
Created November 22, 2022 09:12
Code snippets for starting and stopping a Microsoft Azure application gateway
RESOURCE_GROUP={{ name }}
APPLICATION_GATEWAY={{ name }}
# Start application gateway
az network application-gateway start -g $RESOURCE_GROUP -n $APPLICATION_GATEWAY
# Stop application gateway
az network application-gateway stop -g $RESOURCE_GROUP -n $APPLICATION_GATEWAY
@deangrant
deangrant / kml_create.py
Created November 21, 2022 10:05
Template script to create keyhole markup language file
# This is a template script, you can add additional simple fields to the schema,
# and replace the method to iterate over the original datasource.
import simplekml
# Initializes class to represent a KML file.
kml = simplekml.Kml()
# Creates a custom KML schema to be used to add custom data.
@deangrant
deangrant / buffer_geometry.py
Last active November 20, 2022 14:38
Returns coordinates of a polygon object for a center point and radius.
from functools import (
partial
)
import pyproj
from shapely.geometry import (
Point,
Polygon
)
from shapely.ops import (
transform