Skip to content

Instantly share code, notes, and snippets.

Avatar

Keith Gregory kdgregory

View GitHub Profile
@kdgregory
kdgregory / ExplicitProxyV1.java
Created Jun 9, 2022
Examples of using proxies with AWS Java SDK
View ExplicitProxyV1.java
//
// 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 Feb 24, 2022
AutoMDC: manage the SLF4J mapped diagnostic context using try-with-resources
View AutoMDC.java
// 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 Nov 9, 2020
Example of Terraform module to create an SQS queue with modular policy documents
View main.tf
##
## 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 Nov 9, 2020
Example of Terraform module to create an SQS queue.
View main.tf
##
## 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 Feb 19, 2019
A Log4J appender implementation that captures logging output for assertions within test classes.
View Log4JCapturingAppender.java
// 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 Sep 11, 2019
Example program that uses a database connection checkout test to avoid using a read-only connection after Aurora failover.
View AuroraFailoverTest.java
// 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 Mar 1, 2022
Example of generating JSON logging output from Python
View logging_example.py
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 Dec 3, 2018
Examples for AWS messaging talk
View KinesisConsumer.java
// 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 Dec 3, 2018
Examples for Logging presentation
View Main.java
// 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;
@kdgregory
kdgregory / ForgotPasswordExample.java
Created Jan 29, 2017
Examples of unexpected behavior from Cognito IDP; see comments
View ForgotPasswordExample.java
import java.util.HashMap;
import java.util.Map;
import com.amazonaws.services.cognitoidp.AWSCognitoIdentityProviderClient;
import com.amazonaws.services.cognitoidp.model.*;
/**
* Demonstrates that it's possible to login with the original credentials
* after initiating the Forgot Password flow.