Skip to content

Instantly share code, notes, and snippets.

View kdgregory's full-sized avatar

Keith Gregory kdgregory

View GitHub Profile
@kdgregory
kdgregory / CombinePluginFiles.java
Created December 9, 2023 15:56
Utility to merge Log4j2Plugins.dat files
import java.io.FileOutputStream;
import java.net.URL;
import java.util.Enumeration;
import org.apache.logging.log4j.core.config.plugins.processor.PluginCache;
/**
* A utility to combine the Log4j2Plugins.dat files from multiple JARs on the
* classpath, writing the output to the current working directory.
@kdgregory
kdgregory / ExplicitProxyV1.java
Created June 9, 2022 11:31
Examples of using proxies with AWS Java SDK
//
// This code has been released into the public domain by the author.
// It may be used or modified without attribution. and is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied.
//
package com.kdgregory.sandbox.aws;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
@kdgregory
kdgregory / AutoMDC.java
Last active February 24, 2022 12:50
AutoMDC: manage the SLF4J mapped diagnostic context using try-with-resources
// This code has been placed in the public domain by the author.
//
// You may use, modify, and redistribute without restriction.
//
// Use of this software is on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied.
package com.kdgregory.example;
import java.util.HashSet;
@kdgregory
kdgregory / main.tf
Last active February 26, 2023 21:35
Example of Terraform module to create an SQS queue with modular policy documents
##
## Main configuration: creates several SQS queues using a module, then
## combines their policies into an application role.
##
provider "aws" {}
module "notifications_queue" {
source = "./modules/sqs"
queue_name = "Notifications"
@kdgregory
kdgregory / main.tf
Created November 9, 2020 12:14
Example of Terraform module to create an SQS queue.
##
## Main configuration: creates several SQS queues using a module, then
## combines their policies into an application role.
##
provider "aws" {}
module "notifications_queue" {
source = "./modules/sqs"
queue_name = "Notifications"
@kdgregory
kdgregory / Log4JCapturingAppender.java
Created February 19, 2019 12:12
A Log4J appender implementation that captures logging output for assertions within test classes.
// Copyright (c) Keith D Gregory
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@kdgregory
kdgregory / AuroraFailoverTest.java
Last active September 11, 2019 00:20
Example program that uses a database connection checkout test to avoid using a read-only connection after Aurora failover.
// Copyright (c) Keith D Gregory, all rights reserved
package com.kdgregory.sandbox.jdbc;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@kdgregory
kdgregory / logging_example.py
Last active June 5, 2024 16:37
Example of generating JSON logging output from Python
import json
import logging
import platform
import sys
import time
import traceback
class JSONFormatter:
"""A formatter for the standard logging module that converts a LogRecord into JSON
@kdgregory
kdgregory / KinesisConsumer.java
Last active December 3, 2018 19:42
Examples for AWS messaging talk
// Copyright (c) Keith D Gregory, all rights reserved
package com.example.aws.kinesis;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@kdgregory
kdgregory / Main.java
Last active December 3, 2018 19:42
Examples for Logging presentation
// Copyright (c) Keith D Gregory, all rights reserved
package com.kdgregory.sandbox.spark.concordance;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.List;
import org.apache.spark.SparkContext;
import org.apache.spark.api.java.JavaRDD;