Skip to content

Instantly share code, notes, and snippets.

@sumanmaity112
sumanmaity112 / ArchitectureFitnessTest.java
Last active June 17, 2020 14:59
Architecture Fitness Test example
package platform.medium.example.architecture;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noMethods;
import static com.tngtech.archunit.library.dependencies.SlicesRuleDefinition.slices;
import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.importer.ImportOption.DoNotIncludeTests;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
@sumanmaity112
sumanmaity112 / EventListener.java
Created October 22, 2021 15:19
Manual acknowledgement with sqs listener
package com.suman.demo.listener;
import com.suman.demo.Processor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.aws.messaging.listener.Acknowledgment;
import org.springframework.cloud.aws.messaging.listener.SqsMessageDeletionPolicy;
import org.springframework.cloud.aws.messaging.listener.annotation.SqsListener;
import org.springframework.stereotype.Component;
import reactor.core.publisher.BaseSubscriber;
@sumanmaity112
sumanmaity112 / appWithMdc.js
Last active March 7, 2022 17:16
Example of stractured logging with MDC using log4js for NodeJs
import fetch from "node-fetch";
import {logger} from "./logWithMdc.js";
const fetchReceipt = (receiptId, log) => {
log.info(`Fetching receipt for ${receiptId}`)
// https://jsonplaceholder.typicode.com/todos/{id} can be used for testing
return fetch(`https://jsonplaceholder.typicode.com/todos/${receiptId}`)
.then(res => {
if (res.ok) {
log.info(`Successfully fetched receipt for ${receiptId}`)
@sumanmaity112
sumanmaity112 / get-latest-tag-on-git.sh
Last active November 15, 2022 19:22
Get latest tag (sort by semver/refname) on git repository filtered by optional prefix
#!/usr/bin/env bash
set -euo pipefail
# git version 2.38.1
_get_latest_tag(){
local prefix="${1:-}"
git tag -i -l "${prefix}*" --sort -v:refname | head -n1
}
@sumanmaity112
sumanmaity112 / bump-semver.sh
Last active November 17, 2022 16:00
Update the SemVer in the git repository, where it's maintained using git tags, optionally filtered by tag prefix. It can also be used for MonoRepo
#!/usr/bin/env bash
# git version 2.38.1
set -euo pipefail
_get_latest_tag() {
local prefix="${1:-}"
git tag -i -l "${prefix}*" --sort -v:refname | head -n1
}
@sumanmaity112
sumanmaity112 / automated-slim-jre.Dockerfile
Last active October 6, 2023 08:02
Automatically update the required java modules as per application requirements and create custom slim JRE to execute the same
FROM amazoncorretto:17-alpine as corretto-deps
COPY ./greetings/build/libs/greetings.jar /app/
RUN unzip /app/greetings.jar -d temp && \
jdeps \
--print-module-deps \
--ignore-missing-deps \
--recursive \
--multi-release 17 \
@sumanmaity112
sumanmaity112 / rotate_rds_master_password.sh
Created December 5, 2022 19:55
Rotate RDS password with auto generated password and store password in AWS secrets manager
#!/usr/bin/env bash
# aws-cli/2.9.1
_generate_random_password(){
local length="${1:-64}"
# You can fine tune the excluded characters
aws secretsmanager get-random-password --password-length "${length}" --no-include-space --exclude-characters "{#\@\"\`'^&(/)%:;<>,_?}!$" --require-each-included-type --output text
}
@sumanmaity112
sumanmaity112 / rotate_mongodb_database_user_credential.sh
Created December 10, 2022 09:30
Rotate MongoDB Atlas database user password with auto generated password and store password in AWS secrets manager
#!/usr/bin/env bash
# aws-cli/2.9.1
_generate_random_password(){
local length="${1}"
# You can fine tune the excluded characters
aws secretsmanager get-random-password --password-length "${length}" --no-include-space --exclude-characters "{#\@\"\`'^&(/)%:;<>,_?}!$" --require-each-included-type --output text
}
@sumanmaity112
sumanmaity112 / purge-dynamo-table.sh
Created February 7, 2023 23:17
Delete all data from dynamo table without deleting the actual table
#!/bin/bash
# jq-1.6, aws-cli/2.9.19
# shellcheck disable=SC2086
_scan_table() {
local total_segments="$1"
local segment="$2"
shift || true
@sumanmaity112
sumanmaity112 / build.yml
Last active September 20, 2023 17:21
A simple GitHub workflow is used to show how to build and publish Java modules in a monorepo.
name: build
on:
push:
branches:
- main
jobs:
build-matrix-config:
runs-on: ubuntu-22.04