├── miscellaneous ├── webfont-subsetting │ ├── input │ │ └── .gitkeep │ ├── .dockerignore │ ├── README.md │ ├── Dockerfile │ └── mixin.scss ├── ory-hydra-2--client-credentials-flow │ └── README.md └── README.md ├── python ├── testcontainers-integration-tests-with-pytest │ ├── .python-version │ ├── app │ │ ├── aws.py │ │ ├── singleton.py │ │ ├── main.py │ │ └── dbclient.py │ ├── README.md │ ├── pyproject.toml │ └── tests │ │ └── mockutils.py └── README.md ├── spring ├── spring-file-upload │ ├── src │ │ ├── test │ │ │ └── resources │ │ │ │ ├── files │ │ │ │ ├── first.txt │ │ │ │ ├── second.txt │ │ │ │ └── testupload.txt │ │ │ │ └── application.yml │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── dev │ │ │ └── mflash │ │ │ └── guides │ │ │ └── upload │ │ │ ├── service │ │ │ ├── StorageException.java │ │ │ └── StorageService.java │ │ │ └── configuration │ │ │ └── StorageProperties.java │ ├── web │ │ ├── src │ │ │ ├── polyfills.ts │ │ │ ├── assets │ │ │ │ └── images │ │ │ │ │ └── favicon.ico │ │ │ ├── environments │ │ │ │ ├── environment.prod.ts │ │ │ │ └── environment.ts │ │ │ ├── index.html │ │ │ ├── main.ts │ │ │ ├── app │ │ │ │ ├── app.module.ts │ │ │ │ └── upload.service.ts │ │ │ └── styles.scss │ │ ├── tsconfig.app.json │ │ ├── browserslist │ │ ├── tsconfig.json │ │ ├── package.json │ │ └── README.md │ └── README.md ├── springrx-file-upload │ ├── web │ │ ├── src │ │ │ ├── polyfills.ts │ │ │ ├── environments │ │ │ │ ├── environment.ts │ │ │ │ └── environment.prod.ts │ │ │ ├── assets │ │ │ │ └── images │ │ │ │ │ └── favicon.ico │ │ │ ├── index.html │ │ │ ├── main.ts │ │ │ ├── app │ │ │ │ ├── app.module.ts │ │ │ │ └── upload.service.ts │ │ │ └── styles.scss │ │ ├── tsconfig.app.json │ │ ├── browserslist │ │ ├── tsconfig.json │ │ └── package.json │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── dev │ │ │ └── mflash │ │ │ └── guides │ │ │ └── upload │ │ │ ├── service │ │ │ ├── StorageException.java │ │ │ └── StorageService.java │ │ │ └── configuration │ │ │ └── StorageProperties.java │ ├── README.md │ └── middleware │ │ └── package.json ├── spring-data-micronaut-data │ ├── settings.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── README.md │ ├── docker-compose.yml │ └── src │ │ └── main │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── dev │ │ └── mflash │ │ └── guides │ │ └── customer │ │ ├── Launcher.java │ │ └── Customer.java ├── springboot3-local-dev-docker-compose │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── application.yml │ │ │ ├── schema.sql │ │ │ └── data.sql │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── localdev │ │ │ ├── NotesRepository.java │ │ │ ├── Launcher.java │ │ │ └── Note.java │ ├── README.md │ ├── compose.yml │ └── requests.http ├── springboot3-local-dev-testcontainers │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── application.yml │ │ │ │ ├── schema.sql │ │ │ │ └── data.sql │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── localdev │ │ │ │ ├── NotesRepository.java │ │ │ │ ├── Launcher.java │ │ │ │ └── Note.java │ │ └── test │ │ │ └── java │ │ │ ├── LocalLauncher.java │ │ │ └── LocalContainerConfiguration.java │ ├── README.md │ └── requests.http ├── springboot3-aop-retry-on-failure │ ├── requests.http │ ├── README.md │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── retry │ │ │ ├── annotation │ │ │ ├── BackoffStrategy.java │ │ │ └── RetryOnFailure.java │ │ │ ├── Launcher.java │ │ │ ├── RandomlyFailingService.java │ │ │ └── RandomlyFailingController.java │ │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── retry │ │ └── aspect │ │ ├── RetryOnFailureTestService.java │ │ └── AspectAppender.java ├── springboot3-springdoc-integration │ ├── sample.md │ ├── README.md │ ├── compose.yml │ ├── src │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── springdoc │ │ │ │ ├── OpenAPIProperties.java │ │ │ │ ├── Launcher.java │ │ │ │ ├── OpenAPIConfiguration.java │ │ │ │ └── adapter │ │ │ │ ├── database │ │ │ │ └── Note.java │ │ │ │ └── web │ │ │ │ ├── NoteWebView.java │ │ │ │ └── NoteFileView.java │ │ │ └── resources │ │ │ ├── data.sql │ │ │ ├── schema.sql │ │ │ └── application.yml │ └── sample.http ├── springfox3-webmvc-integration │ ├── notes.csv │ ├── README.md │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── dev │ │ │ └── mflash │ │ │ └── guides │ │ │ └── springfox3 │ │ │ └── NoteRepository.java │ └── docker-compose.yml ├── spring-security-jwt-auth │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── application.yml │ │ │ └── public.pem │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── jwt │ │ │ ├── Launcher.java │ │ │ ├── JwtProperties.java │ │ │ ├── PEMEncoder.java │ │ │ └── web │ │ │ └── GreetingController.java │ └── README.md ├── spring-content-negotiation │ ├── README.md │ └── src │ │ └── main │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── dev │ │ └── mflash │ │ └── guides │ │ └── spring │ │ └── negotiation │ │ ├── Game.java │ │ ├── Launcher.java │ │ └── GameController.java ├── spring-messaging-rabbitmq │ ├── README.md │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── dev │ │ │ └── mflash │ │ │ └── guides │ │ │ └── rabbitmq │ │ │ ├── Launcher.java │ │ │ └── service │ │ │ └── Reader.java │ └── docker-compose.yml ├── spring-data-mongo-repository │ ├── README.md │ ├── src │ │ └── main │ │ │ ├── java │ │ │ └── dev │ │ │ │ └── mflash │ │ │ │ └── guides │ │ │ │ └── mongo │ │ │ │ ├── event │ │ │ │ ├── CascadeType.java │ │ │ │ ├── Cascade.java │ │ │ │ └── IdentifierCallback.java │ │ │ │ ├── repository │ │ │ │ ├── UserRepository.java │ │ │ │ ├── SessionRepository.java │ │ │ │ └── AccountRepository.java │ │ │ │ ├── Launcher.java │ │ │ │ ├── domain │ │ │ │ ├── Session.java │ │ │ │ ├── User.java │ │ │ │ └── Account.java │ │ │ │ └── configuration │ │ │ │ ├── MongoConfiguration.java │ │ │ │ └── ZonedDateTimeConverters.java │ │ │ └── resources │ │ │ └── application.yml │ └── docker-compose.yml ├── spring-rest-error-handling │ ├── README.md │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── dev │ │ │ └── mflash │ │ │ └── guides │ │ │ └── resterror │ │ │ ├── domain │ │ │ └── Genre.java │ │ │ ├── Launcher.java │ │ │ ├── persistence │ │ │ ├── CustomUserRepository.java │ │ │ └── BookRepository.java │ │ │ ├── exception │ │ │ ├── ResourceNotFoundException.java │ │ │ └── InvalidOperationException.java │ │ │ └── security │ │ │ └── CustomUserConverter.java │ ├── docker-compose.yml │ └── schema.sql ├── spring-security-jwt-auth-eddsa │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── public.pem │ │ │ ├── private.pem │ │ │ ├── application.yml │ │ │ └── data.sql │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── jwt │ │ │ ├── userdetails │ │ │ ├── CustomUserRepository.java │ │ │ └── CustomUser.java │ │ │ ├── Launcher.java │ │ │ ├── PEMEncoder.java │ │ │ ├── web │ │ │ ├── GreetingController.java │ │ │ └── UserController.java │ │ │ └── EdDSAKeyReader.java │ └── README.md ├── spring-data-jdbc-hikari-leak-detection │ ├── README.md │ └── src │ │ └── main │ │ ├── resources │ │ ├── application.yml │ │ └── data.sql │ │ └── java │ │ └── com │ │ └── example │ │ ├── Launcher.java │ │ ├── Book.java │ │ ├── BookRepository.java │ │ └── BookController.java ├── springboot4-aop-method-logging │ ├── README.md │ └── src │ │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── method │ │ │ └── logging │ │ │ └── AspectAppender.java │ │ └── main │ │ └── java │ │ └── com │ │ └── example │ │ └── method │ │ └── logging │ │ ├── GreetingService.java │ │ ├── Launcher.java │ │ └── annotation │ │ └── LogEntryExit.java ├── spring-security-jwt-auth-custom-user │ ├── README.md │ └── src │ │ └── main │ │ ├── resources │ │ ├── application.yml │ │ ├── data.sql │ │ └── public.pem │ │ └── java │ │ └── com │ │ └── example │ │ └── jwt │ │ ├── userdetails │ │ ├── CustomUserRepository.java │ │ └── CustomUser.java │ │ ├── Launcher.java │ │ ├── JwtProperties.java │ │ ├── PEMEncoder.java │ │ └── web │ │ ├── GreetingController.java │ │ └── UserController.java ├── spring-security-resource-server-error-handling │ ├── README.md │ └── src │ │ └── main │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── dev │ │ └── mflash │ │ └── guides │ │ └── tokenval │ │ └── introspection │ │ ├── Launcher.java │ │ └── security │ │ └── WWWAuthenticateHeaderBuilder.java ├── spring-security-token-introspection │ ├── README.md │ └── src │ │ └── main │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── dev │ │ └── mflash │ │ └── guides │ │ └── tokenval │ │ └── introspection │ │ └── Launcher.java ├── spring-security-token-validation-hybrid │ ├── README.md │ └── src │ │ └── main │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── dev │ │ └── mflash │ │ └── guides │ │ └── tokenval │ │ └── hybrid │ │ ├── security │ │ ├── OidcProperties.java │ │ └── CustomTokenValidator.java │ │ └── Launcher.java └── spring-security-token-validation-local │ ├── README.md │ └── src │ └── main │ ├── resources │ └── application.yml │ └── java │ └── dev │ └── mflash │ └── guides │ └── tokenval │ └── local │ ├── security │ ├── OidcProperties.java │ └── CustomTokenValidator.java │ └── Launcher.java ├── cloud ├── communicating-with-containers-on-docker-network │ ├── prerequisites │ │ ├── greeter-ui │ │ │ ├── src │ │ │ │ ├── assets │ │ │ │ │ └── .gitkeep │ │ │ │ ├── environments │ │ │ │ │ ├── environment.prod.ts │ │ │ │ │ └── environment.ts │ │ │ │ ├── styles.css │ │ │ │ ├── favicon.ico │ │ │ │ ├── index.html │ │ │ │ ├── app │ │ │ │ │ ├── greeting.service.ts │ │ │ │ │ ├── app.module.ts │ │ │ │ │ └── app.component.ts │ │ │ │ └── main.ts │ │ │ ├── .dockerignore │ │ │ ├── tsconfig.app.json │ │ │ ├── Dockerfile │ │ │ ├── browserslist │ │ │ ├── tsconfig.json │ │ │ ├── .gitignore │ │ │ └── package.json │ │ └── greeter-api │ │ │ ├── micronaut-cli.yml │ │ │ ├── .gitignore │ │ │ ├── src │ │ │ └── main │ │ │ │ ├── resources │ │ │ │ ├── application.yml │ │ │ │ └── logback.xml │ │ │ │ └── java │ │ │ │ └── dev │ │ │ │ └── mflash │ │ │ │ └── guides │ │ │ │ └── greeter │ │ │ │ ├── Application.java │ │ │ │ ├── Greeting.java │ │ │ │ └── GreetingController.java │ │ │ └── Dockerfile │ ├── README.md │ ├── scenario-2-on-different-networks │ │ ├── greeter-api │ │ │ └── docker-compose.yml │ │ └── greeter-ui │ │ │ └── docker-compose.yml │ └── scenario-1-on-the-same-network │ │ └── docker-compose.yml └── README.md ├── @sample └── spring │ └── springboot3-notes-api │ ├── sample.md │ ├── src │ └── main │ │ ├── resources │ │ ├── application.yml │ │ ├── data.sql │ │ └── schema.sql │ │ └── java │ │ └── com │ │ └── example │ │ └── notes │ │ ├── Launcher.java │ │ └── adapter │ │ ├── database │ │ └── Note.java │ │ └── web │ │ ├── NoteWebView.java │ │ └── NoteFileView.java │ ├── compose.yml │ └── sample.http ├── java ├── docker-healthcheck │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── dev │ │ │ └── mflash │ │ │ └── guides │ │ │ └── java │ │ │ └── healthcheck │ │ │ └── Launcher.java │ ├── README.md │ └── Dockerfile ├── deep-copying │ ├── README.md │ └── src │ │ └── main │ │ └── java │ │ └── dev │ │ └── mflash │ │ └── guides │ │ └── java │ │ └── deepcopy │ │ └── domain │ │ ├── Copyable.java │ │ ├── Author.java │ │ └── Book.java ├── aop-compile-time │ ├── README.md │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── aop │ │ │ ├── Launcher.java │ │ │ ├── GreetingHandler.java │ │ │ └── annotation │ │ │ └── LogEntryExit.java │ │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── aop │ │ ├── aspect │ │ └── AspectAppender.java │ │ └── GreetingHandlerTest.java ├── jackson3-polymorphic-requests │ ├── README.md │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── example │ │ └── jackson │ │ └── polymorphic │ │ ├── ItemCategory.java │ │ ├── Software.java │ │ ├── Accessory.java │ │ └── CartItem.java └── jacoco-coverage-with-maven │ ├── README.md │ └── src │ ├── test │ └── resources │ │ └── com │ │ └── example │ │ ├── factorialDataSetSmall.csv │ │ └── fibonacciDataSet.csv │ └── main │ └── java │ └── com │ └── example │ ├── PangramChecker.java │ ├── PalindromeChecker.java │ ├── Factorial.java │ └── Fibonacci.java ├── nodejs ├── logging-with-winston │ ├── README.md │ ├── tsconfig.json │ ├── src │ │ ├── server.ts │ │ ├── configuration │ │ │ └── environment.ts │ │ └── helper │ │ │ ├── default.logger.ts │ │ │ └── request.logger.ts │ └── package.json ├── morgan-request-logging │ ├── README.md │ ├── src │ │ ├── configuration │ │ │ └── environment.ts │ │ ├── server.ts │ │ └── helper │ │ │ └── request.logger.ts │ ├── tsconfig.json │ └── package.json ├── express-with-typescript │ ├── README.md │ ├── src │ │ └── server.ts │ ├── tsconfig.json │ └── package.json ├── linting-with-typescript-eslint │ ├── README.md │ ├── tsconfig.json │ ├── src │ │ ├── server.ts │ │ ├── configuration │ │ │ └── environment.ts │ │ └── helper │ │ │ ├── default.logger.ts │ │ │ └── request.logger.ts │ ├── .eslintrc.js │ └── package.json ├── express-postgres-api │ ├── src │ │ ├── model │ │ │ └── song.ts │ │ ├── api │ │ │ ├── default.ts │ │ │ └── index.ts │ │ ├── helper │ │ │ ├── default.logger.ts │ │ │ └── request.logger.ts │ │ ├── server.ts │ │ └── configuration │ │ │ └── environment.ts │ ├── README.md │ ├── docker-compose.yml │ ├── .env │ ├── song.sql │ ├── tsconfig.json │ ├── .eslintrc.js │ └── package.json ├── logging-with-log4js-node │ ├── README.md │ ├── tsconfig.json │ ├── src │ │ ├── server.ts │ │ ├── configuration │ │ │ └── environment.ts │ │ └── helper │ │ │ ├── default.logger.ts │ │ │ └── request.logger.ts │ └── package.json └── README.md ├── @archive ├── spring │ ├── springboot2-springdoc-webmvc-integration │ │ ├── notes.csv │ │ ├── README.md │ │ ├── src │ │ │ └── main │ │ │ │ ├── resources │ │ │ │ └── application.yml │ │ │ │ └── java │ │ │ │ └── dev │ │ │ │ └── mflash │ │ │ │ └── guides │ │ │ │ └── springdoc │ │ │ │ ├── NoteRepository.java │ │ │ │ └── Launcher.java │ │ └── docker-compose.yml │ ├── springboot2-springdoc-webmvcfn-integration │ │ ├── notes.csv │ │ ├── README.md │ │ ├── src │ │ │ └── main │ │ │ │ ├── resources │ │ │ │ └── application.yml │ │ │ │ └── java │ │ │ │ └── dev │ │ │ │ └── mflash │ │ │ │ └── guides │ │ │ │ └── springdoc │ │ │ │ └── NoteRepository.java │ │ └── docker-compose.yml │ └── springboot2-aop-retry-on-failure │ │ ├── README.md │ │ └── src │ │ ├── main │ │ └── java │ │ │ └── dev │ │ │ └── mflash │ │ │ └── guides │ │ │ └── retry │ │ │ ├── annotation │ │ │ ├── BackoffStrategy.java │ │ │ └── RetryOnFailure.java │ │ │ ├── Launcher.java │ │ │ ├── RandomlyFailingService.java │ │ │ └── RandomlyFailingController.java │ │ └── test │ │ └── java │ │ └── dev │ │ └── mflash │ │ └── guides │ │ └── retry │ │ └── aspect │ │ ├── RetryOnFailureTestService.java │ │ └── AspectAppender.java └── miscellaneous │ └── ory-hydra-1--client-credentials-flow │ ├── README.md │ └── quickstart.yml ├── aws ├── localstack-with-aws-cli │ ├── README.md │ ├── compose.yml │ └── apod.json ├── localstack-lambda-with-sns-trigger │ ├── README.md │ ├── compose.yml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── example │ │ └── SnsRequestHandler.java ├── localstack-lambda-with-sqs-trigger │ ├── README.md │ ├── index.mjs │ └── compose.yml ├── localstack-lambda-with-eventbridge-rule-trigger │ ├── README.md │ ├── main.py │ ├── events.json │ └── compose.yml └── README.md ├── @ ├── archives │ └── spring │ │ └── springboot3-aop-method-logging │ │ ├── README.md │ │ └── src │ │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── method │ │ │ └── logging │ │ │ └── AspectAppender.java │ │ └── main │ │ └── java │ │ └── com │ │ └── example │ │ └── method │ │ └── logging │ │ ├── GreetingService.java │ │ ├── annotation │ │ └── LogEntryExit.java │ │ └── Launcher.java └── templates │ └── maven-java-template │ └── pom.xml ├── micronaut ├── mn4-aws-lambda-with-eventbridge │ ├── README.md │ ├── events.json │ ├── compose.yml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── example │ │ ├── FunctionRequestHandler.java │ │ └── ScheduledEventService.java └── README.md ├── ARCHIVE.md ├── README.md ├── .gitignore └── LICENSE.md /miscellaneous/webfont-subsetting/input/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /miscellaneous/webfont-subsetting/.dockerignore: -------------------------------------------------------------------------------- 1 | * 2 | !run.py 3 | -------------------------------------------------------------------------------- /python/testcontainers-integration-tests-with-pytest/.python-version: -------------------------------------------------------------------------------- 1 | 3.13 2 | -------------------------------------------------------------------------------- /spring/spring-file-upload/src/test/resources/files/first.txt: -------------------------------------------------------------------------------- 1 | Spring Framework 1 -------------------------------------------------------------------------------- /spring/spring-file-upload/web/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | import 'zone.js/dist/zone'; 2 | -------------------------------------------------------------------------------- /spring/spring-file-upload/src/test/resources/files/second.txt: -------------------------------------------------------------------------------- 1 | Spring Framework 2 -------------------------------------------------------------------------------- /spring/spring-file-upload/src/test/resources/files/testupload.txt: -------------------------------------------------------------------------------- 1 | Spring Framework -------------------------------------------------------------------------------- /spring/springrx-file-upload/web/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | import 'zone.js/dist/zone'; 2 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-ui/src/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spring/spring-data-micronaut-data/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'spring-jdbc-micronaut-data' 2 | -------------------------------------------------------------------------------- /spring/springboot3-local-dev-docker-compose/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring.sql.init.mode: always 2 | -------------------------------------------------------------------------------- /spring/springboot3-local-dev-testcontainers/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring.sql.init.mode: always 2 | -------------------------------------------------------------------------------- /@sample/spring/springboot3-notes-api/sample.md: -------------------------------------------------------------------------------- 1 | `pbpaste` is a macOS utility to paste data from the clipboard to STDOUT. -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-ui/.dockerignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | node_modules/ -------------------------------------------------------------------------------- /spring/springboot3-aop-retry-on-failure/requests.http: -------------------------------------------------------------------------------- 1 | # trigger a retry 2 | curl -s http://localhost:8080/random 3 | -------------------------------------------------------------------------------- /spring/springboot3-springdoc-integration/sample.md: -------------------------------------------------------------------------------- 1 | `pbpaste` is a macOS utility to paste data from the clipboard to STDOUT. -------------------------------------------------------------------------------- /spring/springrx-file-upload/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8079 3 | storage: 4 | location: files -------------------------------------------------------------------------------- /java/docker-healthcheck/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | management: 2 | endpoint: 3 | health: 4 | show-details: always 5 | -------------------------------------------------------------------------------- /java/deep-copying/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Creating deep copies in Java](https://mflash.dev/post/2021/06/19/creating-deep-copies-in-java/) 2 | -------------------------------------------------------------------------------- /spring/springfox3-webmvc-integration/notes.csv: -------------------------------------------------------------------------------- 1 | Hello Rust, Learning Rust is an eye-opening experience 2 | BDD, Get over with TDD; it's time for BDD -------------------------------------------------------------------------------- /nodejs/logging-with-winston/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Logging on Node.js with winston](https://mflash.dev/post/2020/01/26/logging-on-nodejs-with-winston/) -------------------------------------------------------------------------------- /nodejs/morgan-request-logging/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Request logging with morgan](https://mflash.dev/post/2019/08/13/request-logging-with-morgan/) 2 | -------------------------------------------------------------------------------- /java/docker-healthcheck/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Java-based health check for Docker](https://mflash.dev/post/2021/03/01/java-based-health-check-for-docker/) 2 | -------------------------------------------------------------------------------- /nodejs/express-with-typescript/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Using Express with TypeScript](https://mflash.dev/post/2019/01/12/using-express-with-typescript/) 2 | -------------------------------------------------------------------------------- /nodejs/linting-with-typescript-eslint/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Linting with TypeScript ESLint](https://mflash.dev/post/2019/08/16/linting-with-typescript-eslint/) -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | jwt: 2 | private-key: classpath:private.pem 3 | public-key: classpath:public.pem 4 | -------------------------------------------------------------------------------- /nodejs/express-postgres-api/src/model/song.ts: -------------------------------------------------------------------------------- 1 | export interface Song { 2 | id?: string; 3 | title: string; 4 | album: string; 5 | artist: string; 6 | } 7 | -------------------------------------------------------------------------------- /nodejs/logging-with-log4js-node/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Logging on Node.js with log4js-node](https://mflash.dev/post/2019/08/14/logging-on-nodejs-with-log4js-node/) -------------------------------------------------------------------------------- /@archive/spring/springboot2-springdoc-webmvc-integration/notes.csv: -------------------------------------------------------------------------------- 1 | Hello Rust, Learning Rust is an eye-opening experience 2 | BDD, Get over with TDD; it's time for BDD -------------------------------------------------------------------------------- /@archive/spring/springboot2-springdoc-webmvcfn-integration/notes.csv: -------------------------------------------------------------------------------- 1 | Hello Rust, Learning Rust is an eye-opening experience 2 | BDD, Get over with TDD; it's time for BDD -------------------------------------------------------------------------------- /miscellaneous/webfont-subsetting/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [How I subset fonts for my site](https://www.naiyerasif.com/post/2024/06/27/how-i-subset-fonts-for-my-site/) 2 | -------------------------------------------------------------------------------- /python/testcontainers-integration-tests-with-pytest/app/aws.py: -------------------------------------------------------------------------------- 1 | import boto3 2 | 3 | s3 = boto3.client("s3") 4 | secretsmanager = boto3.client("secretsmanager") 5 | -------------------------------------------------------------------------------- /spring/spring-content-negotiation/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Content negotiation in Spring Boot](https://mflash.dev/post/2021/03/27/content-negotiation-in-spring-boot/) 2 | -------------------------------------------------------------------------------- /spring/spring-file-upload/web/src/assets/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Microflash/guides/HEAD/spring/spring-file-upload/web/src/assets/images/favicon.ico -------------------------------------------------------------------------------- /spring/spring-file-upload/web/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true, 3 | apiUrl: 'http://localhost:8080/file' 4 | }; 5 | -------------------------------------------------------------------------------- /spring/spring-file-upload/web/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: false, 3 | apiUrl: 'http://localhost:8080/file' 4 | }; 5 | -------------------------------------------------------------------------------- /spring/springfox3-webmvc-integration/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [API Documentation with Springfox 3](https://mflash.dev/post/2020/09/05/api-documentation-with-springfox-3/) 2 | -------------------------------------------------------------------------------- /spring/springrx-file-upload/web/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: false, 3 | apiUrl: 'http://localhost:8080/file' 4 | }; 5 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-ui/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-ui/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /java/aop-compile-time/README.md: -------------------------------------------------------------------------------- 1 | > See [Weaving aspects at compile-time with AspectJ](https://www.naiyerasif.com/post/2021/10/10/weaving-aspects-at-compile-time-with-aspectj/) 2 | -------------------------------------------------------------------------------- /java/jackson3-polymorphic-requests/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Polymorphic Requests with Jackson](https://www.naiyerasif.com/post/2020/06/11/polymorphic-requests-with-jackson/) 2 | -------------------------------------------------------------------------------- /java/jacoco-coverage-with-maven/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Code Coverage with JaCoCo and Maven](https://www.naiyerasif.com/post/2018/11/15/code-coverage-with-jacoco-and-maven/) 2 | -------------------------------------------------------------------------------- /nodejs/express-postgres-api/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Developing an API with Express and Postgres](https://mflash.dev/post/2019/08/19/developing-an-api-with-express-and-postgres/) -------------------------------------------------------------------------------- /spring/spring-messaging-rabbitmq/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Messaging with RabbitMQ and Spring Boot](https://mflash.dev/post/2018/12/13/messaging-with-rabbitmq-and-spring-boot/) 2 | -------------------------------------------------------------------------------- /spring/springrx-file-upload/web/src/assets/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Microflash/guides/HEAD/spring/springrx-file-upload/web/src/assets/images/favicon.ico -------------------------------------------------------------------------------- /spring/springrx-file-upload/web/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true, 3 | apiUrl: 'http://localhost:8080/file' 4 | }; 5 | -------------------------------------------------------------------------------- /spring/spring-data-mongo-repository/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Persisting documents with MongoRepository](https://mflash.dev/post/2019/07/08/persisting-documents-with-mongorepository/) 2 | -------------------------------------------------------------------------------- /spring/spring-file-upload/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Uploading files with Spring Boot and Angular](https://mflash.dev/post/2018/09/09/uploading-files-with-spring-boot-and-angular/) 2 | -------------------------------------------------------------------------------- /spring/spring-rest-error-handling/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Error handling for a Spring-based REST API](https://mflash.dev/post/2020/07/26/error-handling-for-a-spring-based-rest-api/) 2 | -------------------------------------------------------------------------------- /spring/springrx-file-upload/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Uploading files with Spring Boot and Express](https://mflash.dev/post/2019/11/08/uploading-files-with-spring-boot-and-express/) 2 | -------------------------------------------------------------------------------- /aws/localstack-with-aws-cli/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Working with AWS on local using LocalStack](https://www.naiyerasif.com/post/2021/11/16/working-with-aws-on-local-using-localstack/) 2 | -------------------------------------------------------------------------------- /spring/spring-content-negotiation/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | mvc: 3 | contentnegotiation: 4 | favor-parameter: true 5 | parameter-name: mediatype 6 | -------------------------------------------------------------------------------- /spring/spring-data-micronaut-data/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Microflash/guides/HEAD/spring/spring-data-micronaut-data/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /spring/spring-messaging-rabbitmq/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | rabbitmq: 3 | host: localhost 4 | port: 5672 5 | username: rabbitmq 6 | password: rabbitmq -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-eddsa/src/main/resources/public.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MCowBQYDK2VwAyEAVCFQgtx6dVlQ1yiNNjmsHCkSO0y9WJ45/DCB8egpNvI= 3 | -----END PUBLIC KEY----- -------------------------------------------------------------------------------- /spring/spring-data-jdbc-hikari-leak-detection/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Detecting a connection leak with Hikari](https://www.naiyerasif.com/post/2022/09/18/detecting-a-connection-leak-with-hikari/) 2 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-eddsa/src/main/resources/private.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MC4CAQAwBQYDK2VwBCIEINjxhqNQVwQ5lINfzDw74BxTWPeycEO5NqKwBUblQ9Tw 3 | -----END PRIVATE KEY----- -------------------------------------------------------------------------------- /spring/springboot3-springdoc-integration/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [API documentation with springdoc-openapi](https://www.naiyerasif.com/post/2020/06/27/api-documentation-with-springdoc-openapi/) 2 | -------------------------------------------------------------------------------- /@archive/spring/springboot2-springdoc-webmvc-integration/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [API Documentation with springdoc-openapi](https://mflash.dev/post/2020/06/27/api-documentation-with-springdoc-openapi/) 2 | -------------------------------------------------------------------------------- /aws/localstack-lambda-with-sns-trigger/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Using LocalStack for AWS Lambda with SNS trigger](https://www.naiyerasif.com/post/2024/03/03/using-localstack-for-aws-lambda-with-sns-trigger/) -------------------------------------------------------------------------------- /java/deep-copying/src/main/java/dev/mflash/guides/java/deepcopy/domain/Copyable.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.java.deepcopy.domain; 2 | 3 | public interface Copyable { 4 | 5 | T copy(); 6 | } 7 | -------------------------------------------------------------------------------- /miscellaneous/ory-hydra-2--client-credentials-flow/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Client Credentials flow with Ory Hydra](https://www.naiyerasif.com/post/2022/08/21/client-credentials-flow-with-ory-hydra/) 2 | -------------------------------------------------------------------------------- /spring/spring-rest-error-handling/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | url: jdbc:postgresql://localhost:5432/spring 4 | username: erin 5 | password: richards 6 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Securing Spring Boot APIs with JWT Authentication](https://www.naiyerasif.com/post/2020/04/10/securing-spring-boot-apis-with-jwt-authentication/) 2 | -------------------------------------------------------------------------------- /@archive/spring/springboot2-springdoc-webmvcfn-integration/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [API Documentation with springdoc-openapi](https://mflash.dev/post/2020/06/27/api-documentation-with-springdoc-openapi/) 2 | -------------------------------------------------------------------------------- /aws/localstack-lambda-with-sqs-trigger/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Using LocalStack for AWS Lambda with SQS trigger](https://www.naiyerasif.com/post/2024/02/11/using-localstack-for-aws-lambda-with-sqs-trigger/) 2 | -------------------------------------------------------------------------------- /spring/spring-data-micronaut-data/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Querying Postgres with Spring Data and Micronaut Data](https://mflash.dev/post/2020/04/05/querying-postgres-with-spring-data-and-micronaut-data/) 2 | -------------------------------------------------------------------------------- /spring/spring-data-mongo-repository/src/main/java/dev/mflash/guides/mongo/event/CascadeType.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.mongo.event; 2 | 3 | public enum CascadeType { 4 | ALL, SAVE, DELETE 5 | } 6 | -------------------------------------------------------------------------------- /@archive/spring/springboot2-aop-retry-on-failure/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Retrying on failure with Resilience4J and Aspects](https://mflash.dev/post/2020/09/26/retrying-on-failure-with-resilience4j-and-aspects/) 2 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Communicating with containers on Docker network](https://mflash.dev/post/2018/08/05/communicating-with-containers-on-docker-network/) 2 | -------------------------------------------------------------------------------- /spring/spring-content-negotiation/src/main/java/dev/mflash/guides/spring/negotiation/Game.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.spring.negotiation; 2 | 3 | public record Game(String title, String publisher) { 4 | } 5 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-eddsa/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Securing Spring Boot APIs with JWT Authentication](https://www.naiyerasif.com/post/2020/04/10/securing-spring-boot-apis-with-jwt-authentication/) 2 | -------------------------------------------------------------------------------- /spring/springboot3-aop-retry-on-failure/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Retrying on failure with Resilience4J and Aspects](https://www.naiyerasif.com/post/2020/09/26/retrying-on-failure-with-resilience4j-and-aspects/) 2 | -------------------------------------------------------------------------------- /spring/springboot4-aop-method-logging/README.md: -------------------------------------------------------------------------------- 1 | > See [Logging methods with AspectJ in a Spring application](https://www.naiyerasif.com/post/2020/09/13/logging-methods-with-aspectj-in-a-spring-application/) 2 | -------------------------------------------------------------------------------- /@archive/miscellaneous/ory-hydra-1--client-credentials-flow/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Client Credentials flow with Ory Hydra](https://www.naiyerasif.com/archive/2022/08/21/client-credentials-flow-with-ory-hydra--1/) 2 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-api/micronaut-cli.yml: -------------------------------------------------------------------------------- 1 | profile: service 2 | defaultPackage: dev.mflash.guides.greeter 3 | --- 4 | testFramework: junit 5 | sourceLanguage: java -------------------------------------------------------------------------------- /java/jackson3-polymorphic-requests/src/main/java/com/example/jackson/polymorphic/ItemCategory.java: -------------------------------------------------------------------------------- 1 | package com.example.jackson.polymorphic; 2 | 3 | public enum ItemCategory { 4 | SOFTWARE, 5 | ACCESSORY 6 | } 7 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-custom-user/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Securing Spring Boot APIs with JWT Authentication](https://www.naiyerasif.com/post/2020/04/10/securing-spring-boot-apis-with-jwt-authentication/) 2 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-eddsa/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | jwt: 2 | private-key: classpath:private.pem 3 | public-key: classpath:public.pem 4 | 5 | spring.datasource: 6 | url: jdbc:h2:mem:sa 7 | -------------------------------------------------------------------------------- /spring/spring-file-upload/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | servlet: 3 | multipart: 4 | enabled: true 5 | max-file-size: 50MB 6 | max-request-size: 50MB 7 | storage: 8 | location: files -------------------------------------------------------------------------------- /spring/spring-rest-error-handling/src/main/java/dev/mflash/guides/resterror/domain/Genre.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.resterror.domain; 2 | 3 | public enum Genre { 4 | fantasy, 5 | thriller, 6 | scifi 7 | } 8 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-custom-user/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | jwt: 2 | private-key: classpath:private.pem 3 | public-key: classpath:public.pem 4 | 5 | spring.datasource: 6 | url: jdbc:h2:mem:sa 7 | -------------------------------------------------------------------------------- /spring/spring-security-resource-server-error-handling/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Error handling for Spring Security Resource Server](https://mflash.dev/post/2021/01/19/error-handling-for-spring-security-resource-server/) 2 | -------------------------------------------------------------------------------- /spring/spring-security-token-introspection/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Protecting endpoints with Spring Security Resource Server](https://mflash.dev/post/2020/11/15/protecting-endpoints-with-spring-security-resource-server/) 2 | -------------------------------------------------------------------------------- /@/archives/spring/springboot3-aop-method-logging/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Logging methods with AspectJ in a Spring application](https://www.naiyerasif.com/post/2020/09/13/logging-methods-with-aspectj-in-a-spring-application/) 2 | -------------------------------------------------------------------------------- /micronaut/mn4-aws-lambda-with-eventbridge/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [How to implement an AWS Lambda function using Micronaut](https://www.naiyerasif.com/post/2025/07/13/how-to-implement-an-aws-lambda-function-using-micronaut/) 2 | -------------------------------------------------------------------------------- /spring/spring-security-token-validation-hybrid/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Protecting endpoints with Spring Security Resource Server](https://mflash.dev/post/2020/11/15/protecting-endpoints-with-spring-security-resource-server/) 2 | -------------------------------------------------------------------------------- /spring/spring-security-token-validation-local/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Protecting endpoints with Spring Security Resource Server](https://mflash.dev/post/2020/11/15/protecting-endpoints-with-spring-security-resource-server/) 2 | -------------------------------------------------------------------------------- /spring/springfox3-webmvc-integration/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | platform: postgres 4 | url: jdbc:postgresql://localhost:5432/spring 5 | username: erin 6 | password: richards -------------------------------------------------------------------------------- /@sample/spring/springboot3-notes-api/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | password: stacy 4 | username: gwen 5 | url: jdbc:postgresql://localhost:5432/brooklyn 6 | sql.init.mode: always 7 | -------------------------------------------------------------------------------- /aws/localstack-lambda-with-sqs-trigger/index.mjs: -------------------------------------------------------------------------------- 1 | export const handler = async (event) => { 2 | const messages = event.Records.map(record => record.body); 3 | messages.forEach(message => console.log(message)); 4 | return messages; 5 | }; 6 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-ui/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Microflash/guides/HEAD/cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-ui/src/favicon.ico -------------------------------------------------------------------------------- /spring/spring-file-upload/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | servlet: 3 | multipart: 4 | enabled: true 5 | max-file-size: 50MB 6 | max-request-size: 50MB 7 | storage: 8 | location: src/test/resources/files -------------------------------------------------------------------------------- /spring/springboot3-local-dev-docker-compose/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Improved local development using containers in Spring Boot 3.1](https://www.naiyerasif.com/post/2023/09/08/improved-local-development-using-containers-in-spring-boot-3-1/) 2 | -------------------------------------------------------------------------------- /spring/springboot3-local-dev-testcontainers/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Improved local development using containers in Spring Boot 3.1](https://www.naiyerasif.com/post/2023/09/08/improved-local-development-using-containers-in-spring-boot-3-1/) 2 | -------------------------------------------------------------------------------- /@archive/spring/springboot2-springdoc-webmvc-integration/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | platform: postgres 4 | url: jdbc:postgresql://localhost:5432/spring 5 | username: erin 6 | password: richards -------------------------------------------------------------------------------- /@archive/spring/springboot2-springdoc-webmvcfn-integration/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | platform: postgres 4 | url: jdbc:postgresql://localhost:5432/spring 5 | username: erin 6 | password: richards -------------------------------------------------------------------------------- /aws/localstack-lambda-with-eventbridge-rule-trigger/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [Using LocalStack for AWS Lambda with EventBridge rule trigger](https://www.naiyerasif.com/post/2024/08/11/using-localstack-for-aws-lambda-with-eventbridge-rule-trigger/) 2 | -------------------------------------------------------------------------------- /aws/localstack-lambda-with-eventbridge-rule-trigger/main.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | logger = logging.getLogger() 4 | logger.setLevel(logging.INFO) 5 | 6 | 7 | def lambda_handler(event, context): 8 | logger.info(event['detail']['Message']) 9 | -------------------------------------------------------------------------------- /java/jacoco-coverage-with-maven/src/test/resources/com/example/factorialDataSetSmall.csv: -------------------------------------------------------------------------------- 1 | position,factorial 2 | 0,1 3 | 1,1 4 | 2,2 5 | 3,6 6 | 4,24 7 | 5,120 8 | 6,720 9 | 7,5040 10 | 8,40320 11 | 9,362880 12 | 10,3628800 13 | 11,39916800 -------------------------------------------------------------------------------- /python/testcontainers-integration-tests-with-pytest/README.md: -------------------------------------------------------------------------------- 1 | > Refer to [How to write integration tests using Testcontainers in Python](https://www.naiyerasif.com/post/2025/06/03/how-to-write-integration-tests-using-testcontainers-in-python/) 2 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-eddsa/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | create table if not exists custom_user ( 2 | id uuid default random_uuid() primary key, 3 | username varchar(50) not null unique, 4 | password varchar(500) not null 5 | ); 6 | -------------------------------------------------------------------------------- /cloud/README.md: -------------------------------------------------------------------------------- 1 | # Guides — Cloud 2 | 3 | Source code of Cloud examples published on [naiyerasif.com](https://www.naiyerasif.com) 4 | 5 | - [Communicating with containers on Docker network](./communicating-with-containers-on-docker-network/) 6 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-api/.gitignore: -------------------------------------------------------------------------------- 1 | Thumbs.db 2 | .DS_Store 3 | .gradle 4 | build/ 5 | target/ 6 | out/ 7 | .idea 8 | *.iml 9 | *.ipr 10 | *.iws 11 | .project 12 | .settings 13 | .classpath -------------------------------------------------------------------------------- /nodejs/express-postgres-api/src/api/default.ts: -------------------------------------------------------------------------------- 1 | import { Application } from 'express'; 2 | 3 | export const registerDefaultEndpoints = (app: Application) => { 4 | app.get('/health', (req, res) => res.json({ 5 | status: 'UP' 6 | })); 7 | }; 8 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-custom-user/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | create table if not exists custom_user ( 2 | id uuid default random_uuid() primary key, 3 | username varchar(50) not null unique, 4 | password varchar(500) not null 5 | ); 6 | -------------------------------------------------------------------------------- /java/jacoco-coverage-with-maven/src/test/resources/com/example/fibonacciDataSet.csv: -------------------------------------------------------------------------------- 1 | number,fibonacci 2 | 1,1 3 | 2,1 4 | 3,2 5 | 4,3 6 | 5,5 7 | 6,8 8 | 7,13 9 | 8,21 10 | 9,34 11 | 10,55 12 | 11,89 13 | 12,144 14 | 13,233 15 | 14,377 16 | 15,610 -------------------------------------------------------------------------------- /micronaut/README.md: -------------------------------------------------------------------------------- 1 | # Guides — Micronaut 2 | 3 | Source code of Micronaut examples published on [naiyerasif.com](https://www.naiyerasif.com) 4 | 5 | - [How to implement an AWS Lambda function using Micronaut](./mn4-aws-lambda-with-eventbridge/) 6 | -------------------------------------------------------------------------------- /python/README.md: -------------------------------------------------------------------------------- 1 | # Guides — Python 2 | 3 | Source code of Python examples published on [naiyerasif.com](https://www.naiyerasif.com) 4 | 5 | - [How to write integration tests using Testcontainers in Python](./testcontainers-integration-tests-with-pytest/) 6 | -------------------------------------------------------------------------------- /java/docker-healthcheck/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM gcr.io/distroless/java:11 2 | COPY target/*.jar app.jar 3 | COPY HealthCheck.java . 4 | EXPOSE 8080 5 | CMD ["app.jar"] 6 | HEALTHCHECK --interval=25s --timeout=3s --retries=2 CMD ["java", "HealthCheck.java", "||", "exit", "1"] 7 | -------------------------------------------------------------------------------- /micronaut/mn4-aws-lambda-with-eventbridge/events.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "Source": "example-source", 4 | "Detail": "{ \"message\": \"Hello, Gwen!\" }", 5 | "DetailType": "Scheduled Event sent through EventBridge", 6 | "EventBusName": "example-event-bus" 7 | } 8 | ] 9 | -------------------------------------------------------------------------------- /@sample/spring/springboot3-notes-api/compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | postgres: 3 | image: postgres:16-alpine 4 | ports: 5 | - 5432:5432 6 | environment: 7 | POSTGRES_USER: gwen 8 | POSTGRES_PASSWORD: stacy 9 | POSTGRES_DB: brooklyn 10 | -------------------------------------------------------------------------------- /spring/spring-data-micronaut-data/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.1" 2 | 3 | services: 4 | db: 5 | image: postgres:12.2-alpine 6 | container_name: postgres_12.2 7 | ports: 8 | - 5432:5432 9 | environment: 10 | POSTGRES_PASSWORD: example -------------------------------------------------------------------------------- /aws/localstack-lambda-with-eventbridge-rule-trigger/events.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "Source": "example-source", 4 | "Detail": "{ \"Message\": \"Hello, Gwen\" }", 5 | "DetailType": "Scheduled Event sent through EventBridge", 6 | "EventBusName": "example-event-bus" 7 | } 8 | ] 9 | -------------------------------------------------------------------------------- /spring/springboot3-local-dev-docker-compose/compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | postgres: 3 | image: postgres:16-alpine 4 | ports: 5 | - 5432 6 | environment: 7 | POSTGRES_USER: gwen 8 | POSTGRES_PASSWORD: stacy 9 | POSTGRES_DB: brooklyn 10 | -------------------------------------------------------------------------------- /spring/springboot3-springdoc-integration/compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | postgres: 3 | image: postgres:16-alpine 4 | ports: 5 | - 5432:5432 6 | environment: 7 | POSTGRES_USER: gwen 8 | POSTGRES_PASSWORD: stacy 9 | POSTGRES_DB: brooklyn 10 | -------------------------------------------------------------------------------- /miscellaneous/webfont-subsetting/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.12-alpine 2 | RUN apk add --no-cache --virtual .build-deps gcc g++ 3 | RUN pip install brotli 4 | RUN pip install fonttools 5 | RUN pip install rich 6 | RUN apk del .build-deps 7 | WORKDIR /app 8 | CMD ["python3", "run.py"] 9 | -------------------------------------------------------------------------------- /spring/spring-data-mongo-repository/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | data: 3 | mongodb: 4 | host: localhost 5 | port: 27017 6 | database: spring 7 | username: gwen 8 | password: stacy 9 | authentication-database: admin 10 | -------------------------------------------------------------------------------- /spring/spring-security-token-validation-local/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | auth: 2 | audience: api://default 3 | 4 | spring: 5 | security: 6 | oauth2: 7 | resourceserver: 8 | jwt: 9 | issuer-uri: https://dev-4273429.okta.com/oauth2/default 10 | -------------------------------------------------------------------------------- /spring/springboot3-aop-retry-on-failure/src/main/java/com/example/retry/annotation/BackoffStrategy.java: -------------------------------------------------------------------------------- 1 | package com.example.retry.annotation; 2 | 3 | public enum BackoffStrategy { 4 | NONE, RANDOM, LINEAR, LINEAR_RANDOM, GEOMETRIC, GEOMETRIC_RANDOM, EXPONENTIAL, EXPONENTIAL_RANDOM 5 | } 6 | -------------------------------------------------------------------------------- /nodejs/express-postgres-api/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.1" 2 | 3 | services: 4 | db: 5 | image: postgres:alpine 6 | container_name: postgres_latest 7 | restart: always 8 | ports: 9 | - 5432:5432 10 | environment: 11 | POSTGRES_PASSWORD: example 12 | -------------------------------------------------------------------------------- /spring/spring-data-micronaut-data/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /spring/spring-rest-error-handling/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | db: 5 | image: postgres:13-alpine 6 | restart: always 7 | ports: 8 | - 5432:5432 9 | environment: 10 | POSTGRES_USER: erin 11 | POSTGRES_PASSWORD: richards 12 | -------------------------------------------------------------------------------- /spring/springfox3-webmvc-integration/src/main/java/dev/mflash/guides/springfox3/NoteRepository.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.springfox3; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | 5 | public interface NoteRepository extends CrudRepository { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /@archive/spring/springboot2-aop-retry-on-failure/src/main/java/dev/mflash/guides/retry/annotation/BackoffStrategy.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.retry.annotation; 2 | 3 | public enum BackoffStrategy { 4 | RANDOM, LINEAR, LINEAR_RANDOM, GEOMETRIC, GEOMETRIC_RANDOM, EXPONENTIAL, EXPONENTIAL_RANDOM 5 | } 6 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/scenario-2-on-different-networks/greeter-api/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | greeter-api: 5 | image: mflash/greeter-api 6 | networks: 7 | - greeternet 8 | 9 | networks: 10 | greeternet: 11 | driver: bridge -------------------------------------------------------------------------------- /@archive/spring/springboot2-springdoc-webmvc-integration/src/main/java/dev/mflash/guides/springdoc/NoteRepository.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.springdoc; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | 5 | public interface NoteRepository extends CrudRepository { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /@archive/spring/springboot2-springdoc-webmvcfn-integration/src/main/java/dev/mflash/guides/springdoc/NoteRepository.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.springdoc; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | 5 | public interface NoteRepository extends CrudRepository { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /spring/spring-data-micronaut-data/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | datasources: 2 | default: 3 | url: jdbc:postgresql://localhost:5432/spring-guides 4 | driverClassName: org.postgresql.Driver 5 | username: postgres 6 | password: example 7 | schema-generate: CREATE_DROP 8 | dialect: POSTGRES -------------------------------------------------------------------------------- /spring/springboot3-local-dev-docker-compose/src/main/java/com/example/localdev/NotesRepository.java: -------------------------------------------------------------------------------- 1 | package com.example.localdev; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | 5 | import java.util.UUID; 6 | 7 | public interface NotesRepository extends CrudRepository { 8 | } 9 | -------------------------------------------------------------------------------- /spring/springboot3-local-dev-testcontainers/src/main/java/com/example/localdev/NotesRepository.java: -------------------------------------------------------------------------------- 1 | package com.example.localdev; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | 5 | import java.util.UUID; 6 | 7 | public interface NotesRepository extends CrudRepository { 8 | } 9 | -------------------------------------------------------------------------------- /spring/spring-file-upload/web/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": [ 8 | "src/main.ts", 9 | "src/polyfills.ts" 10 | ], 11 | "include": [ 12 | "src/**/*.d.ts" 13 | ] 14 | } -------------------------------------------------------------------------------- /spring/springfox3-webmvc-integration/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | db: 5 | image: postgres:13-alpine 6 | container_name: pg13 7 | restart: always 8 | ports: 9 | - 5432:5432 10 | environment: 11 | POSTGRES_USER: erin 12 | POSTGRES_PASSWORD: richards 13 | -------------------------------------------------------------------------------- /spring/springrx-file-upload/web/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": [ 8 | "src/main.ts", 9 | "src/polyfills.ts" 10 | ], 11 | "include": [ 12 | "src/**/*.d.ts" 13 | ] 14 | } -------------------------------------------------------------------------------- /spring/springboot3-local-dev-testcontainers/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | create extension if not exists "uuid-ossp"; 2 | 3 | create table notes ( 4 | id uuid primary key default uuid_generate_v1(), 5 | title varchar(255) not null, 6 | body text, 7 | read_only boolean not null default false 8 | ); 9 | -------------------------------------------------------------------------------- /spring/spring-data-mongo-repository/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | 5 | mongo: 6 | image: mongo:latest 7 | container_name: mongodb_latest 8 | ports: 9 | - 27017:27017 10 | environment: 11 | MONGO_INITDB_ROOT_USERNAME: gwen 12 | MONGO_INITDB_ROOT_PASSWORD: stacy 13 | -------------------------------------------------------------------------------- /spring/springboot3-local-dev-docker-compose/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | create extension if not exists "uuid-ossp"; 2 | 3 | create table notes ( 4 | id uuid primary key default uuid_generate_v1(), 5 | title varchar(255) not null, 6 | body text, 7 | read_only boolean not null default false 8 | ); 9 | -------------------------------------------------------------------------------- /nodejs/express-postgres-api/src/api/index.ts: -------------------------------------------------------------------------------- 1 | import { Application } from 'express'; 2 | import { registerDefaultEndpoints } from './default'; 3 | import { registerSongEndpoints } from './song'; 4 | 5 | export const registerEndpoints = (app: Application) => { 6 | registerDefaultEndpoints(app); 7 | registerSongEndpoints(app); 8 | }; 9 | -------------------------------------------------------------------------------- /@archive/spring/springboot2-springdoc-webmvc-integration/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | db: 5 | image: postgres:13-alpine 6 | container_name: pg13 7 | restart: always 8 | ports: 9 | - 5432:5432 10 | environment: 11 | POSTGRES_USER: erin 12 | POSTGRES_PASSWORD: richards 13 | -------------------------------------------------------------------------------- /java/jacoco-coverage-with-maven/src/main/java/com/example/PangramChecker.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | interface PangramChecker { 4 | 5 | static boolean isPangram(final String text) { 6 | return text.toLowerCase() 7 | .replaceAll("[^a-z]+", "") 8 | .chars() 9 | .distinct() 10 | .count() == 26; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring/spring-data-jdbc-hikari-leak-detection/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring.datasource: 2 | url: jdbc:h2:mem:sa 3 | hikari: 4 | pool-name: H2HikariPool 5 | maximum-pool-size: 5 6 | minimum-idle: 2 7 | # leak-detection-threshold: 30000 8 | 9 | #logging: 10 | # level: 11 | # com.zaxxer.hikari: TRACE 12 | -------------------------------------------------------------------------------- /spring/spring-rest-error-handling/schema.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE book ( 2 | id SERIAL PRIMARY KEY, 3 | title TEXT NOT NULL, 4 | author TEXT NOT NULL, 5 | genre TEXT NOT NULL 6 | ); 7 | 8 | CREATE TABLE custom_user ( 9 | id SERIAL PRIMARY KEY, 10 | email TEXT NOT NULL, 11 | name TEXT NOT NULL, 12 | password TEXT NOT NULL 13 | ); 14 | -------------------------------------------------------------------------------- /@archive/spring/springboot2-springdoc-webmvcfn-integration/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | db: 5 | image: postgres:13-alpine 6 | container_name: pg13 7 | restart: always 8 | ports: 9 | - 5432:5432 10 | environment: 11 | POSTGRES_USER: erin 12 | POSTGRES_PASSWORD: richards 13 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-api/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | micronaut: 2 | application: 3 | name: greeter-api 4 | server: 5 | port: 8084 6 | cors: 7 | enabled: true 8 | configurations: 9 | web: 10 | allowedOrigins: 11 | - http://0.0.0.0:4200 -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-eddsa/src/main/java/com/example/jwt/userdetails/CustomUserRepository.java: -------------------------------------------------------------------------------- 1 | package com.example.jwt.userdetails; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | 5 | public interface CustomUserRepository extends CrudRepository { 6 | 7 | CustomUser findByUsername(String username); 8 | } 9 | -------------------------------------------------------------------------------- /spring/springboot3-springdoc-integration/src/main/java/com/example/springdoc/OpenAPIProperties.java: -------------------------------------------------------------------------------- 1 | package com.example.springdoc; 2 | 3 | import io.swagger.v3.oas.models.OpenAPI; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | @ConfigurationProperties("openapi") 7 | public class OpenAPIProperties extends OpenAPI { 8 | } 9 | -------------------------------------------------------------------------------- /ARCHIVE.md: -------------------------------------------------------------------------------- 1 | # Backstage Archives 2 | 3 | Source code of archived examples from [naiyerasif.com](https://www.naiyerasif.com) 4 | 5 | ## Sections 6 | 7 | - [Spring](./spring) 8 | - [Logging methods with AspectJ in a Spring application](./@/archives/spring/springboot3-aop-method-logging/) 9 | 10 | ## License 11 | 12 | Licensed under [MIT](./LICENSE.md) 13 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-api/src/main/java/dev/mflash/guides/greeter/Application.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.greeter; 2 | 3 | import io.micronaut.runtime.Micronaut; 4 | 5 | public class Application { 6 | 7 | public static void main(String[] args) { 8 | Micronaut.run(Application.class); 9 | } 10 | } -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-ui/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": [ 8 | "src/main.ts", 9 | "src/polyfills.ts" 10 | ], 11 | "include": [ 12 | "src/**/*.d.ts" 13 | ] 14 | } -------------------------------------------------------------------------------- /spring/spring-data-mongo-repository/src/main/java/dev/mflash/guides/mongo/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.mongo.repository; 2 | 3 | import dev.mflash.guides.mongo.domain.User; 4 | import org.springframework.data.mongodb.repository.MongoRepository; 5 | 6 | public interface UserRepository extends MongoRepository { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-custom-user/src/main/java/com/example/jwt/userdetails/CustomUserRepository.java: -------------------------------------------------------------------------------- 1 | package com.example.jwt.userdetails; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | 5 | public interface CustomUserRepository extends CrudRepository { 6 | 7 | CustomUser findByUsername(String username); 8 | } 9 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/scenario-2-on-different-networks/greeter-ui/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | greeter-ui: 5 | image: mflash/greeter-ui 6 | networks: 7 | - uinet 8 | ports: 9 | - 4200:4200 10 | 11 | networks: 12 | uinet: 13 | external: 14 | name: greeter-api_greeternet -------------------------------------------------------------------------------- /nodejs/express-with-typescript/src/server.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | 3 | const app = express(); 4 | const port = 8080; // server port 5 | 6 | // default route 7 | app.get('/', (req, res) => res.json({ 8 | message: 'Hello World!' 9 | })); 10 | 11 | // server 12 | app.listen(port, () => console.log(`Server started at http://localhost:${port}`)); 13 | -------------------------------------------------------------------------------- /spring/spring-data-mongo-repository/src/main/java/dev/mflash/guides/mongo/repository/SessionRepository.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.mongo.repository; 2 | 3 | import dev.mflash.guides.mongo.domain.Session; 4 | import org.springframework.data.mongodb.repository.MongoRepository; 5 | 6 | public interface SessionRepository extends MongoRepository { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /spring/spring-security-token-introspection/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | security: 3 | oauth2: 4 | resourceserver: 5 | opaque-token: 6 | introspection-uri: https://dev-4273429.okta.com/oauth2/default/v1/introspect 7 | client-id: 0oarle1cZ7n7esoqO5d5 8 | client-secret: i-HUDoMIm5SO7s22ejZzMb2qKHGb7HnMESx4NV2S 9 | -------------------------------------------------------------------------------- /nodejs/express-postgres-api/.env: -------------------------------------------------------------------------------- 1 | ENV=local 2 | LOG_DIR=logs 3 | LOG_FILE=app.log 4 | LOG_LEVEL=info 5 | MORGAN_LOG=requests.log 6 | MORGAN_LOG_FMT=[:date[iso]] :method :url :status :response-time ms - :res[content-length] 7 | MORGAN_LOG_ROLLING_INTERVAL=1d 8 | PGUSER=postgres 9 | PGHOST=localhost 10 | PGPASSWORD=example 11 | PGDATABASE=postgres 12 | PGPORT=5432 13 | SERVER_PORT=8080 -------------------------------------------------------------------------------- /spring/spring-security-resource-server-error-handling/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | security: 3 | oauth2: 4 | resourceserver: 5 | opaque-token: 6 | introspection-uri: https://dev-4273429.okta.com/oauth2/default/v1/introspect 7 | client-id: 0oarle1cZ7n7esoqO5d5 8 | client-secret: i-HUDoMIm5SO7s22ejZzMb2qKHGb7HnMESx4NV2S 9 | -------------------------------------------------------------------------------- /aws/README.md: -------------------------------------------------------------------------------- 1 | # Guides — AWS 2 | 3 | Source code of AWS examples published on [naiyerasif.com](https://www.naiyerasif.com) 4 | 5 | - [Using LocalStack for AWS Lambda with SQS trigger](./localstack-lambda-with-sqs-trigger/) 6 | - [Using LocalStack for AWS Lambda with SNS trigger](./localstack-lambda-with-sns-trigger/) 7 | - [Working with AWS on local using LocalStack](./localstack-with-aws-cli/) 8 | -------------------------------------------------------------------------------- /spring/spring-file-upload/src/main/java/dev/mflash/guides/upload/service/StorageException.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.upload.service; 2 | 3 | public class StorageException extends RuntimeException { 4 | 5 | public StorageException(String message) { 6 | super(message); 7 | } 8 | 9 | public StorageException(String message, Throwable cause) { 10 | super(message, cause); 11 | } 12 | } -------------------------------------------------------------------------------- /spring/springboot3-local-dev-testcontainers/src/test/java/LocalLauncher.java: -------------------------------------------------------------------------------- 1 | import com.example.localdev.Launcher; 2 | import org.springframework.boot.SpringApplication; 3 | 4 | public class LocalLauncher { 5 | 6 | public static void main(String... args) { 7 | SpringApplication 8 | .from(Launcher::main) 9 | .with(LocalContainerConfiguration.class) 10 | .run(args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring/springboot3-local-dev-testcontainers/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | insert into notes (title, body, read_only) 2 | values ('Blocking OpenAI web crawler', 'Disallow routes for GPTBot in robots.txt', false), 3 | ('Goodhart`s Law', 'When a measure becomes a target, it ceases to be a good measure.', false), 4 | ('Prune homebrew dependencies', 'Run `brew autoremove` to prune unused dependencies', true); 5 | -------------------------------------------------------------------------------- /spring/springrx-file-upload/src/main/java/dev/mflash/guides/upload/service/StorageException.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.upload.service; 2 | 3 | public class StorageException extends RuntimeException { 4 | 5 | public StorageException(String message) { 6 | super(message); 7 | } 8 | 9 | public StorageException(String message, Throwable cause) { 10 | super(message, cause); 11 | } 12 | } -------------------------------------------------------------------------------- /spring/spring-data-micronaut-data/src/main/java/dev/mflash/guides/customer/Launcher.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.customer; 2 | 3 | import io.micronaut.runtime.Micronaut; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | public @SpringBootApplication class Launcher { 7 | 8 | public static void main(String... args) { 9 | Micronaut.run(Launcher.class); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /spring/springboot3-local-dev-docker-compose/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | insert into notes (title, body, read_only) 2 | values ('Blocking OpenAI web crawler', 'Disallow routes for GPTBot in robots.txt', false), 3 | ('Goodhart`s Law', 'When a measure becomes a target, it ceases to be a good measure.', false), 4 | ('Prune homebrew dependencies', 'Run `brew autoremove` to prune unused dependencies', true); 5 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-api/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM maven:3.6.1-jdk-13-alpine as builder 2 | WORKDIR /usr/home/greeter 3 | COPY . . 4 | RUN mvn package 5 | 6 | FROM adoptopenjdk/openjdk13-openj9:jre-13.0.2_8_openj9-0.18.0-alpine 7 | COPY --from=builder /usr/home/greeter/target/greeter-api-*.jar greeter-api.jar 8 | EXPOSE 8084 9 | CMD ["java", "-jar", "greeter-api.jar"] 10 | -------------------------------------------------------------------------------- /java/jackson3-polymorphic-requests/src/main/java/com/example/jackson/polymorphic/Software.java: -------------------------------------------------------------------------------- 1 | package com.example.jackson.polymorphic; 2 | 3 | public record Software( 4 | String os, 5 | String manufacturer, 6 | String title, 7 | double price, 8 | String version 9 | ) implements CartItem { 10 | 11 | @Override 12 | public ItemCategory itemCategory() { 13 | return ItemCategory.SOFTWARE; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /spring/spring-data-jdbc-hikari-leak-detection/src/main/java/com/example/Launcher.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Launcher { 8 | 9 | public static void main(String... args) { 10 | SpringApplication.run(Launcher.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring/spring-file-upload/web/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Uploader 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /spring/springrx-file-upload/web/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Uploader 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /@sample/spring/springboot3-notes-api/src/main/java/com/example/notes/Launcher.java: -------------------------------------------------------------------------------- 1 | package com.example.notes; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Launcher { 8 | 9 | public static void main(String... args) { 10 | SpringApplication.run(Launcher.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring/spring-data-jdbc-hikari-leak-detection/src/main/java/com/example/Book.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import org.springframework.data.annotation.Id; 5 | 6 | import java.util.List; 7 | import java.util.UUID; 8 | 9 | @JsonIgnoreProperties(value = { "id" }) 10 | public record Book(@Id UUID id, String title, String author, List genre) {} 11 | -------------------------------------------------------------------------------- /spring/springboot3-aop-retry-on-failure/src/main/java/com/example/retry/Launcher.java: -------------------------------------------------------------------------------- 1 | package com.example.retry; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Launcher { 8 | 9 | public static void main(String... args) { 10 | SpringApplication.run(Launcher.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/scenario-1-on-the-same-network/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | greeter-ui: 5 | image: mflash/greeter-ui 6 | networks: 7 | - greeternet 8 | ports: 9 | - 4200:4200 10 | 11 | greeter-api: 12 | image: mflash/greeter-api 13 | networks: 14 | - greeternet 15 | 16 | networks: 17 | greeternet: 18 | driver: bridge -------------------------------------------------------------------------------- /nodejs/express-postgres-api/song.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE song ( 2 | id SERIAL PRIMARY KEY, 3 | title TEXT NOT NULL, 4 | album TEXT, 5 | artist TEXT 6 | ); 7 | 8 | INSERT INTO song(title, album, artist) VALUES ('Too Much', 'Dedicated', 'Carly Rae Jepsen'); 9 | INSERT INTO song(title, album, artist) VALUES ('Insomnia', 'D2', 'Daya'); 10 | INSERT INTO song(title, album, artist) VALUES ('Issues', 'Nervous System', 'Julia Michaels'); 11 | -------------------------------------------------------------------------------- /spring/spring-data-mongo-repository/src/main/java/dev/mflash/guides/mongo/Launcher.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.mongo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | public @SpringBootApplication class Launcher { 7 | 8 | public static void main(String[] args) { 9 | SpringApplication.run(Launcher.class, args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /spring/spring-messaging-rabbitmq/src/main/java/dev/mflash/guides/rabbitmq/Launcher.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.rabbitmq; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | public @SpringBootApplication class Launcher { 7 | 8 | public static void main(String[] args) { 9 | SpringApplication.run(Launcher.class, args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /spring/springboot3-local-dev-docker-compose/src/main/java/com/example/localdev/Launcher.java: -------------------------------------------------------------------------------- 1 | package com.example.localdev; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Launcher { 8 | 9 | public static void main(String... args) { 10 | SpringApplication.run(Launcher.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring/springboot3-local-dev-testcontainers/src/main/java/com/example/localdev/Launcher.java: -------------------------------------------------------------------------------- 1 | package com.example.localdev; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Launcher { 8 | 9 | public static void main(String... args) { 10 | SpringApplication.run(Launcher.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring/springboot3-springdoc-integration/src/main/java/com/example/springdoc/Launcher.java: -------------------------------------------------------------------------------- 1 | package com.example.springdoc; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Launcher { 8 | 9 | public static void main(String... args) { 10 | SpringApplication.run(Launcher.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring/spring-rest-error-handling/src/main/java/dev/mflash/guides/resterror/Launcher.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.resterror; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | public @SpringBootApplication class Launcher { 7 | 8 | public static void main(String[] args) { 9 | SpringApplication.run(Launcher.class, args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-ui/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | GreeterUi 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /@archive/spring/springboot2-aop-retry-on-failure/src/main/java/dev/mflash/guides/retry/Launcher.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.retry; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Launcher { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Launcher.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-ui/src/app/greeting.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient } from '@angular/common/http'; 3 | 4 | @Injectable({ 5 | providedIn: 'root' 6 | }) 7 | export class GreetingService { 8 | constructor(private client: HttpClient) {} 9 | 10 | getGreeting() { 11 | return this.client.get('/hello?name=Microflash'); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /java/docker-healthcheck/src/main/java/dev/mflash/guides/java/healthcheck/Launcher.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.java.healthcheck; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Launcher { 8 | 9 | public static void main(String... args) { 10 | SpringApplication.run(Launcher.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /aws/localstack-with-aws-cli/compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | localstack: 3 | container_name: localstack-with-aws-cli 4 | image: localstack/localstack:4.4.0 5 | ports: 6 | - "4566:4566" 7 | environment: 8 | - DEBUG=${DEBUG:-0} 9 | # skips internet connections when working offline 10 | - SKIP_SSL_CERT_DOWNLOAD=1 11 | - DISABLE_EVENTS=1 12 | volumes: 13 | - "/var/run/docker.sock:/var/run/docker.sock" 14 | -------------------------------------------------------------------------------- /java/aop-compile-time/src/main/java/com/example/aop/Launcher.java: -------------------------------------------------------------------------------- 1 | package com.example.aop; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | public class Launcher { 7 | 8 | private static final Logger logger = LoggerFactory.getLogger(Launcher.class); 9 | private static final GreetingHandler handler = new GreetingHandler(); 10 | 11 | void main() { 12 | logger.info("{}", handler.greet("Veronica")); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring/spring-messaging-rabbitmq/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.1' 2 | 3 | services: 4 | 5 | rabbitmq: 6 | image: "rabbitmq:3-management" 7 | container_name: "rmq3" 8 | hostname: "albatross" 9 | restart: "no" 10 | environment: 11 | RABBITMQ_DEFAULT_USER: "rabbitmq" 12 | RABBITMQ_DEFAULT_PASS: "rabbitmq" 13 | labels: 14 | NAME: "rabbitmq1" 15 | ports: 16 | - "5672:5672" 17 | - "15672:15672" 18 | -------------------------------------------------------------------------------- /spring/spring-content-negotiation/src/main/java/dev/mflash/guides/spring/negotiation/Launcher.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.spring.negotiation; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Launcher { 8 | 9 | public static void main(String... args) { 10 | SpringApplication.run(Launcher.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-ui/Dockerfile: -------------------------------------------------------------------------------- 1 | # Generate a build 2 | FROM node:12-alpine as builder 3 | WORKDIR /app 4 | COPY . /app 5 | RUN yarn 6 | RUN yarn build 7 | 8 | # Serve with Nginx 9 | FROM nginx:1.17-alpine 10 | RUN rm -rf /usr/share/nginx/html/* 11 | COPY default.conf /etc/nginx/conf.d/ 12 | COPY --from=builder /app/dist/greeter-ui /usr/share/nginx/html 13 | EXPOSE 4200 14 | CMD ["nginx", "-g", "daemon off;"] -------------------------------------------------------------------------------- /nodejs/morgan-request-logging/src/configuration/environment.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | nodeEnv: process.env.ENV || process.env.NODE_ENV, 3 | logDir: process.env.LOG_DIR || 'logs', 4 | requestLogFile: process.env.MORGAN_LOG || 'requests.log', 5 | requestLogFormat: process.env.MORGAN_LOG_FMT || '[:date[iso]] :method :url :status :response-time ms - :res[content-length]', 6 | requestLogRollingInterval: process.env.MORGAN_LOG_ROLLING_INTERVAL || '1d' 7 | } -------------------------------------------------------------------------------- /java/jackson3-polymorphic-requests/src/main/java/com/example/jackson/polymorphic/Accessory.java: -------------------------------------------------------------------------------- 1 | package com.example.jackson.polymorphic; 2 | 3 | import java.util.List; 4 | 5 | public record Accessory( 6 | String brand, 7 | String manufacturer, 8 | String model, 9 | double price, 10 | List specialFeatures 11 | ) implements CartItem { 12 | 13 | @Override 14 | public ItemCategory itemCategory() { 15 | return ItemCategory.ACCESSORY; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /miscellaneous/README.md: -------------------------------------------------------------------------------- 1 | # Guides — Miscellaneous 2 | 3 | Source code of miscellaneous examples published on [naiyerasif.com](https://www.naiyerasif.com) 4 | 5 | - [Client Credentials flow with Ory Hydra 2](./ory-hydra-2--client-credentials-flow/) 6 | - [How I subset fonts for my site](./webfont-subsetting/) 7 | 8 | --- 9 | 10 | ## Archived 11 | 12 | - [Client Credentials flow with Ory Hydra 1](../@archive/miscellaneous/ory-hydra-1--client-credentials-flow/) 13 | -------------------------------------------------------------------------------- /python/testcontainers-integration-tests-with-pytest/app/singleton.py: -------------------------------------------------------------------------------- 1 | class Singleton(type): 2 | """ 3 | A metaclass that creates a Singleton class when inherited from it. 4 | """ 5 | 6 | _instances = {} 7 | 8 | def __call__(cls, *args, **kwargs): 9 | if cls not in cls._instances: 10 | instance = super(Singleton, cls).__call__(*args, **kwargs) 11 | cls._instances[cls] = instance 12 | return cls._instances[cls] 13 | -------------------------------------------------------------------------------- /spring/spring-security-token-introspection/src/main/java/dev/mflash/guides/tokenval/introspection/Launcher.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.tokenval.introspection; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | public @SpringBootApplication class Launcher { 7 | 8 | public static void main(String[] args) { 9 | SpringApplication.run(Launcher.class, args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /spring/springrx-file-upload/middleware/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "uploader-middleware", 3 | "version": "1.0.0", 4 | "main": "server.js", 5 | "scripts": { 6 | "start": "node ." 7 | }, 8 | "dependencies": { 9 | "axios": "^0.19.2", 10 | "body-parser": "^1.19.0", 11 | "cors": "^2.8.5", 12 | "express": "^4.17.1", 13 | "form-data": "^3.0.0", 14 | "morgan": "^1.9.1", 15 | "multer": "^1.4.2" 16 | }, 17 | "license": "MIT" 18 | } 19 | -------------------------------------------------------------------------------- /nodejs/express-postgres-api/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "incremental": true, 4 | "target": "es6", 5 | "module": "commonjs", 6 | "sourceMap": true, 7 | "outDir": "dist", 8 | "strict": true, 9 | "moduleResolution": "node", 10 | "baseUrl": ".", 11 | "paths": { 12 | "*": [ 13 | "node_modules/*" 14 | ] 15 | }, 16 | "esModuleInterop": true 17 | }, 18 | "include": [ 19 | "src/**/*" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /nodejs/logging-with-winston/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "incremental": true, 4 | "target": "es6", 5 | "module": "commonjs", 6 | "sourceMap": true, 7 | "outDir": "dist", 8 | "strict": true, 9 | "moduleResolution": "node", 10 | "baseUrl": ".", 11 | "paths": { 12 | "*": [ 13 | "node_modules/*" 14 | ] 15 | }, 16 | "esModuleInterop": true 17 | }, 18 | "include": [ 19 | "src/**/*" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /spring/spring-rest-error-handling/src/main/java/dev/mflash/guides/resterror/persistence/CustomUserRepository.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.resterror.persistence; 2 | 3 | import dev.mflash.guides.resterror.domain.CustomUser; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | import java.util.Optional; 7 | 8 | public interface CustomUserRepository extends CrudRepository { 9 | 10 | Optional findByEmail(String email); 11 | } 12 | -------------------------------------------------------------------------------- /spring/spring-security-resource-server-error-handling/src/main/java/dev/mflash/guides/tokenval/introspection/Launcher.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.tokenval.introspection; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | public @SpringBootApplication class Launcher { 7 | 8 | public static void main(String[] args) { 9 | SpringApplication.run(Launcher.class, args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /nodejs/express-with-typescript/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "incremental": true, 4 | "target": "es6", 5 | "module": "commonjs", 6 | "sourceMap": true, 7 | "outDir": "dist", 8 | "strict": true, 9 | "moduleResolution": "node", 10 | "baseUrl": ".", 11 | "paths": { 12 | "*": [ 13 | "node_modules/*" 14 | ] 15 | }, 16 | "esModuleInterop": true 17 | }, 18 | "include": [ 19 | "src/**/*" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /nodejs/logging-with-log4js-node/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "incremental": true, 4 | "target": "es6", 5 | "module": "commonjs", 6 | "sourceMap": true, 7 | "outDir": "dist", 8 | "strict": true, 9 | "moduleResolution": "node", 10 | "baseUrl": ".", 11 | "paths": { 12 | "*": [ 13 | "node_modules/*" 14 | ] 15 | }, 16 | "esModuleInterop": true 17 | }, 18 | "include": [ 19 | "src/**/*" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /nodejs/morgan-request-logging/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "incremental": true, 4 | "target": "es6", 5 | "module": "commonjs", 6 | "sourceMap": true, 7 | "outDir": "dist", 8 | "strict": true, 9 | "moduleResolution": "node", 10 | "baseUrl": ".", 11 | "paths": { 12 | "*": [ 13 | "node_modules/*" 14 | ] 15 | }, 16 | "esModuleInterop": true 17 | }, 18 | "include": [ 19 | "src/**/*" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /spring/spring-data-mongo-repository/src/main/java/dev/mflash/guides/mongo/event/Cascade.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.mongo.event; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target(ElementType.FIELD) 10 | public @interface Cascade { 11 | 12 | CascadeType value() default CascadeType.ALL; 13 | } 14 | -------------------------------------------------------------------------------- /nodejs/linting-with-typescript-eslint/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "incremental": true, 4 | "target": "es6", 5 | "module": "commonjs", 6 | "sourceMap": true, 7 | "outDir": "dist", 8 | "strict": true, 9 | "moduleResolution": "node", 10 | "baseUrl": ".", 11 | "paths": { 12 | "*": [ 13 | "node_modules/*" 14 | ] 15 | }, 16 | "esModuleInterop": true 17 | }, 18 | "include": [ 19 | "src/**/*" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /nodejs/morgan-request-logging/src/server.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import { registerRequestLogger } from './helper/request.logger'; 3 | 4 | const app = express(); 5 | const port = 8080; // server port 6 | 7 | // register morgan 8 | registerRequestLogger(app); 9 | 10 | // default route 11 | app.get('/', (req, res) => res.json({ 12 | message: 'Hello World!' 13 | })); 14 | 15 | // server 16 | app.listen(port, () => console.log(`Server started at http://localhost:${port}`)); 17 | -------------------------------------------------------------------------------- /nodejs/express-with-typescript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "express-with-typescript", 3 | "version": "1.0.0", 4 | "main": "dist/server.js", 5 | "scripts": { 6 | "build": "tsc", 7 | "prestart": "npm run build", 8 | "start": "node ." 9 | }, 10 | "dependencies": { 11 | "express": "^4.17.1" 12 | }, 13 | "devDependencies": { 14 | "@types/express": "^4.17.3", 15 | "@types/node": "^13.9.1", 16 | "typescript": "^3.8.3" 17 | }, 18 | "license": "MIT" 19 | } 20 | -------------------------------------------------------------------------------- /spring/spring-file-upload/web/src/main.ts: -------------------------------------------------------------------------------- 1 | import 'typeface-inter'; 2 | import { enableProdMode } from '@angular/core'; 3 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 4 | 5 | import { AppModule } from './app/app.module'; 6 | import { environment } from './environments/environment'; 7 | 8 | if (environment.production) { 9 | enableProdMode(); 10 | } 11 | 12 | platformBrowserDynamic() 13 | .bootstrapModule(AppModule) 14 | .catch(err => console.error(err)); 15 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-api/src/main/java/dev/mflash/guides/greeter/Greeting.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.greeter; 2 | 3 | public class Greeting { 4 | 5 | private String message; 6 | 7 | public Greeting(String message) { 8 | this.message = message; 9 | } 10 | 11 | public String getMessage() { 12 | return message; 13 | } 14 | 15 | public void setMessage(String message) { 16 | this.message = message; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring/springrx-file-upload/web/src/main.ts: -------------------------------------------------------------------------------- 1 | import 'typeface-inter'; 2 | import { enableProdMode } from '@angular/core'; 3 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 4 | 5 | import { AppModule } from './app/app.module'; 6 | import { environment } from './environments/environment'; 7 | 8 | if (environment.production) { 9 | enableProdMode(); 10 | } 11 | 12 | platformBrowserDynamic() 13 | .bootstrapModule(AppModule) 14 | .catch(err => console.error(err)); 15 | -------------------------------------------------------------------------------- /@sample/spring/springboot3-notes-api/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | insert into notes (title, body, created_by, updated_by, word_count, read_only) 2 | values ('Blocking OpenAI web crawler', 'Disallow routes for GPTBot in robots.txt', '@anya', '@anya', 6, false), 3 | ('Islamic calendar in Java', 'Use `HijrahChronology` to work with Islamic calendar system', '@usman', '@nare', 8, false), 4 | ('Prune homebrew dependencies', 'Run `brew autoremove` to prune unused dependencies', '@nare', '@nare', 7, true); 5 | -------------------------------------------------------------------------------- /spring/spring-file-upload/web/browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /spring/springboot3-springdoc-integration/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | insert into notes (title, body, created_by, updated_by, word_count, read_only) 2 | values ('Blocking OpenAI web crawler', 'Disallow routes for GPTBot in robots.txt', '@anya', '@anya', 6, false), 3 | ('Islamic calendar in Java', 'Use `HijrahChronology` to work with Islamic calendar system', '@usman', '@nare', 8, false), 4 | ('Prune homebrew dependencies', 'Run `brew autoremove` to prune unused dependencies', '@nare', '@nare', 7, true); 5 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-ui/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic() 12 | .bootstrapModule(AppModule) 13 | .catch(err => console.error(err)); 14 | -------------------------------------------------------------------------------- /spring/spring-security-token-validation-hybrid/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | auth: 2 | audience: api://default 3 | 4 | spring: 5 | security: 6 | oauth2: 7 | resourceserver: 8 | jwt: 9 | issuer-uri: https://dev-4273429.okta.com/oauth2/default 10 | opaque-token: 11 | introspection-uri: https://dev-4273429.okta.com/oauth2/default/v1/introspect 12 | client-id: 0oarle1cZ7n7esoqO5d5 13 | client-secret: i-HUDoMIm5SO7s22ejZzMb2qKHGb7HnMESx4NV2S 14 | -------------------------------------------------------------------------------- /spring/springboot3-aop-retry-on-failure/src/test/java/com/example/retry/aspect/RetryOnFailureTestService.java: -------------------------------------------------------------------------------- 1 | package com.example.retry.aspect; 2 | 3 | import com.example.retry.annotation.RetryOnFailure; 4 | import org.springframework.stereotype.Service; 5 | 6 | @Service 7 | public class RetryOnFailureTestService { 8 | 9 | @RetryOnFailure 10 | public double attempt(double value) { 11 | if (value <= 0) { 12 | throw new ArithmeticException("Value <= 0"); 13 | } 14 | 15 | return value; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /spring/springrx-file-upload/web/browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-ui/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { HttpClientModule } from '@angular/common/http'; 4 | 5 | import { AppComponent } from './app.component'; 6 | 7 | @NgModule({ 8 | declarations: [AppComponent], 9 | imports: [BrowserModule, HttpClientModule], 10 | providers: [], 11 | bootstrap: [AppComponent] 12 | }) 13 | export class AppModule {} 14 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth/src/main/resources/public.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuub7EmQZJhdpwiNzaYhl 3 | OKgIwgGYKtQI4Bx+Y0+8E4HkY3ipK8vXjNTnkpWgipqNqPGSH6CaXYe9FOaKu5XN 4 | 00+1tMHTTsgxh9rGsbSJDk1NFC54hMs/yCWj/bAzaLGacdOBKp4u/9fxmkjZ2kg4 5 | 03DmBxs4I/fD9dh17iXM1YWt3ED1o3lW+c5II7XSnTW7J0aUfmh6gRceJ7EHv66a 6 | jRTi6kO9QZjLuu8ldw1zhr4Ybm38I00iVyekDIFxLFq8u7aSt9XjFfMZWZk7U4NC 7 | gz5i/ETkcqWpkMkkqGGqtHBBRFv8YTNs4C0tAJzFWAxTk3D+XOw/aiuzCWQj/4IB 8 | 7QIDAQAB 9 | -----END PUBLIC KEY----- -------------------------------------------------------------------------------- /aws/localstack-lambda-with-sns-trigger/compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | localstack: 3 | container_name: localstack-lambda-with-sns-trigger 4 | image: localstack/localstack:4.4.0 5 | ports: 6 | - "4566:4566" 7 | environment: 8 | - DEBUG=${DEBUG:-0} 9 | # improve working completely offline 10 | # see: https://github.com/localstack/localstack/issues/4840 11 | - SKIP_SSL_CERT_DOWNLOAD=1 12 | - DISABLE_EVENTS=1 13 | volumes: 14 | - "/var/run/docker.sock:/var/run/docker.sock" 15 | -------------------------------------------------------------------------------- /aws/localstack-lambda-with-sqs-trigger/compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | localstack: 3 | container_name: localstack-lambda-with-sqs-trigger 4 | image: localstack/localstack:4.4.0 5 | ports: 6 | - "4566:4566" 7 | environment: 8 | - DEBUG=${DEBUG:-0} 9 | # improve working completely offline 10 | # see: https://github.com/localstack/localstack/issues/4840 11 | - SKIP_SSL_CERT_DOWNLOAD=1 12 | - DISABLE_EVENTS=1 13 | volumes: 14 | - "/var/run/docker.sock:/var/run/docker.sock" 15 | -------------------------------------------------------------------------------- /java/aop-compile-time/src/test/java/com/example/aop/aspect/AspectAppender.java: -------------------------------------------------------------------------------- 1 | package com.example.aop.aspect; 2 | 3 | import ch.qos.logback.classic.spi.ILoggingEvent; 4 | import ch.qos.logback.core.AppenderBase; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | public class AspectAppender extends AppenderBase { 10 | 11 | final List events = new ArrayList<>(); 12 | 13 | @Override 14 | protected void append(ILoggingEvent event) { 15 | events.add(event); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /micronaut/mn4-aws-lambda-with-eventbridge/compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | localstack: 3 | container_name: mn4-aws-lambda-with-eventbridge 4 | image: localstack/localstack:4.4.0 5 | ports: 6 | - "4566:4566" 7 | environment: 8 | - DEBUG=${DEBUG:-0} 9 | # improve working completely offline 10 | # see: https://github.com/localstack/localstack/issues/4840 11 | - SKIP_SSL_CERT_DOWNLOAD=1 12 | - DISABLE_EVENTS=1 13 | volumes: 14 | - "/var/run/docker.sock:/var/run/docker.sock" 15 | -------------------------------------------------------------------------------- /spring/springboot3-aop-retry-on-failure/src/main/java/com/example/retry/RandomlyFailingService.java: -------------------------------------------------------------------------------- 1 | package com.example.retry; 2 | 3 | import com.example.retry.annotation.RetryOnFailure; 4 | import org.springframework.stereotype.Service; 5 | 6 | @Service 7 | public class RandomlyFailingService { 8 | 9 | @RetryOnFailure 10 | public double random() { 11 | double random = Math.random(); 12 | 13 | if (random <= 0.5) { 14 | throw new ArithmeticException("Value <= 0.5"); 15 | } 16 | 17 | return random; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring/spring-file-upload/src/main/java/dev/mflash/guides/upload/configuration/StorageProperties.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.upload.configuration; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | 5 | @ConfigurationProperties("storage") 6 | public class StorageProperties { 7 | 8 | private String location; 9 | 10 | public String getLocation() { 11 | return location; 12 | } 13 | 14 | public void setLocation(String location) { 15 | this.location = location; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /spring/springrx-file-upload/src/main/java/dev/mflash/guides/upload/configuration/StorageProperties.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.upload.configuration; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | 5 | @ConfigurationProperties("storage") 6 | public class StorageProperties { 7 | 8 | private String location; 9 | 10 | public String getLocation() { 11 | return location; 12 | } 13 | 14 | public void setLocation(String location) { 15 | this.location = location; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /spring/spring-file-upload/web/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { HttpClientModule } from '@angular/common/http'; 4 | import { CommonModule } from '@angular/common'; 5 | 6 | import { AppComponent } from './app.component'; 7 | 8 | @NgModule({ 9 | declarations: [AppComponent], 10 | imports: [CommonModule, BrowserModule, HttpClientModule], 11 | providers: [], 12 | bootstrap: [AppComponent] 13 | }) 14 | export class AppModule {} 15 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-custom-user/src/main/resources/public.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAr5yCqW+uQOIsKS3/c6cG 3 | nZoIZ7Rl2TEFb0GImB9WrqYrvXBLGX1cWmoL8KoyJUV3LEQtO5L7w1t+xCqsR+z5 4 | BOjq2/Q3OQFe1YdigxMoavlDljYzrq+Yjmzh3lrqVu13T2I4yzhX+AMGRY/cmaKz 5 | wB6dxEzwcW94AGvQywpPMVTYB3wSUz7Dn3/BBOLIUYYw66aCcLgFhldgYL6LYYRd 6 | I0ZMuezJ8awOVTJ87e7Vk9tE7FL+G1vOcoux0BMRncr7QmRpriaItnoSXSkvQ6Vn 7 | uOofoFw5kOgmH7MmyH+h7yXznApdQxwJMSTR/klQgmWOH2Ur27d31k6A5RQakkrg 8 | zQIDAQAB 9 | -----END PUBLIC KEY----- -------------------------------------------------------------------------------- /spring/springboot3-aop-retry-on-failure/src/test/java/com/example/retry/aspect/AspectAppender.java: -------------------------------------------------------------------------------- 1 | package com.example.retry.aspect; 2 | 3 | import ch.qos.logback.classic.spi.ILoggingEvent; 4 | import ch.qos.logback.core.AppenderBase; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | public class AspectAppender extends AppenderBase { 10 | 11 | List events = new ArrayList<>(); 12 | 13 | protected @Override void append(ILoggingEvent event) { 14 | events.add(event); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring/springrx-file-upload/web/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { HttpClientModule } from '@angular/common/http'; 4 | import { CommonModule } from '@angular/common'; 5 | 6 | import { AppComponent } from './app.component'; 7 | 8 | @NgModule({ 9 | declarations: [AppComponent], 10 | imports: [CommonModule, BrowserModule, HttpClientModule], 11 | providers: [], 12 | bootstrap: [AppComponent] 13 | }) 14 | export class AppModule {} 15 | -------------------------------------------------------------------------------- /java/deep-copying/src/main/java/dev/mflash/guides/java/deepcopy/domain/Author.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.java.deepcopy.domain; 2 | 3 | public class Author implements Copyable { 4 | 5 | private String name; 6 | 7 | public String getName() { 8 | return name; 9 | } 10 | 11 | public void setName(String name) { 12 | this.name = name; 13 | } 14 | 15 | @Override 16 | public Author copy() { 17 | final Author newAuthor = new Author(); 18 | newAuthor.setName(name); 19 | return newAuthor; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /nodejs/logging-with-winston/src/server.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import { registerRequestLogger } from './helper/request.logger'; 3 | import { logger } from './helper/default.logger'; 4 | 5 | const app = express(); 6 | const port = 8080; // server port 7 | 8 | // register morgan 9 | registerRequestLogger(app); 10 | 11 | // default route 12 | app.get('/', (req, res) => res.json({ 13 | message: 'Hello World!' 14 | })); 15 | 16 | // server 17 | app.listen(port, () => logger.info(`Server started at http://localhost:${port}`)); 18 | -------------------------------------------------------------------------------- /spring/springboot3-local-dev-docker-compose/requests.http: -------------------------------------------------------------------------------- 1 | # list all notes 2 | curl -s http://localhost:8080/notes 3 | 4 | # fetch a note by id 5 | curl -s http://localhost:8080/notes/32cb722e-3b3b-11ee-b854-0242ac140002 6 | 7 | # create new note 8 | curl -s -X POST http://localhost:8080/notes --json '{"title": "curl`s --json flag","body": "Use `--json` flag to avoid setting content-type and accept headers","readOnly": false}' 9 | 10 | # delete a note 11 | curl -s -X DELETE http://localhost:8080/notes/43f56686-3b3b-11ee-b854-0242ac140002 12 | -------------------------------------------------------------------------------- /spring/springboot3-local-dev-testcontainers/requests.http: -------------------------------------------------------------------------------- 1 | # list all notes 2 | curl -s http://localhost:8080/notes 3 | 4 | # fetch a note by id 5 | curl -s http://localhost:8080/notes/32cb722e-3b3b-11ee-b854-0242ac140002 6 | 7 | # create new note 8 | curl -s -X POST http://localhost:8080/notes --json '{"title": "curl`s --json flag","body": "Use `--json` flag to avoid setting content-type and accept headers","readOnly": false}' 9 | 10 | # delete a note 11 | curl -s -X DELETE http://localhost:8080/notes/43f56686-3b3b-11ee-b854-0242ac140002 12 | -------------------------------------------------------------------------------- /nodejs/logging-with-log4js-node/src/server.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import { registerRequestLogger } from './helper/request.logger'; 3 | import { logger } from './helper/default.logger'; 4 | 5 | const app = express(); 6 | const port = 8080; // server port 7 | 8 | // register morgan 9 | registerRequestLogger(app); 10 | 11 | // default route 12 | app.get('/', (req, res) => res.json({ 13 | message: 'Hello World!' 14 | })); 15 | 16 | // server 17 | app.listen(port, () => logger.info(`Server started at http://localhost:${port}`)); 18 | -------------------------------------------------------------------------------- /@archive/spring/springboot2-aop-retry-on-failure/src/test/java/dev/mflash/guides/retry/aspect/RetryOnFailureTestService.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.retry.aspect; 2 | 3 | import dev.mflash.guides.retry.annotation.RetryOnFailure; 4 | import org.springframework.stereotype.Service; 5 | 6 | @Service 7 | public class RetryOnFailureTestService { 8 | 9 | @RetryOnFailure 10 | public double attempt(double value) { 11 | if (value <= 0) { 12 | throw new ArithmeticException("Value <= 0"); 13 | } 14 | 15 | return value; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /aws/localstack-lambda-with-eventbridge-rule-trigger/compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | localstack: 3 | container_name: localstack-lambda-with-eventbridge-rule-trigger 4 | image: localstack/localstack:4.4.0 5 | ports: 6 | - "4566:4566" 7 | environment: 8 | - DEBUG=${DEBUG:-0} 9 | # improve working completely offline 10 | # see: https://github.com/localstack/localstack/issues/4840 11 | - SKIP_SSL_CERT_DOWNLOAD=1 12 | - DISABLE_EVENTS=1 13 | volumes: 14 | - "/var/run/docker.sock:/var/run/docker.sock" 15 | -------------------------------------------------------------------------------- /nodejs/linting-with-typescript-eslint/src/server.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import { registerRequestLogger } from './helper/request.logger'; 3 | import { logger } from './helper/default.logger'; 4 | 5 | const app = express(); 6 | const port = 8080; // server port 7 | 8 | // register morgan 9 | registerRequestLogger(app); 10 | 11 | // default route 12 | app.get('/', (req, res) => res.json({ 13 | message: 'Hello World!' 14 | })); 15 | 16 | // server 17 | app.listen(port, () => logger.info(`Server started at http://localhost:${port}`)); 18 | -------------------------------------------------------------------------------- /nodejs/logging-with-winston/src/configuration/environment.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | nodeEnv: process.env.ENV || process.env.NODE_ENV, 3 | logDir: process.env.LOG_DIR || 'logs', 4 | logLevel: process.env.LOG_LEVEL || 'info', 5 | logFile: process.env.LOG_FILE || 'app.log', 6 | requestLogFile: process.env.MORGAN_LOG || 'requests.log', 7 | requestLogFormat: process.env.MORGAN_LOG_FMT || '[:date[iso]] :method :url :status :response-time ms - :res[content-length]', 8 | requestLogRollingInterval: process.env.MORGAN_LOG_ROLLING_INTERVAL || '1d' 9 | } -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth/src/main/java/com/example/jwt/Launcher.java: -------------------------------------------------------------------------------- 1 | package com.example.jwt; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 6 | 7 | @SpringBootApplication 8 | @EnableConfigurationProperties(JwtProperties.class) 9 | public class Launcher { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Launcher.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring/springboot4-aop-method-logging/src/test/java/com/example/method/logging/AspectAppender.java: -------------------------------------------------------------------------------- 1 | package com.example.method.logging; 2 | 3 | import ch.qos.logback.classic.spi.ILoggingEvent; 4 | import ch.qos.logback.core.AppenderBase; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | public class AspectAppender extends AppenderBase { 10 | 11 | final List events = new ArrayList<>(); 12 | 13 | @Override 14 | protected void append(ILoggingEvent event) { 15 | events.add(event); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-ui/browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /nodejs/README.md: -------------------------------------------------------------------------------- 1 | # Guides — Node.js 2 | 3 | Source code of Node.js examples published on [naiyerasif.com](https://www.naiyerasif.com) 4 | 5 | - [Developing an API with Express and Postgres](./express-postgres-api/) 6 | - [Linting with TypeScript ESLint](./linting-with-typescript-eslint/) 7 | - [Logging on Node.js with log4js-node](./logging-with-log4js-node/) 8 | - [Logging on Node.js with winston](./logging-with-winston/) 9 | - [Request logging with morgan](./morgan-request-logging/) 10 | - [Using Express with TypeScript](./express-with-typescript/) 11 | -------------------------------------------------------------------------------- /nodejs/logging-with-log4js-node/src/configuration/environment.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | nodeEnv: process.env.ENV || process.env.NODE_ENV, 3 | logDir: process.env.LOG_DIR || 'logs', 4 | logLevel: process.env.LOG_LEVEL || 'info', 5 | logFile: process.env.LOG_FILE || 'app.log', 6 | requestLogFile: process.env.MORGAN_LOG || 'requests.log', 7 | requestLogFormat: process.env.MORGAN_LOG_FMT || '[:date[iso]] :method :url :status :response-time ms - :res[content-length]', 8 | requestLogRollingInterval: process.env.MORGAN_LOG_ROLLING_INTERVAL || '1d' 9 | } -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-eddsa/src/main/java/com/example/jwt/Launcher.java: -------------------------------------------------------------------------------- 1 | package com.example.jwt; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 6 | 7 | @SpringBootApplication 8 | @EnableConfigurationProperties(JwtProperties.class) 9 | public class Launcher { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Launcher.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth/src/main/java/com/example/jwt/JwtProperties.java: -------------------------------------------------------------------------------- 1 | package com.example.jwt; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.boot.context.properties.bind.DefaultValue; 5 | 6 | import java.security.interfaces.RSAPrivateKey; 7 | import java.security.interfaces.RSAPublicKey; 8 | 9 | @ConfigurationProperties("jwt") 10 | public record JwtProperties( 11 | RSAPublicKey publicKey, 12 | RSAPrivateKey privateKey, 13 | @DefaultValue("3600") long expiry) { 14 | } 15 | -------------------------------------------------------------------------------- /@archive/spring/springboot2-aop-retry-on-failure/src/test/java/dev/mflash/guides/retry/aspect/AspectAppender.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.retry.aspect; 2 | 3 | import ch.qos.logback.classic.spi.ILoggingEvent; 4 | import ch.qos.logback.core.AppenderBase; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | public class AspectAppender extends AppenderBase { 10 | 11 | List events = new ArrayList<>(); 12 | 13 | protected @Override void append(ILoggingEvent event) { 14 | events.add(event); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /nodejs/linting-with-typescript-eslint/src/configuration/environment.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | nodeEnv: process.env.ENV || process.env.NODE_ENV, 3 | logDir: process.env.LOG_DIR || 'logs', 4 | logLevel: process.env.LOG_LEVEL || 'info', 5 | logFile: process.env.LOG_FILE || 'app.log', 6 | requestLogFile: process.env.MORGAN_LOG || 'requests.log', 7 | requestLogFormat: process.env.MORGAN_LOG_FMT || '[:date[iso]] :method :url :status :response-time ms - :res[content-length]', 8 | requestLogRollingInterval: process.env.MORGAN_LOG_ROLLING_INTERVAL || '1d' 9 | }; -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-custom-user/src/main/java/com/example/jwt/Launcher.java: -------------------------------------------------------------------------------- 1 | package com.example.jwt; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 6 | 7 | @SpringBootApplication 8 | @EnableConfigurationProperties(JwtProperties.class) 9 | public class Launcher { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Launcher.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-custom-user/src/main/java/com/example/jwt/JwtProperties.java: -------------------------------------------------------------------------------- 1 | package com.example.jwt; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.boot.context.properties.bind.DefaultValue; 5 | 6 | import java.security.interfaces.RSAPrivateKey; 7 | import java.security.interfaces.RSAPublicKey; 8 | 9 | @ConfigurationProperties("jwt") 10 | public record JwtProperties( 11 | RSAPublicKey publicKey, 12 | RSAPrivateKey privateKey, 13 | @DefaultValue("3600") long expiry) { 14 | } 15 | -------------------------------------------------------------------------------- /@archive/spring/springboot2-aop-retry-on-failure/src/main/java/dev/mflash/guides/retry/RandomlyFailingService.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.retry; 2 | 3 | import dev.mflash.guides.retry.annotation.RetryOnFailure; 4 | import org.springframework.stereotype.Service; 5 | 6 | @Service 7 | public class RandomlyFailingService { 8 | 9 | @RetryOnFailure 10 | public double random() { 11 | double random = Math.random(); 12 | 13 | if (random <= 0.5) { 14 | throw new ArithmeticException("Value <= 0.5"); 15 | } 16 | 17 | return random; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /python/testcontainers-integration-tests-with-pytest/pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "testcontainers-integration-tests-with-pytest" 3 | version = "0.0.1" 4 | description = "Integration tests using testcontainers and pytest" 5 | readme = "README.md" 6 | requires-python = ">=3.13" 7 | dependencies = [ 8 | "boto3>=1.38.28", 9 | "psycopg[binary]>=3.2.9", 10 | ] 11 | 12 | [dependency-groups] 13 | dev = [ 14 | "pytest>=8.4.0", 15 | "ruff>=0.11.12", 16 | "testcontainers[localstack,postgres]>=4.10.0", 17 | ] 18 | 19 | [tool.ruff] 20 | line-length = 120 21 | -------------------------------------------------------------------------------- /@/archives/spring/springboot3-aop-method-logging/src/test/java/com/example/method/logging/AspectAppender.java: -------------------------------------------------------------------------------- 1 | package com.example.method.logging; 2 | 3 | import ch.qos.logback.classic.spi.ILoggingEvent; 4 | import ch.qos.logback.core.AppenderBase; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | public class AspectAppender extends AppenderBase { 10 | 11 | public final List events = new ArrayList<>(); 12 | 13 | @Override 14 | protected void append(ILoggingEvent event) { 15 | events.add(event); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /spring/springboot3-local-dev-docker-compose/src/main/java/com/example/localdev/Note.java: -------------------------------------------------------------------------------- 1 | package com.example.localdev; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import lombok.Builder; 5 | import org.springframework.data.annotation.Id; 6 | import org.springframework.data.relational.core.mapping.Table; 7 | 8 | import java.util.UUID; 9 | 10 | @Table("notes") 11 | @Builder 12 | @JsonIgnoreProperties(ignoreUnknown = true) 13 | public record Note( 14 | @Id 15 | UUID id, 16 | String title, 17 | String body, 18 | boolean readOnly) { 19 | } 20 | -------------------------------------------------------------------------------- /spring/springboot3-local-dev-testcontainers/src/main/java/com/example/localdev/Note.java: -------------------------------------------------------------------------------- 1 | package com.example.localdev; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import lombok.Builder; 5 | import org.springframework.data.annotation.Id; 6 | import org.springframework.data.relational.core.mapping.Table; 7 | 8 | import java.util.UUID; 9 | 10 | @Table("notes") 11 | @Builder 12 | @JsonIgnoreProperties(ignoreUnknown = true) 13 | public record Note( 14 | @Id 15 | UUID id, 16 | String title, 17 | String body, 18 | boolean readOnly) { 19 | } 20 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-api/src/main/java/dev/mflash/guides/greeter/GreetingController.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.greeter; 2 | 3 | import io.micronaut.http.annotation.Controller; 4 | import io.micronaut.http.annotation.Get; 5 | import io.micronaut.http.annotation.QueryValue; 6 | 7 | @Controller("/hello") 8 | public class GreetingController { 9 | 10 | @Get 11 | public Greeting greet(@QueryValue(value = "name", defaultValue = "World") String name) { 12 | return new Greeting(String.format("Hello, %s!", name)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /micronaut/mn4-aws-lambda-with-eventbridge/src/main/java/com/example/FunctionRequestHandler.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import io.micronaut.function.aws.MicronautRequestHandler; 4 | import com.amazonaws.services.lambda.runtime.events.ScheduledEvent; 5 | import jakarta.inject.Inject; 6 | 7 | public class FunctionRequestHandler extends MicronautRequestHandler { 8 | 9 | private @Inject ScheduledEventService eventService; 10 | 11 | @Override 12 | public Void execute(ScheduledEvent event) { 13 | this.eventService.process(event); 14 | return null; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /nodejs/morgan-request-logging/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "morgan-request-logging", 3 | "version": "1.0.0", 4 | "main": "dist/server.js", 5 | "scripts": { 6 | "build": "tsc", 7 | "prestart": "npm run build", 8 | "start": "node ." 9 | }, 10 | "dependencies": { 11 | "express": "^4.17.1", 12 | "morgan": "^1.9.1", 13 | "rotating-file-stream": "^2.0.2" 14 | }, 15 | "devDependencies": { 16 | "@types/express": "^4.17.3", 17 | "@types/morgan": "^1.9.0", 18 | "@types/node": "^13.9.1", 19 | "typescript": "^3.8.3" 20 | }, 21 | "license": "MIT" 22 | } 23 | -------------------------------------------------------------------------------- /spring/spring-file-upload/src/main/java/dev/mflash/guides/upload/service/StorageService.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.upload.service; 2 | 3 | import org.springframework.core.io.Resource; 4 | import org.springframework.web.multipart.MultipartFile; 5 | 6 | import java.nio.file.Path; 7 | import java.util.stream.Stream; 8 | 9 | public interface StorageService { 10 | 11 | void init(); 12 | 13 | void store(MultipartFile... files); 14 | 15 | Stream loadAll(); 16 | 17 | Path load(String filename); 18 | 19 | Resource loadAsResource(String filename); 20 | 21 | void deleteAll(); 22 | } -------------------------------------------------------------------------------- /java/jackson3-polymorphic-requests/src/main/java/com/example/jackson/polymorphic/CartItem.java: -------------------------------------------------------------------------------- 1 | package com.example.jackson.polymorphic; 2 | 3 | import com.fasterxml.jackson.annotation.JsonSubTypes; 4 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 5 | 6 | @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "itemCategory") 7 | @JsonSubTypes({ 8 | @JsonSubTypes.Type(value = Software.class, name = "SOFTWARE"), 9 | @JsonSubTypes.Type(value = Accessory.class, name = "ACCESSORY"), 10 | }) 11 | sealed interface CartItem permits Software, Accessory { 12 | 13 | ItemCategory itemCategory(); 14 | } 15 | -------------------------------------------------------------------------------- /spring/spring-data-mongo-repository/src/main/java/dev/mflash/guides/mongo/domain/Session.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.mongo.domain; 2 | 3 | import lombok.Builder; 4 | import lombok.Builder.Default; 5 | import lombok.Data; 6 | import org.springframework.data.annotation.Id; 7 | 8 | import java.time.LocalDateTime; 9 | import java.util.Locale; 10 | import java.util.UUID; 11 | 12 | @Data @Builder 13 | public class Session { 14 | 15 | private final @Id @Default String key = UUID.randomUUID().toString(); 16 | private String city; 17 | private Locale locale; 18 | private LocalDateTime accessed; 19 | } 20 | -------------------------------------------------------------------------------- /spring/spring-data-jdbc-hikari-leak-detection/src/main/java/com/example/BookRepository.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.data.jdbc.repository.query.Query; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | //import java.util.Collection; 7 | import java.util.UUID; 8 | import java.util.stream.Stream; 9 | 10 | public interface BookRepository extends CrudRepository { 11 | 12 | @Query("select * from book where array_contains(genre, :genre)") 13 | Stream findAllByGenre(String genre); 14 | // Collection findAllByGenre(String genre); 15 | } 16 | -------------------------------------------------------------------------------- /spring/spring-data-mongo-repository/src/main/java/dev/mflash/guides/mongo/repository/AccountRepository.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.mongo.repository; 2 | 3 | import dev.mflash.guides.mongo.domain.Account; 4 | import dev.mflash.guides.mongo.domain.Session; 5 | import dev.mflash.guides.mongo.domain.User; 6 | import org.springframework.data.mongodb.repository.MongoRepository; 7 | 8 | import java.util.List; 9 | 10 | public interface AccountRepository extends MongoRepository { 11 | 12 | Account findDistinctFirstByUser(User user); 13 | 14 | List findBySessions(Session session); 15 | } 16 | -------------------------------------------------------------------------------- /spring/spring-file-upload/web/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "lib": [ 15 | "es2018", 16 | "dom" 17 | ] 18 | }, 19 | "angularCompilerOptions": { 20 | "fullTemplateTypeCheck": true, 21 | "strictInjectionParameters": true 22 | } 23 | } -------------------------------------------------------------------------------- /spring/spring-data-mongo-repository/src/main/java/dev/mflash/guides/mongo/domain/User.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.mongo.domain; 2 | 3 | import lombok.Builder; 4 | import lombok.Builder.Default; 5 | import lombok.Data; 6 | import org.springframework.data.annotation.Id; 7 | 8 | import java.time.LocalDate; 9 | import java.util.Locale; 10 | import java.util.UUID; 11 | 12 | @Data @Builder 13 | public class User { 14 | 15 | private final @Id @Default String key = UUID.randomUUID().toString(); 16 | private String name; 17 | private String email; 18 | private Locale locale; 19 | private LocalDate dateOfBirth; 20 | } 21 | -------------------------------------------------------------------------------- /spring/springrx-file-upload/web/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "lib": [ 15 | "es2018", 16 | "dom" 17 | ] 18 | }, 19 | "angularCompilerOptions": { 20 | "fullTemplateTypeCheck": true, 21 | "strictInjectionParameters": true 22 | } 23 | } -------------------------------------------------------------------------------- /nodejs/logging-with-log4js-node/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "logging-with-log4js-node", 3 | "version": "1.0.0", 4 | "main": "dist/server.js", 5 | "scripts": { 6 | "build": "tsc", 7 | "prestart": "npm run build", 8 | "start": "node ." 9 | }, 10 | "dependencies": { 11 | "express": "^4.17.1", 12 | "log4js": "^6.1.2", 13 | "morgan": "^1.9.1", 14 | "rotating-file-stream": "^2.0.2" 15 | }, 16 | "devDependencies": { 17 | "@types/express": "^4.17.3", 18 | "@types/morgan": "^1.9.0", 19 | "@types/node": "^13.9.1", 20 | "typescript": "^3.8.3" 21 | }, 22 | "license": "MIT" 23 | } 24 | -------------------------------------------------------------------------------- /spring/springrx-file-upload/src/main/java/dev/mflash/guides/upload/service/StorageService.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.upload.service; 2 | 3 | import org.springframework.core.io.Resource; 4 | import org.springframework.http.codec.multipart.FilePart; 5 | 6 | import java.nio.file.Path; 7 | import java.util.List; 8 | import java.util.stream.Stream; 9 | 10 | public interface StorageService { 11 | 12 | void init(); 13 | 14 | void store(List files); 15 | 16 | Stream loadAll(); 17 | 18 | Path load(String filename); 19 | 20 | Resource loadAsResource(String filename); 21 | 22 | void deleteAll(); 23 | } 24 | -------------------------------------------------------------------------------- /python/testcontainers-integration-tests-with-pytest/app/main.py: -------------------------------------------------------------------------------- 1 | from app.aws import s3 2 | from app.conf import conf 3 | from app.dbclient import connection 4 | 5 | 6 | def download_file_as_bytes(object_key: str) -> bytes: 7 | response = s3.get_object(Bucket=conf.bucket_name, Key=object_key) 8 | return response["Body"].read() 9 | 10 | 11 | def read_text_file(file_id: int): 12 | with connection.cursor() as cur: 13 | object_key = cur.execute("select object_key from files where id = %(id)s", {"id": file_id}).fetchone()[0] 14 | data = download_file_as_bytes(object_key) 15 | return data.decode("utf-8") 16 | -------------------------------------------------------------------------------- /@sample/spring/springboot3-notes-api/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | create extension if not exists "uuid-ossp"; 2 | drop table if exists notes; 3 | create table notes ( 4 | id uuid primary key default uuid_generate_v1(), 5 | title varchar(255) not null, 6 | body text, 7 | created_by varchar(255) not null, 8 | created_at timestamptz not null default localtimestamp, 9 | updated_by varchar(255) not null, 10 | updated_at timestamptz not null default localtimestamp, 11 | version smallint not null default 1, 12 | word_count int not null, 13 | read_only boolean not null default false 14 | ); 15 | -------------------------------------------------------------------------------- /spring/springboot3-springdoc-integration/src/main/java/com/example/springdoc/OpenAPIConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.example.springdoc; 2 | 3 | import io.swagger.v3.oas.models.OpenAPI; 4 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | @Configuration 9 | @EnableConfigurationProperties(OpenAPIProperties.class) 10 | public class OpenAPIConfiguration { 11 | 12 | @Bean 13 | public OpenAPI openAPI(OpenAPIProperties openAPIProperties) { 14 | return openAPIProperties; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring/springboot3-springdoc-integration/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | create extension if not exists "uuid-ossp"; 2 | drop table if exists notes; 3 | create table notes ( 4 | id uuid primary key default uuid_generate_v1(), 5 | title varchar(255) not null, 6 | body text, 7 | created_by varchar(255) not null, 8 | created_at timestamptz not null default localtimestamp, 9 | updated_by varchar(255) not null, 10 | updated_at timestamptz not null default localtimestamp, 11 | version smallint not null default 1, 12 | word_count int not null, 13 | read_only boolean not null default false 14 | ); 15 | -------------------------------------------------------------------------------- /spring/spring-security-token-validation-local/src/main/java/dev/mflash/guides/tokenval/local/security/OidcProperties.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.tokenval.local.security; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.boot.context.properties.ConstructorBinding; 5 | 6 | @ConfigurationProperties("auth") 7 | @ConstructorBinding 8 | public class OidcProperties { 9 | 10 | private final String audience; 11 | 12 | public OidcProperties(String audience) { 13 | this.audience = audience; 14 | } 15 | 16 | public String getAudience() { 17 | return audience; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring/springboot4-aop-method-logging/src/main/java/com/example/method/logging/GreetingService.java: -------------------------------------------------------------------------------- 1 | package com.example.method.logging; 2 | 3 | import com.example.method.logging.annotation.LogEntryExit; 4 | import org.springframework.stereotype.Service; 5 | 6 | import java.time.temporal.ChronoUnit; 7 | 8 | @Service 9 | public class GreetingService { 10 | 11 | @LogEntryExit(showArgs = true, showResult = true, unit = ChronoUnit.MILLIS) 12 | public String greet(String name) { 13 | return "Hello, " + resolveName(name) + "!"; 14 | } 15 | 16 | public String resolveName(String name) { 17 | return !name.isBlank() ? name : "world"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring/spring-security-token-validation-hybrid/src/main/java/dev/mflash/guides/tokenval/hybrid/security/OidcProperties.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.tokenval.hybrid.security; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.boot.context.properties.ConstructorBinding; 5 | 6 | @ConfigurationProperties("auth") 7 | @ConstructorBinding 8 | public class OidcProperties { 9 | 10 | private final String audience; 11 | 12 | public OidcProperties(String audience) { 13 | this.audience = audience; 14 | } 15 | 16 | public String getAudience() { 17 | return audience; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /@/archives/spring/springboot3-aop-method-logging/src/main/java/com/example/method/logging/GreetingService.java: -------------------------------------------------------------------------------- 1 | package com.example.method.logging; 2 | 3 | import com.example.method.logging.annotation.LogEntryExit; 4 | import org.springframework.stereotype.Service; 5 | 6 | import java.time.temporal.ChronoUnit; 7 | 8 | @Service 9 | public class GreetingService { 10 | 11 | @LogEntryExit(showArgs = true, showResult = true, unit = ChronoUnit.MILLIS) 12 | public String greet(String name) { 13 | return "Hello, " + resolveName(name) + "!"; 14 | } 15 | 16 | public String resolveName(String name) { 17 | return !name.isBlank() ? name : "world"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /nodejs/logging-with-winston/src/helper/default.logger.ts: -------------------------------------------------------------------------------- 1 | import winston from 'winston'; 2 | import DailyRotateFile from 'winston-daily-rotate-file'; 3 | import { environment } from '../configuration/environment'; 4 | 5 | export const logger = winston.createLogger({ 6 | level: environment.logLevel, 7 | format: winston.format.simple(), 8 | transports: [ 9 | new winston.transports.Console(), 10 | new DailyRotateFile({ 11 | filename: environment.logFile, 12 | dirname: environment.logDir, 13 | datePattern: 'YYYY-MM-DD', 14 | zippedArchive: true, 15 | maxFiles: '14d', 16 | maxSize: '20m' 17 | }) 18 | ] 19 | }); 20 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-api/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | false 4 | 6 | 7 | %cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - 8 | %msg%n 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /micronaut/mn4-aws-lambda-with-eventbridge/src/main/java/com/example/ScheduledEventService.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import com.amazonaws.services.lambda.runtime.events.ScheduledEvent; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import jakarta.inject.Singleton; 6 | 7 | @Singleton 8 | public class ScheduledEventService { 9 | 10 | private final ObjectMapper mapper = new ObjectMapper(); 11 | 12 | record EventDetails(String message) {} 13 | 14 | public void process(ScheduledEvent event) { 15 | var eventDetails = mapper.convertValue(event.getDetail(), EventDetails.class); 16 | System.out.println(eventDetails.message()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring/spring-rest-error-handling/src/main/java/dev/mflash/guides/resterror/persistence/BookRepository.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.resterror.persistence; 2 | 3 | import dev.mflash.guides.resterror.domain.Book; 4 | import org.springframework.data.jdbc.repository.query.Modifying; 5 | import org.springframework.data.jdbc.repository.query.Query; 6 | import org.springframework.data.repository.CrudRepository; 7 | import org.springframework.data.repository.query.Param; 8 | 9 | public interface BookRepository extends CrudRepository { 10 | 11 | @Modifying 12 | @Query("delete from book where id = :id") 13 | int deleteById(@Param("id") long id); 14 | } 15 | -------------------------------------------------------------------------------- /spring/spring-security-token-validation-local/src/main/java/dev/mflash/guides/tokenval/local/Launcher.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.tokenval.local; 2 | 3 | import dev.mflash.guides.tokenval.local.security.OidcProperties; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 7 | 8 | @EnableConfigurationProperties(OidcProperties.class) 9 | public @SpringBootApplication class Launcher { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Launcher.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /nodejs/logging-with-winston/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "logging-with-winston", 3 | "version": "1.0.0", 4 | "main": "dist/server.js", 5 | "scripts": { 6 | "build": "tsc", 7 | "prestart": "npm run build", 8 | "start": "node ." 9 | }, 10 | "dependencies": { 11 | "express": "^4.17.1", 12 | "morgan": "^1.9.1", 13 | "rotating-file-stream": "^2.0.2", 14 | "winston": "^3.2.1", 15 | "winston-daily-rotate-file": "^4.4.2" 16 | }, 17 | "devDependencies": { 18 | "@types/express": "^4.17.3", 19 | "@types/morgan": "^1.9.0", 20 | "@types/node": "^13.9.1", 21 | "typescript": "^3.8.3" 22 | }, 23 | "license": "MIT" 24 | } 25 | -------------------------------------------------------------------------------- /spring/spring-security-token-validation-hybrid/src/main/java/dev/mflash/guides/tokenval/hybrid/Launcher.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.tokenval.hybrid; 2 | 3 | import dev.mflash.guides.tokenval.hybrid.security.OidcProperties; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 7 | 8 | @EnableConfigurationProperties(OidcProperties.class) 9 | public @SpringBootApplication class Launcher { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Launcher.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring/spring-data-jdbc-hikari-leak-detection/src/main/java/com/example/BookController.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import java.util.List; 9 | 10 | @RestController 11 | @RequestMapping("/book") 12 | public record BookController(BookRepository repository) { 13 | 14 | @GetMapping 15 | public List booksByGenre(@RequestParam String genre) { 16 | return repository.findAllByGenre(genre).toList(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /nodejs/express-postgres-api/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 'parser': '@typescript-eslint/parser', 3 | 'extends': ['plugin:@typescript-eslint/eslint-recommended'], 4 | 'parserOptions': { 5 | 'ecmaVersion': 2018, 6 | 'sourceType': 'module' 7 | }, 8 | 'plugins': ['@typescript-eslint'], 9 | 'rules': { 10 | 'quotes': ['error', 'single'], 11 | 'semi': ['error', 'always'], 12 | '@typescript-eslint/explicit-function-return-type': 'off', 13 | '@typescript-eslint/no-explicit-any': 1, 14 | '@typescript-eslint/no-inferrable-types': [ 15 | 'warn', { 'ignoreParameters': true } 16 | ], 17 | '@typescript-eslint/no-unused-vars': 'warn' 18 | } 19 | } -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth/src/main/java/com/example/jwt/PEMEncoder.java: -------------------------------------------------------------------------------- 1 | package com.example.jwt; 2 | 3 | import java.security.Key; 4 | import java.security.PublicKey; 5 | import java.util.Base64; 6 | 7 | public final class PEMEncoder { 8 | 9 | private PEMEncoder() {} 10 | 11 | public static PEMEncoder of() { 12 | return new PEMEncoder(); 13 | } 14 | 15 | public String encodeToString(Key key) { 16 | var marker = key instanceof PublicKey ? "PUBLIC KEY" : "PRIVATE KEY"; 17 | String base64 = Base64.getMimeEncoder(64, "\n".getBytes()).encodeToString(key.getEncoded()); 18 | return "-----BEGIN " + marker + "-----\n" + base64 + "\n-----END " + marker + "-----"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-eddsa/src/main/java/com/example/jwt/userdetails/CustomUser.java: -------------------------------------------------------------------------------- 1 | package com.example.jwt.userdetails; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | import com.fasterxml.jackson.annotation.JsonProperty.Access; 6 | import org.springframework.data.annotation.Id; 7 | 8 | import java.util.UUID; 9 | 10 | @JsonIgnoreProperties(value = { "id" }) 11 | public record CustomUser(@Id UUID id, String username, @JsonProperty(access = Access.WRITE_ONLY) String password) { 12 | 13 | public CustomUser(String username, String password) { 14 | this(null, username, password); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /nodejs/linting-with-typescript-eslint/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 'parser': '@typescript-eslint/parser', 3 | 'extends': ['plugin:@typescript-eslint/eslint-recommended'], 4 | 'parserOptions': { 5 | 'ecmaVersion': 2018, 6 | 'sourceType': 'module' 7 | }, 8 | 'plugins': ['@typescript-eslint'], 9 | 'rules': { 10 | 'quotes': ['error', 'single'], 11 | 'semi': ['error', 'always'], 12 | '@typescript-eslint/explicit-function-return-type': 'off', 13 | '@typescript-eslint/no-explicit-any': 1, 14 | '@typescript-eslint/no-inferrable-types': [ 15 | 'warn', { 'ignoreParameters': true } 16 | ], 17 | '@typescript-eslint/no-unused-vars': 'warn' 18 | } 19 | } -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-custom-user/src/main/java/com/example/jwt/userdetails/CustomUser.java: -------------------------------------------------------------------------------- 1 | package com.example.jwt.userdetails; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | import com.fasterxml.jackson.annotation.JsonProperty.Access; 6 | import org.springframework.data.annotation.Id; 7 | 8 | import java.util.UUID; 9 | 10 | @JsonIgnoreProperties(value = { "id" }) 11 | public record CustomUser(@Id UUID id, String username, @JsonProperty(access = Access.WRITE_ONLY) String password) { 12 | 13 | public CustomUser(String username, String password) { 14 | this(null, username, password); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-eddsa/src/main/java/com/example/jwt/PEMEncoder.java: -------------------------------------------------------------------------------- 1 | package com.example.jwt; 2 | 3 | import java.security.Key; 4 | import java.security.PublicKey; 5 | import java.util.Base64; 6 | 7 | public final class PEMEncoder { 8 | 9 | private PEMEncoder() {} 10 | 11 | public static PEMEncoder of() { 12 | return new PEMEncoder(); 13 | } 14 | 15 | public String encodeToString(Key key) { 16 | var marker = key instanceof PublicKey ? "PUBLIC KEY" : "PRIVATE KEY"; 17 | String base64 = Base64.getMimeEncoder(64, "\n".getBytes()).encodeToString(key.getEncoded()); 18 | return "-----BEGIN " + marker + "-----\n" + base64 + "\n-----END " + marker + "-----"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-custom-user/src/main/java/com/example/jwt/PEMEncoder.java: -------------------------------------------------------------------------------- 1 | package com.example.jwt; 2 | 3 | import java.security.Key; 4 | import java.security.PublicKey; 5 | import java.util.Base64; 6 | 7 | public final class PEMEncoder { 8 | 9 | private PEMEncoder() {} 10 | 11 | public static PEMEncoder of() { 12 | return new PEMEncoder(); 13 | } 14 | 15 | public String encodeToString(Key key) { 16 | var marker = key instanceof PublicKey ? "PUBLIC KEY" : "PRIVATE KEY"; 17 | String base64 = Base64.getMimeEncoder(64, "\n".getBytes()).encodeToString(key.getEncoded()); 18 | return "-----BEGIN " + marker + "-----\n" + base64 + "\n-----END " + marker + "-----"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring/springboot3-aop-retry-on-failure/src/main/java/com/example/retry/RandomlyFailingController.java: -------------------------------------------------------------------------------- 1 | package com.example.retry; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | @RequestMapping("/random") 9 | public class RandomlyFailingController { 10 | 11 | private final RandomlyFailingService service; 12 | 13 | public RandomlyFailingController(RandomlyFailingService service) { 14 | this.service = service; 15 | } 16 | 17 | @GetMapping 18 | public double getRandom() { 19 | return service.random(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring/spring-rest-error-handling/src/main/java/dev/mflash/guides/resterror/exception/ResourceNotFoundException.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.resterror.exception; 2 | 3 | import static org.springframework.http.HttpStatus.NOT_FOUND; 4 | 5 | import org.springframework.web.server.ResponseStatusException; 6 | 7 | public class ResourceNotFoundException extends ResponseStatusException { 8 | 9 | public ResourceNotFoundException() { 10 | super(NOT_FOUND); 11 | } 12 | 13 | public ResourceNotFoundException(String reason) { 14 | super(NOT_FOUND, reason); 15 | } 16 | 17 | public ResourceNotFoundException(String reason, Throwable cause) { 18 | super(NOT_FOUND, reason, cause); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring/spring-security-resource-server-error-handling/src/main/java/dev/mflash/guides/tokenval/introspection/security/WWWAuthenticateHeaderBuilder.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.tokenval.introspection.security; 2 | 3 | import java.util.Map; 4 | import java.util.StringJoiner; 5 | 6 | public final class WWWAuthenticateHeaderBuilder { 7 | 8 | public static String computeWWWAuthenticateHeaderValue(Map parameters) { 9 | StringJoiner wwwAuthenticate = new StringJoiner(", ", "Bearer ", ""); 10 | 11 | if (!parameters.isEmpty()) { 12 | parameters.forEach((k, v) -> wwwAuthenticate.add(k + "=\"" + v + "\"")); 13 | } 14 | 15 | return wwwAuthenticate.toString(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /python/testcontainers-integration-tests-with-pytest/tests/mockutils.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from contextlib import contextmanager 3 | from types import ModuleType 4 | 5 | 6 | @contextmanager 7 | def mock_module(module_name: str, **attributes): 8 | original_module = sys.modules.get(module_name) 9 | mocked_module = ModuleType(module_name) 10 | for name, value in attributes.items(): 11 | setattr(mocked_module, name, value) 12 | sys.modules[module_name] = mocked_module 13 | 14 | try: 15 | yield 16 | finally: 17 | if original_module is not None: 18 | sys.modules[module_name] = original_module 19 | else: 20 | sys.modules.pop(module_name, None) 21 | -------------------------------------------------------------------------------- /spring/spring-content-negotiation/src/main/java/dev/mflash/guides/spring/negotiation/GameController.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.spring.negotiation; 2 | 3 | import org.springframework.http.MediaType; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | @RequestMapping("/game") 10 | public class GameController { 11 | 12 | @GetMapping(value = "/trial", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE }) 13 | public Game getTrialGame() { 14 | return new Game("Control", "Remedy Entertainment"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring/springboot3-springdoc-integration/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | password: stacy 4 | username: gwen 5 | url: jdbc:postgresql://localhost:5432/brooklyn 6 | sql.init.mode: always 7 | 8 | openapi: 9 | info: 10 | title: "Notes API" 11 | description: "A demo of Springdoc integration with custom configuration" 12 | version: "@project.version@" 13 | license: 14 | name: MIT 15 | url: "https://opensource.org/licenses/MIT" 16 | security: 17 | - BearerToken: 18 | components: 19 | security-schemes: 20 | BearerToken: 21 | name: BearerToken 22 | type: HTTP 23 | scheme: bearer 24 | bearer-format: JWT 25 | -------------------------------------------------------------------------------- /@archive/spring/springboot2-aop-retry-on-failure/src/main/java/dev/mflash/guides/retry/RandomlyFailingController.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.retry; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | @RequestMapping("/random") 9 | public class RandomlyFailingController { 10 | 11 | private final RandomlyFailingService service; 12 | 13 | public RandomlyFailingController(RandomlyFailingService service) { 14 | this.service = service; 15 | } 16 | 17 | @GetMapping 18 | public double getRandom() { 19 | return service.random(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-ui/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ], 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ] 21 | }, 22 | "angularCompilerOptions": { 23 | "fullTemplateTypeCheck": true, 24 | "strictInjectionParameters": true 25 | } 26 | } -------------------------------------------------------------------------------- /java/aop-compile-time/src/main/java/com/example/aop/GreetingHandler.java: -------------------------------------------------------------------------------- 1 | package com.example.aop; 2 | 3 | import com.example.aop.annotation.LogEntryExit; 4 | 5 | import java.time.temporal.ChronoUnit; 6 | 7 | public class GreetingHandler { 8 | 9 | @LogEntryExit(showArgs = true, showResult = true, unit = ChronoUnit.MILLIS) 10 | public String greet(String name) { 11 | return "Hello, " + resolveName(name) + "!"; 12 | } 13 | 14 | @LogEntryExit(showArgs = true, showResult = true, unit = ChronoUnit.MILLIS) 15 | private String resolveName(String name) { 16 | return !name.isBlank() ? name : "world"; 17 | } 18 | 19 | public void resolveNothing(String randomString) { 20 | IO.println("All good, nothing to resolve!"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /nodejs/express-postgres-api/src/helper/default.logger.ts: -------------------------------------------------------------------------------- 1 | import { configure, getLogger } from 'log4js'; 2 | import { environment } from '../configuration/environment'; 3 | 4 | // appenders 5 | configure({ 6 | appenders: { 7 | console: { type: 'stdout', layout: { type: 'colored' } }, 8 | dateFile: { 9 | type: 'dateFile', 10 | filename: `${environment.logDir}/${environment.logFile}`, 11 | layout: { type: 'basic' }, 12 | compress: true, 13 | daysToKeep: 14, 14 | keepFileExt: true 15 | } 16 | }, 17 | categories: { 18 | default: { appenders: ['console', 'dateFile'], level: environment.logLevel } 19 | } 20 | }); 21 | 22 | // fetch logger and export 23 | export const logger = getLogger(); 24 | -------------------------------------------------------------------------------- /java/aop-compile-time/src/main/java/com/example/aop/annotation/LogEntryExit.java: -------------------------------------------------------------------------------- 1 | package com.example.aop.annotation; 2 | 3 | import org.slf4j.event.Level; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | import java.time.temporal.ChronoUnit; 10 | 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target(ElementType.METHOD) 13 | public @interface LogEntryExit { 14 | 15 | Level value() default Level.INFO; 16 | 17 | ChronoUnit unit() default ChronoUnit.SECONDS; 18 | 19 | boolean showArgs() default false; 20 | 21 | boolean showResult() default false; 22 | 23 | boolean showExecutionTime() default true; 24 | } 25 | -------------------------------------------------------------------------------- /java/jacoco-coverage-with-maven/src/main/java/com/example/PalindromeChecker.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | interface PalindromeChecker { 4 | 5 | static boolean isPalindrome(final String input) { 6 | var forward = 0; 7 | var backward = input.length() - 1; 8 | var str = input.toLowerCase(); 9 | while (backward > forward) { 10 | if (str.charAt(forward) != str.charAt(backward)) { 11 | return false; 12 | } 13 | forward++; 14 | backward--; 15 | } 16 | return true; 17 | } 18 | 19 | static boolean isPalindrome(final int input) { 20 | int MINUS = -1; 21 | return input < 0 ? isPalindrome(String.valueOf(input * MINUS)) 22 | : isPalindrome(String.valueOf(input)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /nodejs/logging-with-log4js-node/src/helper/default.logger.ts: -------------------------------------------------------------------------------- 1 | import { configure, getLogger } from 'log4js'; 2 | import { environment } from '../configuration/environment'; 3 | 4 | // appenders 5 | configure({ 6 | appenders: { 7 | console: { type: 'stdout', layout: { type: 'colored' } }, 8 | dateFile: { 9 | type: 'dateFile', 10 | filename: `${environment.logDir}/${environment.logFile}`, 11 | layout: { type: 'basic' }, 12 | compress: true, 13 | daysToKeep: 14, 14 | keepFileExt: true 15 | } 16 | }, 17 | categories: { 18 | default: { appenders: ['console', 'dateFile'], level: environment.logLevel } 19 | } 20 | }); 21 | 22 | // fetch logger and export 23 | export const logger = getLogger(); 24 | -------------------------------------------------------------------------------- /spring/springboot4-aop-method-logging/src/main/java/com/example/method/logging/Launcher.java: -------------------------------------------------------------------------------- 1 | package com.example.method.logging; 2 | 3 | import org.springframework.boot.CommandLineRunner; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.annotation.Bean; 7 | 8 | @SpringBootApplication 9 | public class Launcher { 10 | 11 | void main(String... args) { 12 | SpringApplication.run(Launcher.class, args); 13 | } 14 | 15 | @Bean 16 | public CommandLineRunner commandLineRunner(GreetingService greetingService) { 17 | return _ -> { 18 | greetingService.greet("Joe"); 19 | greetingService.greet("Jane"); 20 | }; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /nodejs/linting-with-typescript-eslint/src/helper/default.logger.ts: -------------------------------------------------------------------------------- 1 | import { configure, getLogger } from 'log4js'; 2 | import { environment } from '../configuration/environment'; 3 | 4 | // appenders 5 | configure({ 6 | appenders: { 7 | console: { type: 'stdout', layout: { type: 'colored' } }, 8 | dateFile: { 9 | type: 'dateFile', 10 | filename: `${environment.logDir}/${environment.logFile}`, 11 | layout: { type: 'basic' }, 12 | compress: true, 13 | daysToKeep: 14, 14 | keepFileExt: true 15 | } 16 | }, 17 | categories: { 18 | default: { appenders: ['console', 'dateFile'], level: environment.logLevel } 19 | } 20 | }); 21 | 22 | // fetch logger and export 23 | export const logger = getLogger(); 24 | -------------------------------------------------------------------------------- /spring/spring-data-jdbc-hikari-leak-detection/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | create table book ( 2 | id uuid default random_uuid() primary key, 3 | title varchar(255) not null, 4 | author varchar(255) not null, 5 | genre varchar(255) array not null 6 | ); 7 | 8 | insert into book (title, author, genre) 9 | values ('Royal Gambit', 'Daniel O''Malley', array['Fantasy', 'Science Fiction']), 10 | ('Nemesis', 'Gregg Hurwitz', array['Action', 'Thriller']), 11 | ('Shroud', 'Adrian Tchaikovsky', array['Science Fiction', 'Horror']), 12 | ('Careless People', 'Sarah Wynn-Williams', array['Memoir']), 13 | ('Raising Hare', 'Chloe Dalton', array['Memoir']), 14 | ('System Collapse', 'Martha Wells', array['Science Fiction', 'Space Opera']); 15 | -------------------------------------------------------------------------------- /spring/spring-rest-error-handling/src/main/java/dev/mflash/guides/resterror/exception/InvalidOperationException.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.resterror.exception; 2 | 3 | import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; 4 | 5 | import org.springframework.web.server.ResponseStatusException; 6 | 7 | public class InvalidOperationException extends ResponseStatusException { 8 | 9 | public InvalidOperationException() { 10 | super(INTERNAL_SERVER_ERROR); 11 | } 12 | 13 | public InvalidOperationException(String reason) { 14 | super(INTERNAL_SERVER_ERROR, reason); 15 | } 16 | 17 | public InvalidOperationException(String reason, Throwable cause) { 18 | super(INTERNAL_SERVER_ERROR, reason, cause); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /nodejs/express-postgres-api/src/server.ts: -------------------------------------------------------------------------------- 1 | import express from 'express'; 2 | import bodyParser from 'body-parser'; 3 | import { environment } from './configuration/environment'; 4 | import { registerRequestLogger } from './helper/request.logger'; 5 | import { logger } from './helper/default.logger'; 6 | import { registerEndpoints } from './api'; 7 | 8 | const app = express(); 9 | const port = environment.serverPort; // server port 10 | app.use(bodyParser.json()); // body parser to read request body 11 | 12 | // register morgan 13 | registerRequestLogger(app); 14 | 15 | // register all endpoints 16 | registerEndpoints(app); 17 | 18 | // server 19 | app.listen(port, () => logger.info(`Server started at http://localhost:${port}, Press CTRL+C to stop it`)); 20 | -------------------------------------------------------------------------------- /aws/localstack-lambda-with-sns-trigger/src/main/java/com/example/SnsRequestHandler.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import com.amazonaws.services.lambda.runtime.Context; 4 | import com.amazonaws.services.lambda.runtime.RequestHandler; 5 | import com.amazonaws.services.lambda.runtime.events.SNSEvent; 6 | 7 | import java.util.List; 8 | 9 | public class SnsRequestHandler implements RequestHandler> { 10 | 11 | @Override 12 | public List handleRequest(SNSEvent event, Context context) { 13 | final List messages = event.getRecords().stream() 14 | .map(SNSEvent.SNSRecord::getSNS) 15 | .map(SNSEvent.SNS::getMessage) 16 | .toList(); 17 | messages.forEach(System.out::println); 18 | return messages; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /java/deep-copying/src/main/java/dev/mflash/guides/java/deepcopy/domain/Book.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.java.deepcopy.domain; 2 | 3 | public class Book implements Copyable { 4 | 5 | private String title; 6 | private Author author; 7 | 8 | public String getTitle() { 9 | return title; 10 | } 11 | 12 | public void setTitle(String title) { 13 | this.title = title; 14 | } 15 | 16 | public Author getAuthor() { 17 | return author; 18 | } 19 | 20 | public void setAuthor(Author author) { 21 | this.author = author; 22 | } 23 | 24 | @Override 25 | public Book copy() { 26 | final Book newBook = new Book(); 27 | newBook.setAuthor(author.copy()); 28 | newBook.setTitle(title); 29 | return newBook; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /@/templates/maven-java-template/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.example 8 | maven-java-template 9 | 1.0.0 10 | 11 | 12 | 25 13 | ${java.version} 14 | ${java.version} 15 | UTF-8 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /spring/springboot4-aop-method-logging/src/main/java/com/example/method/logging/annotation/LogEntryExit.java: -------------------------------------------------------------------------------- 1 | package com.example.method.logging.annotation; 2 | 3 | import org.slf4j.event.Level; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | import java.time.temporal.ChronoUnit; 10 | 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target(ElementType.METHOD) 13 | public @interface LogEntryExit { 14 | 15 | Level value() default Level.INFO; 16 | 17 | ChronoUnit unit() default ChronoUnit.SECONDS; 18 | 19 | boolean showArgs() default false; 20 | 21 | boolean showResult() default false; 22 | 23 | boolean showExecutionTime() default true; 24 | } 25 | -------------------------------------------------------------------------------- /spring/spring-data-mongo-repository/src/main/java/dev/mflash/guides/mongo/event/IdentifierCallback.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.mongo.event; 2 | 3 | import org.springframework.data.annotation.Id; 4 | import org.springframework.util.ReflectionUtils; 5 | import org.springframework.util.ReflectionUtils.FieldCallback; 6 | 7 | import java.lang.reflect.Field; 8 | 9 | public class IdentifierCallback implements FieldCallback { 10 | 11 | private boolean idFound; 12 | 13 | public @Override void doWith(final Field field) throws IllegalArgumentException { 14 | ReflectionUtils.makeAccessible(field); 15 | 16 | if (field.isAnnotationPresent(Id.class)) { 17 | idFound = true; 18 | } 19 | } 20 | 21 | public boolean isIdFound() { 22 | return idFound; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /spring/spring-data-mongo-repository/src/main/java/dev/mflash/guides/mongo/domain/Account.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.mongo.domain; 2 | 3 | import dev.mflash.guides.mongo.event.Cascade; 4 | import lombok.Builder; 5 | import lombok.Builder.Default; 6 | import lombok.Data; 7 | import lombok.Singular; 8 | import org.springframework.data.annotation.Id; 9 | import org.springframework.data.mongodb.core.mapping.DBRef; 10 | 11 | import java.time.ZonedDateTime; 12 | import java.util.Set; 13 | import java.util.UUID; 14 | 15 | @Data @Builder 16 | public class Account { 17 | 18 | private final @Id @Default String key = UUID.randomUUID().toString(); 19 | private @DBRef @Cascade User user; 20 | private @DBRef @Cascade @Singular Set sessions; 21 | private ZonedDateTime created; 22 | } 23 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth/src/main/java/com/example/jwt/web/GreetingController.java: -------------------------------------------------------------------------------- 1 | package com.example.jwt.web; 2 | 3 | import org.springframework.security.core.Authentication; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class GreetingController { 9 | 10 | public static final String PUBLIC_ENDPOINT = "/public"; 11 | public static final String PRIVATE_ENDPOINT = "/private"; 12 | 13 | @GetMapping(PUBLIC_ENDPOINT) 14 | public String greetPublic() { 15 | return "Hello, World!"; 16 | } 17 | 18 | @GetMapping(PRIVATE_ENDPOINT) 19 | public String greetPrivate(Authentication authentication) { 20 | return "Hello, " + authentication.getName() + "!"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-eddsa/src/main/java/com/example/jwt/web/GreetingController.java: -------------------------------------------------------------------------------- 1 | package com.example.jwt.web; 2 | 3 | import org.springframework.security.core.Authentication; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class GreetingController { 9 | 10 | public static final String PUBLIC_ENDPOINT = "/public"; 11 | public static final String PRIVATE_ENDPOINT = "/private"; 12 | 13 | @GetMapping(PUBLIC_ENDPOINT) 14 | public String greetPublic() { 15 | return "Hello, World!"; 16 | } 17 | 18 | @GetMapping(PRIVATE_ENDPOINT) 19 | public String greetPrivate(Authentication authentication) { 20 | return "Hello, " + authentication.getName() + "!"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /spring/spring-file-upload/web/src/styles.scss: -------------------------------------------------------------------------------- 1 | @charset 'utf-8'; 2 | 3 | $family-sans-serif: Inter, BlinkMacSystemFont, -apple-system, 'Segoe UI', 4 | 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 5 | 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif !default; 6 | 7 | $yellow: #f99a00 !default; 8 | $green: #16bf68 !default; 9 | $turquoise: #37a68c !default; 10 | $blue: #006fd8 !default; 11 | $red: #db2e4d !default; 12 | 13 | .form { 14 | display: flex; 15 | align-items: center; 16 | margin-bottom: 0.5rem; 17 | } 18 | 19 | .file-control { 20 | margin-bottom: 0 !important; 21 | margin-right: 1rem; 22 | } 23 | 24 | .title { 25 | padding-bottom: 1rem; 26 | } 27 | 28 | .subtitle { 29 | max-width: 22vw; 30 | } 31 | 32 | @import '../node_modules/bulma/bulma.sass'; 33 | -------------------------------------------------------------------------------- /spring/spring-rest-error-handling/src/main/java/dev/mflash/guides/resterror/security/CustomUserConverter.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.resterror.security; 2 | 3 | import dev.mflash.guides.resterror.domain.CustomUser; 4 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 5 | import org.springframework.security.core.userdetails.User; 6 | 7 | import java.util.List; 8 | 9 | public class CustomUserConverter { 10 | 11 | public static User toUser(CustomUser user) { 12 | return new User(user.getEmail(), user.getPassword(), List.of()); 13 | } 14 | 15 | public static UsernamePasswordAuthenticationToken toAuthenticationToken(CustomUser user) { 16 | return new UsernamePasswordAuthenticationToken(user.getEmail(), user.getPassword(), List.of()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-custom-user/src/main/java/com/example/jwt/web/GreetingController.java: -------------------------------------------------------------------------------- 1 | package com.example.jwt.web; 2 | 3 | import org.springframework.security.core.Authentication; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class GreetingController { 9 | 10 | public static final String PUBLIC_ENDPOINT = "/public"; 11 | public static final String PRIVATE_ENDPOINT = "/private"; 12 | 13 | @GetMapping(PUBLIC_ENDPOINT) 14 | public String greetPublic() { 15 | return "Hello, World!"; 16 | } 17 | 18 | @GetMapping(PRIVATE_ENDPOINT) 19 | public String greetPrivate(Authentication authentication) { 20 | return "Hello, " + authentication.getName() + "!"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /spring/springrx-file-upload/web/src/styles.scss: -------------------------------------------------------------------------------- 1 | @charset 'utf-8'; 2 | 3 | $family-sans-serif: Inter, BlinkMacSystemFont, -apple-system, 'Segoe UI', 4 | 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 5 | 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif !default; 6 | 7 | $yellow: #f99a00 !default; 8 | $green: #16bf68 !default; 9 | $turquoise: #37a68c !default; 10 | $blue: #006fd8 !default; 11 | $red: #db2e4d !default; 12 | 13 | .form { 14 | display: flex; 15 | align-items: center; 16 | margin-bottom: 0.5rem; 17 | } 18 | 19 | .file-control { 20 | margin-bottom: 0 !important; 21 | margin-right: 1rem; 22 | } 23 | 24 | .title { 25 | padding-bottom: 1rem; 26 | } 27 | 28 | .subtitle { 29 | max-width: 22vw; 30 | } 31 | 32 | @import '../node_modules/bulma/bulma.sass'; 33 | -------------------------------------------------------------------------------- /@/archives/spring/springboot3-aop-method-logging/src/main/java/com/example/method/logging/annotation/LogEntryExit.java: -------------------------------------------------------------------------------- 1 | package com.example.method.logging.annotation; 2 | 3 | import org.springframework.boot.logging.LogLevel; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | import java.time.temporal.ChronoUnit; 10 | 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target(ElementType.METHOD) 13 | public @interface LogEntryExit { 14 | 15 | LogLevel value() default LogLevel.INFO; 16 | 17 | ChronoUnit unit() default ChronoUnit.SECONDS; 18 | 19 | boolean showArgs() default false; 20 | 21 | boolean showResult() default false; 22 | 23 | boolean showExecutionTime() default true; 24 | } 25 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-ui/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /nodejs/linting-with-typescript-eslint/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "linting-with-typescript-eslint", 3 | "version": "1.0.0", 4 | "main": "dist/server.js", 5 | "scripts": { 6 | "build": "tsc", 7 | "prestart": "npm run build && npm run lint", 8 | "lint": "eslint src/**/* --fix", 9 | "start": "node ." 10 | }, 11 | "dependencies": { 12 | "express": "^4.17.1", 13 | "log4js": "^6.1.2", 14 | "morgan": "^1.9.1", 15 | "rotating-file-stream": "^2.0.2" 16 | }, 17 | "devDependencies": { 18 | "@types/express": "^4.17.3", 19 | "@types/morgan": "^1.9.0", 20 | "@types/node": "^13.9.1", 21 | "@typescript-eslint/eslint-plugin": "^2.24.0", 22 | "@typescript-eslint/parser": "^2.24.0", 23 | "eslint": "^6.8.0", 24 | "typescript": "^3.8.3" 25 | }, 26 | "license": "MIT" 27 | } 28 | -------------------------------------------------------------------------------- /@sample/spring/springboot3-notes-api/sample.http: -------------------------------------------------------------------------------- 1 | # list all notes 2 | curl -s http://localhost:8080/v1/notes 3 | 4 | # list specific notes by id 5 | curl -s http://localhost:8080/v1/notes?id=&id= 6 | 7 | # add new note 8 | curl -s -X PUT http://localhost:8080/v1/notes --json '{"title": "curl`s --json flag","body": "Use `--json` flag to avoid setting content-type and accept headers","createdBy": "@anya","readOnly": false}' 9 | 10 | # upload a note 11 | curl -s http://localhost:8080/v1/notes -F "title=Paste to clipboard on macOS" -F "body=@sample.md;type=text/markdown" --form-string "createdBy=@nare" -F "readOnly=false" 12 | 13 | # patch an existing note 14 | curl -s -X PATCH http://localhost:8080/v1/notes --json '{"readOnly": true,"id": }' 15 | 16 | # delete notes by id 17 | curl -s -X DELETE http://localhost:8080/v1/notes/, 18 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-ui/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { GreetingService } from './greeting.service'; 3 | 4 | @Component({ 5 | selector: 'app-root', 6 | template: ` 7 |
{{ message }}
8 | `, 9 | styles: [ 10 | ` 11 | main { 12 | margin: calc(2rem + 5vw); 13 | font-size: calc(2rem + 4vw); 14 | } 15 | ` 16 | ] 17 | }) 18 | export class AppComponent { 19 | message: string = 'Hello, stranger!'; 20 | 21 | constructor(private greetingService: GreetingService) {} 22 | 23 | ngOnInit(): void { 24 | this.getMessage(); 25 | } 26 | 27 | getMessage() { 28 | this.greetingService.getGreeting() 29 | .subscribe(response => (this.message = response['message'])); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /nodejs/express-postgres-api/src/configuration/environment.ts: -------------------------------------------------------------------------------- 1 | import dotenv from 'dotenv'; 2 | 3 | // fetch .env configuration 4 | dotenv.config(); 5 | 6 | export const environment = { 7 | nodeEnv: process.env.ENV || process.env.NODE_ENV, 8 | logDir: process.env.LOG_DIR || 'logs', 9 | logLevel: process.env.LOG_LEVEL || 'info', 10 | logFile: process.env.LOG_FILE || 'app.log', 11 | pgUser: process.env.PGUSER, 12 | pgHost: process.env.PGHOST, 13 | pgPassword: process.env.PGPASSWORD, 14 | pgDatabase: process.env.PGDATABASE, 15 | pgPort: Number(process.env.PGPORT), 16 | requestLogFile: process.env.MORGAN_LOG || 'requests.log', 17 | requestLogFormat: process.env.MORGAN_LOG_FMT || 'combined', 18 | requestLogRollingInterval: process.env.MORGAN_LOG_ROLLING_INTERVAL || '1d', 19 | serverPort: Number(process.env.SERVER_PORT) || 8080 20 | }; -------------------------------------------------------------------------------- /python/testcontainers-integration-tests-with-pytest/app/dbclient.py: -------------------------------------------------------------------------------- 1 | import atexit 2 | from contextlib import contextmanager 3 | from dataclasses import dataclass 4 | 5 | from psycopg import Connection, connect 6 | 7 | from app.conf import conf 8 | from app.singleton import Singleton 9 | 10 | 11 | @dataclass 12 | class ConnectionContext(metaclass=Singleton): 13 | _connection: Connection | None = None 14 | 15 | def __post_init__(self): 16 | if self._connection is None: 17 | conn = connect(conninfo=conf.db_url, autocommit=True) 18 | object.__setattr__(self, "_connection", conn) 19 | atexit.register(conn.close) 20 | 21 | @contextmanager 22 | def cursor(self): 23 | with self._connection.cursor() as cursor: 24 | yield cursor 25 | 26 | 27 | connection = ConnectionContext() 28 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-eddsa/src/main/java/com/example/jwt/web/UserController.java: -------------------------------------------------------------------------------- 1 | package com.example.jwt.web; 2 | 3 | import com.example.jwt.userdetails.CustomUser; 4 | import com.example.jwt.userdetails.CustomUserDetailsService; 5 | import org.springframework.web.bind.annotation.PostMapping; 6 | import org.springframework.web.bind.annotation.RequestBody; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | @RestController 10 | public record UserController(CustomUserDetailsService customUserDetailsService) { 11 | 12 | public static final String USER_ENDPOINT = "/user"; 13 | 14 | @PostMapping(USER_ENDPOINT) 15 | public String register(@RequestBody CustomUser newUser) { 16 | customUserDetailsService.saveUser(newUser); 17 | return "User '%s' registered successfully".formatted(newUser.username()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-custom-user/src/main/java/com/example/jwt/web/UserController.java: -------------------------------------------------------------------------------- 1 | package com.example.jwt.web; 2 | 3 | import com.example.jwt.userdetails.CustomUser; 4 | import com.example.jwt.userdetails.CustomUserDetailsService; 5 | import org.springframework.web.bind.annotation.PostMapping; 6 | import org.springframework.web.bind.annotation.RequestBody; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | @RestController 10 | public record UserController(CustomUserDetailsService customUserDetailsService) { 11 | 12 | public static final String USER_ENDPOINT = "/user"; 13 | 14 | @PostMapping(USER_ENDPOINT) 15 | public String register(@RequestBody CustomUser newUser) { 16 | customUserDetailsService.saveUser(newUser); 17 | return "User '%s' registered successfully".formatted(newUser.username()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring/springboot3-local-dev-testcontainers/src/test/java/LocalContainerConfiguration.java: -------------------------------------------------------------------------------- 1 | import org.springframework.boot.test.context.TestConfiguration; 2 | import org.springframework.context.annotation.Bean; 3 | import org.springframework.test.context.DynamicPropertyRegistry; 4 | import org.testcontainers.containers.PostgreSQLContainer; 5 | 6 | @TestConfiguration(proxyBeanMethods = false) 7 | public class LocalContainerConfiguration { 8 | 9 | @Bean 10 | public PostgreSQLContainer postgreSQLContainer(DynamicPropertyRegistry props) { 11 | var container = new PostgreSQLContainer<>("postgres:16-alpine"); 12 | props.add("spring.datasource.url", container::getJdbcUrl); 13 | props.add("spring.datasource.username", container::getUsername); 14 | props.add("spring.datasource.password", container::getPassword); 15 | return container; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /spring/springboot3-springdoc-integration/sample.http: -------------------------------------------------------------------------------- 1 | # list all notes 2 | curl -s http://localhost:8080/v1/notes 3 | 4 | # list specific notes by id 5 | curl -s http://localhost:8080/v1/notes?id=&id= 6 | 7 | # add new note 8 | curl -s -X PUT http://localhost:8080/v1/notes --json '{"title": "curl`s --json flag","body": "Use `--json` flag to avoid setting content-type and accept headers","createdBy": "@anya","readOnly": false}' 9 | 10 | # upload a note 11 | curl -s http://localhost:8080/v1/notes -F "title=Paste to clipboard on macOS" -F "body=@sample.md;type=text/markdown" --form-string "createdBy=@nare" -F "readOnly=false" 12 | 13 | # patch an existing note 14 | curl -s -X PATCH http://localhost:8080/v1/notes --json '{"readOnly": true,"id": }' 15 | 16 | # delete notes by id 17 | curl -s -X DELETE http://localhost:8080/v1/notes/, 18 | -------------------------------------------------------------------------------- /@/archives/spring/springboot3-aop-method-logging/src/main/java/com/example/method/logging/Launcher.java: -------------------------------------------------------------------------------- 1 | package com.example.method.logging; 2 | 3 | import org.springframework.boot.CommandLineRunner; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | public class Launcher implements CommandLineRunner { 9 | 10 | private final GreetingService greetingService; 11 | 12 | public Launcher(GreetingService greetingService) { 13 | this.greetingService = greetingService; 14 | } 15 | 16 | public static void main(String... args) { 17 | SpringApplication.run(Launcher.class, args); 18 | } 19 | 20 | @Override 21 | public void run(String... args) throws Exception { 22 | greetingService.greet("Joe"); 23 | greetingService.greet("Jane"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Backstage 2 | 3 | Source code of examples published on [naiyerasif.com](https://www.naiyerasif.com) 4 | 5 | ## Sections 6 | 7 | - [AWS](./aws/) 8 | - [Cloud](./cloud) 9 | - [Java](./java/) 10 | - [Code Coverage with JaCoCo and Maven](./java/jacoco-coverage-with-maven/) 11 | - [Creating deep copies in Java](./java/deep-copying/) 12 | - [Java-based health check for Docker](./java/docker-healthcheck/) 13 | - [Polymorphic Requests with Jackson](./java/jackson3-polymorphic-requests/) 14 | - [Weaving aspects at compile-time with AspectJ](./java/aop-compile-time/) 15 | - [Micronaut](./micronaut) 16 | - [Node.js](./nodejs) 17 | - [Python](./python) 18 | - [Spring](./spring) 19 | - [Logging methods with AspectJ in a Spring application](./spring/springboot4-aop-method-logging/) 20 | - [Miscellaneous](./miscellaneous) 21 | 22 | ## License 23 | 24 | Licensed under [MIT](./LICENSE.md) 25 | -------------------------------------------------------------------------------- /spring/spring-messaging-rabbitmq/src/main/java/dev/mflash/guides/rabbitmq/service/Reader.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.rabbitmq.service; 2 | 3 | import dev.mflash.guides.rabbitmq.configuration.RabbitMQConfiguration; 4 | import dev.mflash.guides.rabbitmq.domain.Book; 5 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | import java.util.concurrent.CountDownLatch; 10 | 11 | public @Service class Reader { 12 | 13 | private CountDownLatch latch = new CountDownLatch(1); 14 | 15 | @RabbitListener(queues = RabbitMQConfiguration.QUEUE_NAME, containerFactory = "listenerContainerFactory") 16 | public void receiveMessage(final List books) { 17 | books.forEach(System.out::println); 18 | latch.countDown(); 19 | } 20 | 21 | public CountDownLatch getLatch() { 22 | return latch; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /@sample/spring/springboot3-notes-api/src/main/java/com/example/notes/adapter/database/Note.java: -------------------------------------------------------------------------------- 1 | package com.example.notes.adapter.database; 2 | 3 | import lombok.Builder; 4 | import org.springframework.data.annotation.Id; 5 | import org.springframework.data.relational.core.mapping.Table; 6 | 7 | import java.time.LocalDateTime; 8 | import java.util.StringTokenizer; 9 | import java.util.UUID; 10 | 11 | @Table("notes") 12 | @Builder 13 | public record Note( 14 | @Id 15 | UUID id, 16 | String title, 17 | String body, 18 | String createdBy, 19 | LocalDateTime createdAt, 20 | String updatedBy, 21 | LocalDateTime updatedAt, 22 | long version, 23 | long wordCount, 24 | boolean readOnly) { 25 | 26 | @Override 27 | public long wordCount() { 28 | return countWords(body); 29 | } 30 | 31 | public static long countWords(String text) { 32 | return new StringTokenizer(text).countTokens(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-ui/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /@sample/spring/springboot3-notes-api/src/main/java/com/example/notes/adapter/web/NoteWebView.java: -------------------------------------------------------------------------------- 1 | package com.example.notes.adapter.web; 2 | 3 | import com.example.notes.adapter.database.Note; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | import lombok.Builder; 6 | 7 | import java.util.UUID; 8 | 9 | @Builder 10 | @JsonIgnoreProperties(ignoreUnknown = true) 11 | public record NoteWebView( 12 | UUID id, 13 | String title, 14 | String body, 15 | String createdBy, 16 | String updatedBy, 17 | long wordCount, 18 | boolean readOnly 19 | ) { 20 | 21 | public static NoteWebView convert(Note note) { 22 | return NoteWebView.builder() 23 | .id(note.id()) 24 | .title(note.title()) 25 | .body(note.body()) 26 | .createdBy(note.createdBy()) 27 | .updatedBy(note.updatedBy()) 28 | .wordCount(note.wordCount()) 29 | .readOnly(note.readOnly()) 30 | .build(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /spring/springboot3-springdoc-integration/src/main/java/com/example/springdoc/adapter/database/Note.java: -------------------------------------------------------------------------------- 1 | package com.example.springdoc.adapter.database; 2 | 3 | import lombok.Builder; 4 | import org.springframework.data.annotation.Id; 5 | import org.springframework.data.relational.core.mapping.Table; 6 | 7 | import java.time.LocalDateTime; 8 | import java.util.StringTokenizer; 9 | import java.util.UUID; 10 | 11 | @Table("notes") 12 | @Builder 13 | public record Note( 14 | @Id 15 | UUID id, 16 | String title, 17 | String body, 18 | String createdBy, 19 | LocalDateTime createdAt, 20 | String updatedBy, 21 | LocalDateTime updatedAt, 22 | long version, 23 | long wordCount, 24 | boolean readOnly) { 25 | 26 | @Override 27 | public long wordCount() { 28 | return countWords(body); 29 | } 30 | 31 | public static long countWords(String text) { 32 | return new StringTokenizer(text).countTokens(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring/springboot3-springdoc-integration/src/main/java/com/example/springdoc/adapter/web/NoteWebView.java: -------------------------------------------------------------------------------- 1 | package com.example.springdoc.adapter.web; 2 | 3 | import com.example.springdoc.adapter.database.Note; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | import lombok.Builder; 6 | 7 | import java.util.UUID; 8 | 9 | @Builder 10 | @JsonIgnoreProperties(ignoreUnknown = true) 11 | public record NoteWebView( 12 | UUID id, 13 | String title, 14 | String body, 15 | String createdBy, 16 | String updatedBy, 17 | long wordCount, 18 | boolean readOnly 19 | ) { 20 | 21 | public static NoteWebView convert(Note note) { 22 | return NoteWebView.builder() 23 | .id(note.id()) 24 | .title(note.title()) 25 | .body(note.body()) 26 | .createdBy(note.createdBy()) 27 | .updatedBy(note.updatedBy()) 28 | .wordCount(note.wordCount()) 29 | .readOnly(note.readOnly()) 30 | .build(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /@sample/spring/springboot3-notes-api/src/main/java/com/example/notes/adapter/web/NoteFileView.java: -------------------------------------------------------------------------------- 1 | package com.example.notes.adapter.web; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import org.springframework.web.multipart.MultipartFile; 5 | 6 | import java.io.IOException; 7 | import java.nio.charset.StandardCharsets; 8 | import java.util.Objects; 9 | 10 | @JsonIgnoreProperties(ignoreUnknown = true) 11 | public record NoteFileView(String title, MultipartFile body, String createdBy, boolean readOnly) { 12 | 13 | public NoteFileView { 14 | if (!Objects.requireNonNull(body.getContentType()).equals("text/markdown")) { 15 | throw new RuntimeException("Illegal file format"); 16 | } 17 | } 18 | 19 | public String content() { 20 | try { 21 | return new String(body.getBytes(), StandardCharsets.UTF_8); 22 | } catch (IOException e) { 23 | throw new RuntimeException("Failed to read file", e); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring/spring-file-upload/web/src/app/upload.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient, HttpEvent, HttpRequest, HttpResponse } from '@angular/common/http'; 3 | import { Observable } from 'rxjs'; 4 | import { environment } from '../environments/environment'; 5 | 6 | @Injectable({ 7 | providedIn: 'root' 8 | }) 9 | export class UploadService { 10 | constructor(private client: HttpClient) {} 11 | 12 | getUploadedFiles() { 13 | return this.client.get(environment.apiUrl); 14 | } 15 | 16 | upload(data: FileList): Observable> { 17 | const formData = new FormData(); 18 | 19 | Array.from(data).forEach(file => { 20 | formData.append('data', file); 21 | }); 22 | 23 | const request = new HttpRequest('POST', environment.apiUrl, formData, { 24 | reportProgress: true, 25 | responseType: 'text' 26 | }); 27 | 28 | return this.client.request(request); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring/springrx-file-upload/web/src/app/upload.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient, HttpEvent, HttpRequest, HttpResponse } from '@angular/common/http'; 3 | import { Observable } from 'rxjs'; 4 | import { environment } from '../environments/environment'; 5 | 6 | @Injectable({ 7 | providedIn: 'root' 8 | }) 9 | export class UploadService { 10 | constructor(private client: HttpClient) {} 11 | 12 | getUploadedFiles() { 13 | return this.client.get(environment.apiUrl); 14 | } 15 | 16 | upload(data: FileList): Observable> { 17 | const formData = new FormData(); 18 | 19 | Array.from(data).forEach(file => { 20 | formData.append('data', file); 21 | }); 22 | 23 | const request = new HttpRequest('POST', environment.apiUrl, formData, { 24 | reportProgress: true, 25 | responseType: 'text' 26 | }); 27 | 28 | return this.client.request(request); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring/springboot3-springdoc-integration/src/main/java/com/example/springdoc/adapter/web/NoteFileView.java: -------------------------------------------------------------------------------- 1 | package com.example.springdoc.adapter.web; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import org.springframework.web.multipart.MultipartFile; 5 | 6 | import java.io.IOException; 7 | import java.nio.charset.StandardCharsets; 8 | import java.util.Objects; 9 | 10 | @JsonIgnoreProperties(ignoreUnknown = true) 11 | public record NoteFileView(String title, MultipartFile body, String createdBy, boolean readOnly) { 12 | 13 | public NoteFileView { 14 | if (!Objects.requireNonNull(body.getContentType()).equals("text/markdown")) { 15 | throw new RuntimeException("Illegal file format"); 16 | } 17 | } 18 | 19 | public String content() { 20 | try { 21 | return new String(body.getBytes(), StandardCharsets.UTF_8); 22 | } catch (IOException e) { 23 | throw new RuntimeException("Failed to read file", e); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /java/jacoco-coverage-with-maven/src/main/java/com/example/Factorial.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.Optional; 5 | import java.util.stream.LongStream; 6 | 7 | interface Factorial { 8 | 9 | static long getFactorialViaLoop(final int num) { 10 | int factorial = num == 0 ? 1 : num; 11 | for (int i = num - 1; i > 1; i--) { 12 | factorial *= i; 13 | } 14 | return factorial; 15 | } 16 | 17 | static long getFactorialViaRecursion(final int num) { 18 | if (num == 1 || num == 0) { 19 | return 1; 20 | } 21 | return num * getFactorialViaRecursion(num - 1); 22 | } 23 | 24 | static long getFactorialFunctionally(final int num) { 25 | return LongStream.rangeClosed(2, num).reduce(1, Math::multiplyExact); 26 | } 27 | 28 | static Optional getFactorial(final int num) { 29 | return LongStream.rangeClosed(2, num).parallel().mapToObj(BigDecimal::new) 30 | .reduce(BigDecimal::multiply); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /nodejs/express-postgres-api/src/helper/request.logger.ts: -------------------------------------------------------------------------------- 1 | import { Application } from 'express'; 2 | import morgan from 'morgan'; 3 | import { createStream } from 'rotating-file-stream'; 4 | import { environment } from '../configuration/environment'; 5 | 6 | // rotating stream for morgan 7 | const accessLogStream = createStream(environment.requestLogFile, { 8 | interval: environment.requestLogRollingInterval, 9 | path: environment.logDir 10 | }); 11 | 12 | // appenders for printing the logs to console and file 13 | const consoleAppender = morgan(environment.requestLogFormat); 14 | const fileAppender = morgan(environment.requestLogFormat, { 15 | stream: accessLogStream 16 | }); 17 | 18 | // function to inject morgan in an express app 19 | export const registerRequestLogger = (app: Application) => { 20 | app.use(consoleAppender); 21 | 22 | // log to file only in `production` 23 | if (environment.nodeEnv === 'production') { 24 | app.use(fileAppender); 25 | } 26 | }; -------------------------------------------------------------------------------- /nodejs/logging-with-winston/src/helper/request.logger.ts: -------------------------------------------------------------------------------- 1 | import { Application } from 'express'; 2 | import morgan from 'morgan'; 3 | import { createStream } from 'rotating-file-stream'; 4 | import { environment } from '../configuration/environment'; 5 | 6 | // rotating stream for morgan 7 | const accessLogStream = createStream(environment.requestLogFile, { 8 | interval: environment.requestLogRollingInterval, 9 | path: environment.logDir 10 | }); 11 | 12 | // appenders for printing the logs to console and file 13 | const consoleAppender = morgan(environment.requestLogFormat); 14 | const fileAppender = morgan(environment.requestLogFormat, { 15 | stream: accessLogStream 16 | }); 17 | 18 | // function to inject morgan in an express app 19 | export const registerRequestLogger = (app: Application) => { 20 | app.use(consoleAppender); 21 | 22 | // log to file only in `production` 23 | if (environment.nodeEnv === 'production') { 24 | app.use(fileAppender); 25 | } 26 | } -------------------------------------------------------------------------------- /nodejs/morgan-request-logging/src/helper/request.logger.ts: -------------------------------------------------------------------------------- 1 | import { Application } from 'express'; 2 | import morgan from 'morgan'; 3 | import { createStream } from 'rotating-file-stream'; 4 | import { environment } from '../configuration/environment'; 5 | 6 | // rotating stream for morgan 7 | const accessLogStream = createStream(environment.requestLogFile, { 8 | interval: environment.requestLogRollingInterval, 9 | path: environment.logDir 10 | }); 11 | 12 | // appenders for printing the logs to console and file 13 | const consoleAppender = morgan(environment.requestLogFormat); 14 | const fileAppender = morgan(environment.requestLogFormat, { 15 | stream: accessLogStream 16 | }); 17 | 18 | // function to inject morgan in an express app 19 | export const registerRequestLogger = (app: Application) => { 20 | app.use(consoleAppender); 21 | 22 | // log to file only in `production` 23 | if (environment.nodeEnv === 'production') { 24 | app.use(fileAppender); 25 | } 26 | } -------------------------------------------------------------------------------- /nodejs/logging-with-log4js-node/src/helper/request.logger.ts: -------------------------------------------------------------------------------- 1 | import { Application } from 'express'; 2 | import morgan from 'morgan'; 3 | import { createStream } from 'rotating-file-stream'; 4 | import { environment } from '../configuration/environment'; 5 | 6 | // rotating stream for morgan 7 | const accessLogStream = createStream(environment.requestLogFile, { 8 | interval: environment.requestLogRollingInterval, 9 | path: environment.logDir 10 | }); 11 | 12 | // appenders for printing the logs to console and file 13 | const consoleAppender = morgan(environment.requestLogFormat); 14 | const fileAppender = morgan(environment.requestLogFormat, { 15 | stream: accessLogStream 16 | }); 17 | 18 | // function to inject morgan in an express app 19 | export const registerRequestLogger = (app: Application) => { 20 | app.use(consoleAppender); 21 | 22 | // log to file only in `production` 23 | if (environment.nodeEnv === 'production') { 24 | app.use(fileAppender); 25 | } 26 | } -------------------------------------------------------------------------------- /nodejs/linting-with-typescript-eslint/src/helper/request.logger.ts: -------------------------------------------------------------------------------- 1 | import { Application } from 'express'; 2 | import morgan from 'morgan'; 3 | import { createStream } from 'rotating-file-stream'; 4 | import { environment } from '../configuration/environment'; 5 | 6 | // rotating stream for morgan 7 | const accessLogStream = createStream(environment.requestLogFile, { 8 | interval: environment.requestLogRollingInterval, 9 | path: environment.logDir 10 | }); 11 | 12 | // appenders for printing the logs to console and file 13 | const consoleAppender = morgan(environment.requestLogFormat); 14 | const fileAppender = morgan(environment.requestLogFormat, { 15 | stream: accessLogStream 16 | }); 17 | 18 | // function to inject morgan in an express app 19 | export const registerRequestLogger = (app: Application) => { 20 | app.use(consoleAppender); 21 | 22 | // log to file only in `production` 23 | if (environment.nodeEnv === 'production') { 24 | app.use(fileAppender); 25 | } 26 | }; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # aws 2 | .aws/ 3 | 4 | # build and output directories 5 | build/ 6 | dist/ 7 | target/ 8 | out/ 9 | .astro/ 10 | *.class 11 | *.jar 12 | *.war 13 | *.ear 14 | 15 | # dependency directories 16 | node_modules/ 17 | .venv/ 18 | venv/ 19 | __pycache__/ 20 | 21 | # eclipse 22 | .apt_generated/ 23 | .classpath/ 24 | .factorypath/ 25 | .project/ 26 | .settings/ 27 | .springBeans/ 28 | .sts4-cache/ 29 | 30 | # java 31 | .gradle/ 32 | .mvn/ 33 | .settings/ 34 | .classpath 35 | .project 36 | 37 | # jetbrains 38 | .idea/ 39 | *.iml 40 | *.ipr 41 | *.iws 42 | 43 | # logs and temp directories 44 | logs/ 45 | *.log 46 | *.tmp 47 | *.swp 48 | 49 | # netbeans 50 | nbproject/private/ 51 | nbbuild/ 52 | nbdist/ 53 | .nb-gradle/ 54 | 55 | # os-specific 56 | .DS_Store 57 | Thumbs.db 58 | 59 | # spring 60 | HELP.md 61 | 62 | # sublimetext 63 | *.sublime-workspace 64 | *.sublime-project 65 | 66 | # vscode 67 | .vscode/ 68 | 69 | # workspace 70 | .workspace 71 | 72 | # zed 73 | .ropeproject/ 74 | .zed/ 75 | -------------------------------------------------------------------------------- /aws/localstack-with-aws-cli/apod.json: -------------------------------------------------------------------------------- 1 | { 2 | "copyright": "Panther Observatory", 3 | "date": "2006-04-15", 4 | "explanation": "In this stunning cosmic vista, galaxy M81 is on the left surrounded by blue spiral arms. On the right marked by massive gas and dust clouds, is M82. These two mammoth galaxies have been locked in gravitational combat for the past billion years. The gravity from each galaxy dramatically affects the other during each hundred million-year pass. Last go-round, M82's gravity likely raised density waves rippling around M81, resulting in the richness of M81's spiral arms. But M81 left M82 with violent star forming regions and colliding gas clouds so energetic the galaxy glows in X-rays. In a few billion years only one galaxy will remain.", 5 | "hdurl": "https://apod.nasa.gov/apod/image/0604/M81_M82_schedler_c80.jpg", 6 | "media_type": "image", 7 | "service_version": "v1", 8 | "title": "Galaxy Wars: M81 versus M82", 9 | "url": "https://apod.nasa.gov/apod/image/0604/M81_M82_schedler_c25.jpg" 10 | } 11 | -------------------------------------------------------------------------------- /spring/spring-data-micronaut-data/src/main/java/dev/mflash/guides/customer/Customer.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.customer; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | 8 | public @Entity class Customer { 9 | 10 | @GeneratedValue(strategy = GenerationType.IDENTITY) 11 | private @Id long customerId; 12 | private String firstName; 13 | private String lastName; 14 | 15 | public long getCustomerId() { 16 | return customerId; 17 | } 18 | 19 | public void setCustomerId(long customerId) { 20 | this.customerId = customerId; 21 | } 22 | 23 | public String getFirstName() { 24 | return firstName; 25 | } 26 | 27 | public void setFirstName(String firstName) { 28 | this.firstName = firstName; 29 | } 30 | 31 | public String getLastName() { 32 | return lastName; 33 | } 34 | 35 | public void setLastName(String lastName) { 36 | this.lastName = lastName; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /java/jacoco-coverage-with-maven/src/main/java/com/example/Fibonacci.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import java.math.BigInteger; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.stream.Stream; 7 | 8 | interface Fibonacci { 9 | 10 | static List fibonacciViaLoop(int limit) { 11 | var prev = 0; 12 | var curr = 1; 13 | int temp; 14 | var list = new ArrayList(); 15 | for (var i = 1; i <= limit; i++) { 16 | temp = curr; 17 | curr = prev + curr; 18 | prev = temp; 19 | list.add(prev); 20 | } 21 | return list; 22 | } 23 | 24 | record Pair(BigInteger previous, BigInteger current) { 25 | } 26 | 27 | static Stream fibonacciViaStream(int limit) { 28 | return Stream.iterate(new Pair(BigInteger.ONE, BigInteger.ONE), 29 | e -> new Pair(e.current, e.previous.add(e.current))).limit(limit); 30 | } 31 | 32 | static int recursiveFibonacci(int num) { 33 | if (num < 3) { 34 | return 1; 35 | } 36 | return recursiveFibonacci(num - 2) + recursiveFibonacci(num - 1); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /spring/spring-data-mongo-repository/src/main/java/dev/mflash/guides/mongo/configuration/MongoConfiguration.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.mongo.configuration; 2 | 3 | import dev.mflash.guides.mongo.event.AccountCascadeMongoEventListener; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.data.mongodb.core.convert.MongoCustomConversions; 7 | import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; 8 | 9 | @EnableMongoRepositories(MongoConfiguration.REPOSITORY_PACKAGE) 10 | public @Configuration class MongoConfiguration { 11 | 12 | static final String REPOSITORY_PACKAGE = "dev.mflash.guides.mongo.repository"; 13 | 14 | public @Bean AccountCascadeMongoEventListener cascadeMongoEventListener() { 15 | return new AccountCascadeMongoEventListener(); 16 | } 17 | 18 | public @Bean MongoCustomConversions customConversions() { 19 | return new MongoCustomConversions(ZonedDateTimeConverters.getConvertersToRegister()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /cloud/communicating-with-containers-on-docker-network/prerequisites/greeter-ui/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "greeter-ui", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build --prod" 8 | }, 9 | "private": true, 10 | "dependencies": { 11 | "@angular/animations": "~9.0.1", 12 | "@angular/common": "~9.0.1", 13 | "@angular/compiler": "~9.0.1", 14 | "@angular/core": "~9.0.1", 15 | "@angular/forms": "~9.0.1", 16 | "@angular/platform-browser": "~9.0.1", 17 | "@angular/platform-browser-dynamic": "~9.0.1", 18 | "@angular/router": "~9.0.1", 19 | "rxjs": "~6.5.4", 20 | "tslib": "^1.10.0", 21 | "zone.js": "~0.10.2" 22 | }, 23 | "devDependencies": { 24 | "@angular-devkit/build-angular": "~0.900.2", 25 | "@angular/cli": "~9.0.2", 26 | "@angular/compiler-cli": "~9.0.1", 27 | "@angular/language-service": "~9.0.1", 28 | "@types/node": "^12.11.1", 29 | "ts-node": "~8.3.0", 30 | "tslint": "~5.18.0", 31 | "typescript": "~3.7.5" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring/spring-file-upload/web/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "uploader", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build" 8 | }, 9 | "private": true, 10 | "dependencies": { 11 | "@angular/animations": "~9.0.6", 12 | "@angular/common": "~9.0.6", 13 | "@angular/compiler": "~9.0.6", 14 | "@angular/core": "~9.0.6", 15 | "@angular/forms": "~9.0.6", 16 | "@angular/platform-browser": "~9.0.6", 17 | "@angular/platform-browser-dynamic": "~9.0.6", 18 | "@angular/router": "~9.0.6", 19 | "bulma": "^0.8.0", 20 | "rxjs": "~6.5.4", 21 | "tslib": "^1.10.0", 22 | "typeface-inter": "^3.12.0", 23 | "zone.js": "~0.10.2" 24 | }, 25 | "devDependencies": { 26 | "@angular-devkit/build-angular": "~0.900.6", 27 | "@angular/cli": "~9.0.6", 28 | "@angular/compiler-cli": "~9.0.6", 29 | "@angular/language-service": "~9.0.6", 30 | "@types/node": "^12.11.1", 31 | "ts-node": "~8.3.0", 32 | "tslint": "~5.18.0", 33 | "typescript": "~3.7.5" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring/springrx-file-upload/web/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "uploader", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build" 8 | }, 9 | "private": true, 10 | "dependencies": { 11 | "@angular/animations": "~9.0.6", 12 | "@angular/common": "~9.0.6", 13 | "@angular/compiler": "~9.0.6", 14 | "@angular/core": "~9.0.6", 15 | "@angular/forms": "~9.0.6", 16 | "@angular/platform-browser": "~9.0.6", 17 | "@angular/platform-browser-dynamic": "~9.0.6", 18 | "@angular/router": "~9.0.6", 19 | "bulma": "^0.8.0", 20 | "rxjs": "~6.5.4", 21 | "tslib": "^1.10.0", 22 | "typeface-inter": "^3.12.0", 23 | "zone.js": "~0.10.2" 24 | }, 25 | "devDependencies": { 26 | "@angular-devkit/build-angular": "~0.900.6", 27 | "@angular/cli": "~9.0.6", 28 | "@angular/compiler-cli": "~9.0.6", 29 | "@angular/language-service": "~9.0.6", 30 | "@types/node": "^12.11.1", 31 | "ts-node": "~8.3.0", 32 | "tslint": "~5.18.0", 33 | "typescript": "~3.7.5" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /@archive/spring/springboot2-springdoc-webmvc-integration/src/main/java/dev/mflash/guides/springdoc/Launcher.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.springdoc; 2 | 3 | import io.swagger.v3.oas.models.OpenAPI; 4 | import io.swagger.v3.oas.models.info.Info; 5 | import io.swagger.v3.oas.models.info.License; 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.context.annotation.Bean; 9 | 10 | public @SpringBootApplication class Launcher { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(Launcher.class, args); 14 | } 15 | 16 | public @Bean OpenAPI noteAPI() { 17 | return new OpenAPI() 18 | .info( 19 | new Info() 20 | .title("Note API") 21 | .description("A CRUD API to demonstrate Springdoc integration") 22 | .version("0.0.1-SNAPSHOT") 23 | .license( 24 | new License().name("MIT").url("https://opensource.org/licenses/MIT") 25 | ) 26 | ); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring/spring-data-mongo-repository/src/main/java/dev/mflash/guides/mongo/configuration/ZonedDateTimeConverters.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.mongo.configuration; 2 | 3 | import org.springframework.core.convert.converter.Converter; 4 | 5 | import java.time.ZoneOffset; 6 | import java.time.ZonedDateTime; 7 | import java.util.Date; 8 | import java.util.List; 9 | 10 | public class ZonedDateTimeConverters { 11 | 12 | public static List> getConvertersToRegister() { 13 | return List.of(ZonedDateTimeToDateConverter.INSTANCE, DateToZonedDateTimeConverter.INSTANCE); 14 | } 15 | 16 | private enum ZonedDateTimeToDateConverter implements Converter { 17 | INSTANCE; 18 | 19 | public @Override Date convert(ZonedDateTime source) { 20 | return Date.from(source.toInstant()); 21 | } 22 | } 23 | 24 | private enum DateToZonedDateTimeConverter implements Converter { 25 | INSTANCE; 26 | 27 | public @Override ZonedDateTime convert(Date source) { 28 | return source.toInstant().atZone(ZoneOffset.UTC); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /java/aop-compile-time/src/test/java/com/example/aop/GreetingHandlerTest.java: -------------------------------------------------------------------------------- 1 | package com.example.aop; 2 | 3 | import org.junit.jupiter.api.BeforeEach; 4 | import org.junit.jupiter.api.DisplayName; 5 | import org.junit.jupiter.params.ParameterizedTest; 6 | import org.junit.jupiter.params.provider.Arguments; 7 | import org.junit.jupiter.params.provider.MethodSource; 8 | 9 | import java.util.stream.Stream; 10 | 11 | import static org.assertj.core.api.Assertions.assertThat; 12 | 13 | class GreetingHandlerTest { 14 | 15 | private GreetingHandler greetingHandler; 16 | 17 | @BeforeEach 18 | void setUp() { 19 | greetingHandler = new GreetingHandler(); 20 | } 21 | 22 | @ParameterizedTest 23 | @MethodSource 24 | @DisplayName("Should return greeting") 25 | void shouldReturnGreeting(String name, String expectedGreeting) { 26 | assertThat(greetingHandler.greet(name)).isEqualTo(expectedGreeting); 27 | } 28 | 29 | private static Stream shouldReturnGreeting() { 30 | return Stream.of( 31 | Arguments.of("Veronica", "Hello, Veronica!"), 32 | Arguments.of("", "Hello, world!") 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /miscellaneous/webfont-subsetting/mixin.scss: -------------------------------------------------------------------------------- 1 | @mixin font-face($font-family, $file-path, $font-style, $font-weight, $unicode-range) { 2 | @font-face { 3 | font-family: $font-family; 4 | font-display: swap; 5 | src: url("#{$file-path}.woff2") format("woff2"); 6 | font-style: $font-style; 7 | font-weight: $font-weight; 8 | unicode-range: #{$unicode-range}; 9 | @content; 10 | } 11 | } 12 | 13 | $subsets: ( 14 | "latin": "U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD", 15 | "latin-ext": "U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF", 16 | "greek": "U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF, U+1F00-1FFF" 17 | ); 18 | 19 | @mixin subsetter($font-family, $file-path, $font-style, $font-weight) { 20 | @each $subset, $unicode-range in $subsets { 21 | @include font-face($font-family, "#{$file-path}.#{$subset}", $font-style, $font-weight, $unicode-range); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring/springboot3-aop-retry-on-failure/src/main/java/com/example/retry/annotation/RetryOnFailure.java: -------------------------------------------------------------------------------- 1 | package com.example.retry.annotation; 2 | 3 | import io.github.resilience4j.core.IntervalFunction; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | import java.time.temporal.ChronoUnit; 10 | 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target(ElementType.METHOD) 13 | public @interface RetryOnFailure { 14 | 15 | int attempts() default 3; 16 | 17 | BackoffStrategy strategy() default BackoffStrategy.EXPONENTIAL_RANDOM; 18 | 19 | long interval() default IntervalFunction.DEFAULT_INITIAL_INTERVAL; 20 | 21 | ChronoUnit unit() default ChronoUnit.MILLIS; 22 | 23 | double randomizationFactor() default IntervalFunction.DEFAULT_RANDOMIZATION_FACTOR; 24 | 25 | double multiplier() default IntervalFunction.DEFAULT_MULTIPLIER; 26 | 27 | Class[] retryExceptions() default {Throwable.class}; 28 | 29 | Class[] ignoreExceptions() default {}; 30 | } 31 | -------------------------------------------------------------------------------- /spring/spring-security-jwt-auth-eddsa/src/main/java/com/example/jwt/EdDSAKeyReader.java: -------------------------------------------------------------------------------- 1 | package com.example.jwt; 2 | 3 | import java.security.KeyFactory; 4 | import java.security.NoSuchAlgorithmException; 5 | import java.security.interfaces.EdECPrivateKey; 6 | import java.security.interfaces.EdECPublicKey; 7 | import java.security.spec.InvalidKeySpecException; 8 | 9 | public class EdDSAKeyReader { 10 | 11 | static final PEMDecoder PEM_DECODER; 12 | 13 | static { 14 | try { 15 | PEM_DECODER = PEMDecoder.withFactory(KeyFactory.getInstance("Ed25519")); 16 | } catch (NoSuchAlgorithmException e) { 17 | throw new RuntimeException(e); 18 | } 19 | } 20 | 21 | public static EdECPublicKey publicKey(String pem) { 22 | try { 23 | return PEM_DECODER.decode(pem, EdECPublicKey.class); 24 | } catch (InvalidKeySpecException e) { 25 | throw new RuntimeException(e); 26 | } 27 | } 28 | 29 | public static EdECPrivateKey privateKey(String pem) { 30 | try { 31 | return PEM_DECODER.decode(pem, EdECPrivateKey.class); 32 | } catch (InvalidKeySpecException e) { 33 | throw new RuntimeException(e); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /@archive/spring/springboot2-aop-retry-on-failure/src/main/java/dev/mflash/guides/retry/annotation/RetryOnFailure.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.retry.annotation; 2 | 3 | import io.github.resilience4j.core.IntervalFunction; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | import java.time.temporal.ChronoUnit; 10 | 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target(ElementType.METHOD) 13 | public @interface RetryOnFailure { 14 | 15 | int attempts() default 3; 16 | 17 | BackoffStrategy strategy() default BackoffStrategy.EXPONENTIAL_RANDOM; 18 | 19 | long interval() default IntervalFunction.DEFAULT_INITIAL_INTERVAL; 20 | 21 | ChronoUnit unit() default ChronoUnit.MILLIS; 22 | 23 | double randomizationFactor() default IntervalFunction.DEFAULT_RANDOMIZATION_FACTOR; 24 | 25 | double multiplier() default IntervalFunction.DEFAULT_MULTIPLIER; 26 | 27 | Class[] retryExceptions() default { Throwable.class }; 28 | 29 | Class[] ignoreExceptions() default { }; 30 | } 31 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright © 2015—present Naiyer Asif 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /spring/spring-file-upload/web/README.md: -------------------------------------------------------------------------------- 1 | # Web 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.0.6. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 28 | -------------------------------------------------------------------------------- /nodejs/express-postgres-api/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "express-postgres-api", 3 | "version": "1.0.0", 4 | "main": "dist/server.js", 5 | "scripts": { 6 | "build": "npm-run-all build:*", 7 | "build:clean": "shx rm -rf dist", 8 | "build:lint": "eslint src/**/* --fix", 9 | "build:compile": "tsc", 10 | "watch": "nodemon --watch src -e ts --exec npm run serve", 11 | "serve": "npm-run-all build start", 12 | "start": "node ." 13 | }, 14 | "dependencies": { 15 | "body-parser": "^1.19.0", 16 | "dotenv": "^8.2.0", 17 | "express": "^4.17.1", 18 | "log4js": "^6.1.2", 19 | "morgan": "^1.9.1", 20 | "pg": "^7.18.2", 21 | "rotating-file-stream": "^2.0.2" 22 | }, 23 | "devDependencies": { 24 | "@types/express": "^4.17.3", 25 | "@types/morgan": "^1.9.0", 26 | "@types/node": "^13.9.1", 27 | "@types/pg": "^7.14.3", 28 | "@typescript-eslint/eslint-plugin": "^2.24.0", 29 | "@typescript-eslint/parser": "^2.24.0", 30 | "eslint": "^6.8.0", 31 | "nodemon": "^2.0.2", 32 | "npm-run-all": "^4.1.5", 33 | "shx": "^0.3.2", 34 | "typescript": "^3.8.3" 35 | }, 36 | "license": "MIT" 37 | } 38 | -------------------------------------------------------------------------------- /spring/spring-security-token-validation-hybrid/src/main/java/dev/mflash/guides/tokenval/hybrid/security/CustomTokenValidator.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.tokenval.hybrid.security; 2 | 3 | import org.springframework.security.oauth2.core.OAuth2Error; 4 | import org.springframework.security.oauth2.core.OAuth2TokenValidator; 5 | import org.springframework.security.oauth2.core.OAuth2TokenValidatorResult; 6 | import org.springframework.security.oauth2.jwt.Jwt; 7 | 8 | public class CustomTokenValidator implements OAuth2TokenValidator { 9 | 10 | private static final OAuth2Error MISSING_AUDIENCE_ERROR = new OAuth2Error("invalid_token", 11 | "The required audience is missing", null); 12 | 13 | private final String audience; 14 | 15 | public CustomTokenValidator(String resource) { 16 | this.audience = resource; 17 | } 18 | 19 | public @Override OAuth2TokenValidatorResult validate(Jwt jwt) { 20 | boolean hasAudience = jwt.getAudience().contains(audience); 21 | 22 | if (hasAudience) { 23 | return OAuth2TokenValidatorResult.success(); 24 | } 25 | 26 | return OAuth2TokenValidatorResult.failure(MISSING_AUDIENCE_ERROR); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring/spring-security-token-validation-local/src/main/java/dev/mflash/guides/tokenval/local/security/CustomTokenValidator.java: -------------------------------------------------------------------------------- 1 | package dev.mflash.guides.tokenval.local.security; 2 | 3 | import org.springframework.security.oauth2.core.OAuth2Error; 4 | import org.springframework.security.oauth2.core.OAuth2TokenValidator; 5 | import org.springframework.security.oauth2.core.OAuth2TokenValidatorResult; 6 | import org.springframework.security.oauth2.jwt.Jwt; 7 | 8 | public class CustomTokenValidator implements OAuth2TokenValidator { 9 | 10 | private static final OAuth2Error MISSING_AUDIENCE_ERROR = new OAuth2Error("invalid_token", 11 | "The required audience is missing", null); 12 | 13 | private final String audience; 14 | 15 | public CustomTokenValidator(String resource) { 16 | this.audience = resource; 17 | } 18 | 19 | public @Override OAuth2TokenValidatorResult validate(Jwt jwt) { 20 | boolean hasAudience = jwt.getAudience().contains(audience); 21 | 22 | if (hasAudience) { 23 | return OAuth2TokenValidatorResult.success(); 24 | } 25 | 26 | return OAuth2TokenValidatorResult.failure(MISSING_AUDIENCE_ERROR); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /@archive/miscellaneous/ory-hydra-1--client-credentials-flow/quickstart.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | 3 | services: 4 | 5 | hydra: 6 | image: oryd/hydra:v1.11.9 7 | ports: 8 | - "4444:4444" # Public port 9 | - "4445:4445" # Admin port 10 | - "5555:5555" # Port for hydra token user 11 | command: serve all --dangerous-force-http 12 | environment: 13 | - DSN=postgres://hydra:secret@postgresd:5432/hydra?sslmode=disable&max_conns=20&max_idle_conns=4 14 | restart: unless-stopped 15 | depends_on: 16 | - hydra-migrate 17 | networks: 18 | - hydranet 19 | 20 | hydra-migrate: 21 | image: oryd/hydra:v1.11.9 22 | environment: 23 | - DSN=postgres://hydra:secret@postgresd:5432/hydra?sslmode=disable&max_conns=20&max_idle_conns=4 24 | command: migrate sql -e --yes 25 | restart: on-failure 26 | networks: 27 | - hydranet 28 | 29 | postgresd: 30 | image: postgres:9.6 31 | ports: 32 | - "5432:5432" 33 | environment: 34 | - POSTGRES_USER=hydra 35 | - POSTGRES_PASSWORD=secret 36 | - POSTGRES_DB=hydra 37 | networks: 38 | - hydranet 39 | 40 | networks: 41 | hydranet: 42 | --------------------------------------------------------------------------------