├── .gitignore ├── k8s └── machine-ip │ ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── in │ │ │ └── kuros │ │ │ └── k8s │ │ │ └── machineip │ │ │ ├── MachineIpApplication.java │ │ │ └── rest │ │ │ └── IpController.java │ └── test │ │ └── java │ │ └── in │ │ └── kuros │ │ └── k8s │ │ └── machineip │ │ └── MachineIpApplicationTests.java │ ├── Dockerfile │ ├── client.sh │ ├── Service.yaml │ ├── .gitignore │ ├── Deployment.yaml │ └── pom.xml ├── nestjs ├── nest-auth │ ├── src │ │ ├── users │ │ │ ├── dto │ │ │ │ ├── create-user.dto.ts │ │ │ │ └── update-user.dto.ts │ │ │ ├── entities │ │ │ │ ├── role.enum.ts │ │ │ │ └── user.entity.ts │ │ │ ├── roles.decorator.ts │ │ │ ├── users.module.ts │ │ │ ├── users.service.spec.ts │ │ │ ├── users.controller.spec.ts │ │ │ ├── users.service.ts │ │ │ ├── roles.guard.ts │ │ │ └── users.controller.ts │ │ ├── app.service.ts │ │ ├── main.ts │ │ ├── app.controller.ts │ │ ├── app.module.ts │ │ └── app.controller.spec.ts │ ├── nest-cli.json │ ├── tsconfig.build.json │ ├── test │ │ ├── jest-e2e.json │ │ └── app.e2e-spec.ts │ ├── tsconfig.json │ └── package.json ├── gcp-storage │ ├── .prettierrc │ ├── nest-cli.json │ ├── src │ │ ├── media │ │ │ ├── file-upload-dto.ts │ │ │ ├── media.module.ts │ │ │ ├── media.controller.spec.ts │ │ │ └── media.controller.ts │ │ ├── storage │ │ │ ├── storage-file.ts │ │ │ ├── storage.module.ts │ │ │ ├── storage-config.ts │ │ │ └── storage.service.ts │ │ ├── app.service.ts │ │ ├── main.ts │ │ ├── app.controller.ts │ │ ├── app.module.ts │ │ └── app.controller.spec.ts │ ├── tsconfig.build.json │ ├── .env │ ├── test │ │ ├── jest-e2e.json │ │ └── app.e2e-spec.ts │ ├── .gitignore │ ├── tsconfig.json │ ├── .eslintrc.js │ ├── package.json │ └── README.md └── nestjs-mongo │ ├── nest-cli.json │ ├── src │ ├── users │ │ ├── dto │ │ │ ├── create-user.dto.ts │ │ │ └── update-user.dto.ts │ │ ├── schemas │ │ │ └── user.schema.ts │ │ ├── users.module.ts │ │ ├── users.repository.ts │ │ ├── users.service.ts │ │ └── users.controller.ts │ ├── app.service.ts │ ├── main.ts │ ├── app.controller.ts │ ├── app.module.ts │ └── app.controller.spec.ts │ ├── tsconfig.build.json │ ├── test │ ├── jest-e2e.json │ └── app.e2e-spec.ts │ ├── tsconfig.json │ ├── .gitignore │ ├── package.json │ └── README.md ├── react ├── first-app │ ├── src │ │ ├── react-app-env.d.ts │ │ ├── components │ │ │ ├── common │ │ │ │ ├── Header.css │ │ │ │ └── Header.tsx │ │ │ ├── book │ │ │ │ └── BookPage.tsx │ │ │ ├── about │ │ │ │ └── AboutPage.tsx │ │ │ └── home │ │ │ │ └── HomePage.tsx │ │ ├── NotFoundPage.tsx │ │ ├── App.test.tsx │ │ ├── index.css │ │ ├── index.tsx │ │ ├── App.css │ │ ├── App.tsx │ │ ├── logo.svg │ │ └── serviceWorker.ts │ ├── public │ │ ├── favicon.ico │ │ ├── manifest.json │ │ └── index.html │ ├── .gitignore │ ├── tsconfig.json │ ├── package.json │ └── README.md ├── react-redux │ ├── src │ │ ├── react-app-env.d.ts │ │ ├── components │ │ │ ├── common │ │ │ │ ├── Header.css │ │ │ │ └── Header.tsx │ │ │ ├── about │ │ │ │ └── AboutPage.tsx │ │ │ ├── home │ │ │ │ └── HomePage.tsx │ │ │ └── book │ │ │ │ └── BookPage.tsx │ │ ├── NotFoundPage.tsx │ │ ├── redux │ │ │ ├── rootReducer.ts │ │ │ ├── book │ │ │ │ ├── bookAction.ts │ │ │ │ ├── bookActionType.ts │ │ │ │ └── bookReducer.ts │ │ │ └── store.ts │ │ ├── App.test.tsx │ │ ├── index.css │ │ ├── App.css │ │ ├── index.tsx │ │ ├── App.tsx │ │ ├── logo.svg │ │ └── serviceWorker.ts │ ├── public │ │ ├── favicon.ico │ │ ├── manifest.json │ │ └── index.html │ ├── .gitignore │ ├── tsconfig.json │ ├── package.json │ └── README.md └── react-thunk │ ├── src │ ├── react-app-env.d.ts │ ├── components │ │ ├── common │ │ │ ├── Header.css │ │ │ └── Header.tsx │ │ ├── about │ │ │ └── AboutPage.tsx │ │ ├── home │ │ │ └── HomePage.tsx │ │ └── book │ │ │ └── BookPage.tsx │ ├── NotFoundPage.tsx │ ├── redux │ │ ├── rootReducer.ts │ │ ├── book │ │ │ ├── bookAction.ts │ │ │ ├── bookActionType.ts │ │ │ └── bookReducer.ts │ │ └── store.ts │ ├── App.test.tsx │ ├── index.css │ ├── App.css │ ├── index.tsx │ ├── App.tsx │ ├── logo.svg │ └── serviceWorker.ts │ ├── public │ ├── favicon.ico │ ├── manifest.json │ └── index.html │ ├── .gitignore │ └── README.md ├── spring ├── spring-security-oauth │ └── authorization-server │ │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── in │ │ │ │ └── kuros │ │ │ │ └── blog │ │ │ │ └── spring │ │ │ │ └── security │ │ │ │ └── oauth │ │ │ │ └── SpringSecurityOauthApplication.java │ │ └── test │ │ │ └── java │ │ │ └── in │ │ │ └── kuros │ │ │ └── blog │ │ │ └── spring │ │ │ └── security │ │ │ └── oauth │ │ │ └── SpringSecurityOauthApplicationTests.java │ │ ├── .gitignore │ │ └── pom.xml ├── spring-security-basics │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ ├── maven-wrapper.properties │ │ │ └── MavenWrapperDownloader.java │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── application.properties │ │ │ │ └── db │ │ │ │ │ └── data.sql │ │ │ └── java │ │ │ │ └── in │ │ │ │ └── kuros │ │ │ │ └── blog │ │ │ │ └── code │ │ │ │ └── spring │ │ │ │ └── security │ │ │ │ └── basics │ │ │ │ ├── repository │ │ │ │ └── BookRepository.java │ │ │ │ ├── SpringSecurityBasicsApplication.java │ │ │ │ ├── entity │ │ │ │ └── Book.java │ │ │ │ ├── controller │ │ │ │ └── BookController.java │ │ │ │ └── security │ │ │ │ └── SecurityConfiguration.java │ │ └── test │ │ │ └── java │ │ │ └── in │ │ │ └── kuros │ │ │ └── blog │ │ │ └── code │ │ │ └── spring │ │ │ └── security │ │ │ └── basics │ │ │ └── SpringSecurityBasicsApplicationTests.java │ ├── .gitignore │ └── pom.xml ├── spring-cloud-stream-rabbitmq │ └── publisher │ │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ ├── maven-wrapper.properties │ │ │ └── MavenWrapperDownloader.java │ │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── in │ │ │ │ └── kuros │ │ │ │ └── blog │ │ │ │ └── publisher │ │ │ │ ├── SpringCloudStreamRabbitmqPubApplication.java │ │ │ │ ├── Order.java │ │ │ │ ├── LoggingListener.java │ │ │ │ └── OrderPublisher.java │ │ └── test │ │ │ └── java │ │ │ └── in │ │ │ └── kuros │ │ │ └── blog │ │ │ └── publisher │ │ │ └── SpringCloudStreamRabbitmqPubApplicationTests.java │ │ ├── .gitignore │ │ └── pom.xml └── spring-security-authentication-provider │ ├── src │ ├── main │ │ ├── resources │ │ │ ├── db │ │ │ │ └── data.sql │ │ │ └── application.properties │ │ └── java │ │ │ └── in │ │ │ └── kuros │ │ │ ├── repository │ │ │ └── UserRepository.java │ │ │ ├── controller │ │ │ ├── UserControllers.java │ │ │ └── BookController.java │ │ │ ├── SpringSecurityAuthenticationProviderApplication.java │ │ │ ├── entity │ │ │ ├── UserRoles.java │ │ │ └── UserEntity.java │ │ │ ├── config │ │ │ └── SecurityConfig.java │ │ │ └── custom │ │ │ ├── User.java │ │ │ └── CustomAuthenticationProvider.java │ └── test │ │ └── java │ │ └── in │ │ └── kuros │ │ └── blog │ │ └── code │ │ └── spring │ │ └── security │ │ └── authentication │ │ └── provider │ │ └── SpringSecurityAuthenticationProviderApplicationTests.java │ ├── .gitignore │ └── pom.xml ├── terraform ├── sqs-lambda-integration-localstack │ ├── main.tf │ ├── lambda │ │ ├── tsconfig.build.json │ │ ├── .gitignore │ │ ├── tsconfig.json │ │ ├── src │ │ │ └── main.ts │ │ └── package.json │ ├── output.tf │ ├── variable.tf │ ├── scripts │ │ └── build.sh │ ├── .gitignore │ ├── sqs.tf │ ├── lambda.tf │ └── provider.tf └── fix-lambda-localstack │ ├── index.js │ ├── lambda.tf │ └── provider.tf ├── messaging └── messaging-kafka │ ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ ├── maven-wrapper.properties │ │ └── MavenWrapperDownloader.java │ ├── src │ ├── test │ │ └── java │ │ │ └── in │ │ │ └── kuros │ │ │ └── blogcode │ │ │ └── messaging │ │ │ └── kafka │ │ │ └── MessagingKafkaApplicationTests.java │ └── main │ │ ├── java │ │ └── in │ │ │ └── kuros │ │ │ └── blogcode │ │ │ └── messaging │ │ │ └── kafka │ │ │ ├── consumer │ │ │ └── MessageConsumer.java │ │ │ ├── MessagingKafkaApplication.java │ │ │ ├── producer │ │ │ └── MessageProducer.java │ │ │ └── controller │ │ │ └── KafkaController.java │ │ └── resources │ │ └── application.yaml │ ├── .gitignore │ └── pom.xml ├── testing └── greenmail │ ├── src │ ├── main │ │ └── java │ │ │ └── in │ │ │ └── kuros │ │ │ ├── ServerInfo.java │ │ │ ├── MailContext.java │ │ │ └── MailSender.java │ └── test │ │ └── java │ │ └── in │ │ └── kuros │ │ └── MailSenderTest.java │ └── pom.xml └── java ├── src └── main │ └── java │ └── in │ └── kuros │ └── blog │ └── code │ └── java │ ├── parallel │ ├── ExecutionResult.java │ ├── ParallelExecutionExceptionExample.java │ ├── ParallelExecutionExample.java │ ├── CompletableFutureExample.java │ └── ParallelExecution.java │ └── streams │ └── CustomCollector.java └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | *.class 3 | .idea/* -------------------------------------------------------------------------------- /k8s/machine-ip/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /nestjs/nest-auth/src/users/dto/create-user.dto.ts: -------------------------------------------------------------------------------- 1 | export class CreateUserDto {} 2 | -------------------------------------------------------------------------------- /react/first-app/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /react/react-redux/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /react/react-thunk/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /nestjs/gcp-storage/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } -------------------------------------------------------------------------------- /spring/spring-security-oauth/authorization-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /terraform/sqs-lambda-integration-localstack/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = "~> 1.3.3" 3 | } -------------------------------------------------------------------------------- /nestjs/gcp-storage/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "collection": "@nestjs/schematics", 3 | "sourceRoot": "src" 4 | } 5 | -------------------------------------------------------------------------------- /nestjs/nest-auth/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "collection": "@nestjs/schematics", 3 | "sourceRoot": "src" 4 | } 5 | -------------------------------------------------------------------------------- /nestjs/nestjs-mongo/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "collection": "@nestjs/schematics", 3 | "sourceRoot": "src" 4 | } 5 | -------------------------------------------------------------------------------- /nestjs/nest-auth/src/users/entities/role.enum.ts: -------------------------------------------------------------------------------- 1 | export enum Role{ 2 | USER='user', 3 | ADMIN='admin', 4 | } -------------------------------------------------------------------------------- /react/first-app/src/components/common/Header.css: -------------------------------------------------------------------------------- 1 | .space { 2 | margin-bottom: 20px; 3 | margin-top: 20px; 4 | } -------------------------------------------------------------------------------- /react/first-app/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuros/blog-code/HEAD/react/first-app/public/favicon.ico -------------------------------------------------------------------------------- /react/react-redux/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuros/blog-code/HEAD/react/react-redux/public/favicon.ico -------------------------------------------------------------------------------- /react/react-redux/src/components/common/Header.css: -------------------------------------------------------------------------------- 1 | .space { 2 | margin-bottom: 20px; 3 | margin-top: 20px; 4 | } -------------------------------------------------------------------------------- /react/react-thunk/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuros/blog-code/HEAD/react/react-thunk/public/favicon.ico -------------------------------------------------------------------------------- /react/react-thunk/src/components/common/Header.css: -------------------------------------------------------------------------------- 1 | .space { 2 | margin-bottom: 20px; 3 | margin-top: 20px; 4 | } -------------------------------------------------------------------------------- /nestjs/gcp-storage/src/media/file-upload-dto.ts: -------------------------------------------------------------------------------- 1 | 2 | class FileUploadDto { 3 | file: any; 4 | mediaId: string 5 | } -------------------------------------------------------------------------------- /nestjs/nest-auth/src/users/entities/user.entity.ts: -------------------------------------------------------------------------------- 1 | export class User { 2 | name:string; 3 | roles:string[]; 4 | } 5 | -------------------------------------------------------------------------------- /nestjs/nestjs-mongo/src/users/dto/create-user.dto.ts: -------------------------------------------------------------------------------- 1 | export class CreateUserDto { 2 | email: string; 3 | age: number; 4 | } -------------------------------------------------------------------------------- /nestjs/nestjs-mongo/src/users/dto/update-user.dto.ts: -------------------------------------------------------------------------------- 1 | export class UpdateUserDto { 2 | favoriteFoods: string[] 3 | age: number; 4 | } -------------------------------------------------------------------------------- /k8s/machine-ip/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jdk-alpine 2 | COPY target/machine-ip-0.0.1.jar app.jar 3 | EXPOSE 8080 4 | ENTRYPOINT ["java","-jar","/app.jar"] -------------------------------------------------------------------------------- /nestjs/gcp-storage/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /nestjs/nest-auth/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /nestjs/nestjs-mongo/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /messaging/messaging-kafka/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuros/blog-code/HEAD/messaging/messaging-kafka/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /nestjs/gcp-storage/src/storage/storage-file.ts: -------------------------------------------------------------------------------- 1 | 2 | export class StorageFile { 3 | buffer: Buffer; 4 | metadata: Map; 5 | contentType: string; 6 | } -------------------------------------------------------------------------------- /spring/spring-security-basics/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuros/blog-code/HEAD/spring/spring-security-basics/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /terraform/sqs-lambda-integration-localstack/lambda/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /k8s/machine-ip/client.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for i in {1..10} 4 | do 5 | response=$(curl -sb -H "Accept: application/json" "http://localhost:8080/ip") 6 | echo ${response} 7 | done -------------------------------------------------------------------------------- /spring/spring-security-basics/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /nestjs/gcp-storage/.env: -------------------------------------------------------------------------------- 1 | PROJECT_ID = 2 | PRIVATE_KEY = 3 | CLIENT_EMAIL = 4 | STORAGE_MEDIA_BUCKET = -------------------------------------------------------------------------------- /spring/spring-cloud-stream-rabbitmq/publisher/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuros/blog-code/HEAD/spring/spring-cloud-stream-rabbitmq/publisher/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring/spring-cloud-stream-rabbitmq/publisher/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /react/first-app/src/NotFoundPage.tsx: -------------------------------------------------------------------------------- 1 | import React, {FunctionComponent} from "react"; 2 | 3 | const NotFoundPage:FunctionComponent = () =>
Oops Page Not found.
; 4 | 5 | export default NotFoundPage; -------------------------------------------------------------------------------- /terraform/sqs-lambda-integration-localstack/output.tf: -------------------------------------------------------------------------------- 1 | output "test-queue" { 2 | value = aws_sqs_queue.test-queue.id 3 | } 4 | 5 | output "lambda" { 6 | value = aws_lambda_function.lambda.invoke_arn 7 | } -------------------------------------------------------------------------------- /nestjs/gcp-storage/src/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class AppService { 5 | getHello(): string { 6 | return 'Hello World!'; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /nestjs/nest-auth/src/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class AppService { 5 | getHello(): string { 6 | return 'Hello World!'; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /nestjs/nestjs-mongo/src/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class AppService { 5 | getHello(): string { 6 | return 'Hello World!'; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /nestjs/nest-auth/src/users/roles.decorator.ts: -------------------------------------------------------------------------------- 1 | import { SetMetadata } from "@nestjs/common"; 2 | import { Role } from "./entities/role.enum"; 3 | 4 | export const Roles=(...roles: Role [])=>SetMetadata('roles',roles) -------------------------------------------------------------------------------- /terraform/sqs-lambda-integration-localstack/variable.tf: -------------------------------------------------------------------------------- 1 | variable "url" { 2 | type = string 3 | description = "Url for forwarding the event" 4 | default = "http://host.docker.internal:3001/lambda-handler" 5 | } -------------------------------------------------------------------------------- /react/react-redux/src/NotFoundPage.tsx: -------------------------------------------------------------------------------- 1 | import React, {FunctionComponent} from "react"; 2 | 3 | 4 | const NotFoundPage:FunctionComponent = () =>
Oops Page Not found.
; 5 | 6 | 7 | export default NotFoundPage; -------------------------------------------------------------------------------- /react/react-thunk/src/NotFoundPage.tsx: -------------------------------------------------------------------------------- 1 | import React, {FunctionComponent} from "react"; 2 | 3 | 4 | const NotFoundPage:FunctionComponent = () =>
Oops Page Not found.
; 5 | 6 | 7 | export default NotFoundPage; -------------------------------------------------------------------------------- /spring/spring-security-authentication-provider/src/main/resources/db/data.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO users (user_name, password) VALUES ('kuros', 'passwd'); 2 | 3 | INSERT INTO user_roles (user_id, role) VALUES (1, 'ADMIN'), (1, 'USER'); 4 | -------------------------------------------------------------------------------- /nestjs/nest-auth/src/users/dto/update-user.dto.ts: -------------------------------------------------------------------------------- 1 | import { PartialType } from '@nestjs/mapped-types'; 2 | import { CreateUserDto } from './create-user.dto'; 3 | 4 | export class UpdateUserDto extends PartialType(CreateUserDto) {} 5 | -------------------------------------------------------------------------------- /k8s/machine-ip/Service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: machine-ip-service 5 | spec: 6 | selector: 7 | app: machine-ip 8 | ports: 9 | - port: 8080 10 | targetPort: 8080 11 | type: LoadBalancer -------------------------------------------------------------------------------- /react/react-redux/src/redux/rootReducer.ts: -------------------------------------------------------------------------------- 1 | import {combineReducers} from "redux"; 2 | import BookReducer from "./book/bookReducer"; 3 | 4 | const rootReducer = combineReducers({ 5 | books: BookReducer 6 | }); 7 | 8 | export default rootReducer; -------------------------------------------------------------------------------- /react/react-thunk/src/redux/rootReducer.ts: -------------------------------------------------------------------------------- 1 | import {combineReducers} from "redux"; 2 | import BookReducer from "./book/bookReducer"; 3 | 4 | const rootReducer = combineReducers({ 5 | books: BookReducer 6 | }); 7 | 8 | export default rootReducer; -------------------------------------------------------------------------------- /nestjs/gcp-storage/test/jest-e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": ["js", "json", "ts"], 3 | "rootDir": ".", 4 | "testEnvironment": "node", 5 | "testRegex": ".e2e-spec.ts$", 6 | "transform": { 7 | "^.+\\.(t|j)s$": "ts-jest" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /nestjs/nest-auth/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(3000); 7 | } 8 | bootstrap(); 9 | -------------------------------------------------------------------------------- /nestjs/nest-auth/test/jest-e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": ["js", "json", "ts"], 3 | "rootDir": ".", 4 | "testEnvironment": "node", 5 | "testRegex": ".e2e-spec.ts$", 6 | "transform": { 7 | "^.+\\.(t|j)s$": "ts-jest" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /nestjs/nestjs-mongo/test/jest-e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": ["js", "json", "ts"], 3 | "rootDir": ".", 4 | "testEnvironment": "node", 5 | "testRegex": ".e2e-spec.ts$", 6 | "transform": { 7 | "^.+\\.(t|j)s$": "ts-jest" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /nestjs/gcp-storage/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(3000); 7 | } 8 | bootstrap(); 9 | -------------------------------------------------------------------------------- /nestjs/gcp-storage/src/storage/storage.module.ts: -------------------------------------------------------------------------------- 1 | import {Module} from '@nestjs/common'; 2 | import {StorageService} from "./storage.service"; 3 | 4 | @Module({ 5 | providers: [StorageService], 6 | exports: [StorageService] 7 | }) 8 | export class StorageModule {} 9 | -------------------------------------------------------------------------------- /nestjs/nestjs-mongo/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(3000); 7 | } 8 | bootstrap(); 9 | -------------------------------------------------------------------------------- /react/first-app/src/components/book/BookPage.tsx: -------------------------------------------------------------------------------- 1 | import React, {Component, ReactNode} from "react"; 2 | 3 | class BookPage extends Component{ 4 | 5 | render(): ReactNode { 6 | return
Books
; 7 | } 8 | } 9 | 10 | export default BookPage; -------------------------------------------------------------------------------- /spring/spring-security-authentication-provider/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.h2.console.enabled=true 2 | spring.jpa.hibernate.ddl-auto=create 3 | spring.datasource.data=classpath:db/data.sql 4 | spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true -------------------------------------------------------------------------------- /terraform/sqs-lambda-integration-localstack/scripts/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -rf lambda_function.zip 4 | pushd lambda || exit 1 5 | npm install 6 | npm run build 7 | popd || exit 1 8 | 9 | #zip -r lambda_function.zip lambda 10 | #chmod 777 lambda_function.zip -------------------------------------------------------------------------------- /react/react-redux/src/redux/book/bookAction.ts: -------------------------------------------------------------------------------- 1 | import {Book} from "../../components/book/BookPage"; 2 | import {BookActionType, CREATE_BOOK} from "./bookActionType"; 3 | 4 | export function createBook(book: Book): BookActionType { 5 | return {type: CREATE_BOOK, payload: book} 6 | } -------------------------------------------------------------------------------- /react/react-thunk/src/redux/book/bookAction.ts: -------------------------------------------------------------------------------- 1 | import {Book} from "../../components/book/BookPage"; 2 | import {BookActionType, CREATE_BOOK} from "./bookActionType"; 3 | 4 | export function createBook(book: Book): BookActionType { 5 | return {type: CREATE_BOOK, payload: book} 6 | } -------------------------------------------------------------------------------- /messaging/messaging-kafka/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /testing/greenmail/src/main/java/in/kuros/ServerInfo.java: -------------------------------------------------------------------------------- 1 | package in.kuros; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | @Data 7 | @AllArgsConstructor 8 | public class ServerInfo { 9 | private String host; 10 | private String port; 11 | } 12 | -------------------------------------------------------------------------------- /terraform/sqs-lambda-integration-localstack/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | **.iml 3 | target/ 4 | build/ 5 | dist/ 6 | .gradle/ 7 | .terraform/ 8 | **.tfstate 9 | .pytest_cache 10 | __pycache__ 11 | **.pyc 12 | **.swp 13 | .terraform 14 | .terraform.lock.hcl 15 | *.tfstate* 16 | lambda_function.zip -------------------------------------------------------------------------------- /nestjs/gcp-storage/src/storage/storage-config.ts: -------------------------------------------------------------------------------- 1 | 2 | const StorageConfig = { 3 | projectId: process.env.PROJECT_ID, 4 | private_key: process.env.PRIVATE_KEY, 5 | client_email: process.env.CLIENT_EMAIL, 6 | mediaBucket: process.env.STORAGE_MEDIA_BUCKET 7 | } 8 | 9 | export default StorageConfig; -------------------------------------------------------------------------------- /react/react-redux/src/redux/book/bookActionType.ts: -------------------------------------------------------------------------------- 1 | import {Book} from "../../components/book/BookPage"; 2 | 3 | export const CREATE_BOOK = 'CREATE_BOOK'; 4 | 5 | interface CreateBookAction { 6 | type: typeof CREATE_BOOK 7 | payload: Book 8 | } 9 | 10 | export type BookActionType = CreateBookAction; -------------------------------------------------------------------------------- /react/react-thunk/src/redux/book/bookActionType.ts: -------------------------------------------------------------------------------- 1 | import {Book} from "../../components/book/BookPage"; 2 | 3 | export const CREATE_BOOK = 'CREATE_BOOK'; 4 | 5 | interface CreateBookAction { 6 | type: typeof CREATE_BOOK 7 | payload: Book 8 | } 9 | 10 | export type BookActionType = CreateBookAction; -------------------------------------------------------------------------------- /react/first-app/src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); 10 | -------------------------------------------------------------------------------- /react/react-redux/src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); 10 | -------------------------------------------------------------------------------- /react/react-thunk/src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); 10 | -------------------------------------------------------------------------------- /nestjs/nest-auth/src/users/users.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { UsersService } from './users.service'; 3 | import { UsersController } from './users.controller'; 4 | 5 | @Module({ 6 | controllers: [UsersController], 7 | providers: [UsersService] 8 | }) 9 | export class UsersModule {} 10 | -------------------------------------------------------------------------------- /nestjs/gcp-storage/src/media/media.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { StorageModule } from 'src/storage/storage.module'; 3 | import { MediaController } from './media.controller'; 4 | 5 | @Module({ 6 | imports: [StorageModule], 7 | controllers: [MediaController] 8 | }) 9 | export class MediaModule {} 10 | -------------------------------------------------------------------------------- /testing/greenmail/src/main/java/in/kuros/MailContext.java: -------------------------------------------------------------------------------- 1 | package in.kuros; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | @Data 7 | @AllArgsConstructor 8 | public class MailContext { 9 | private String from; 10 | private String to; 11 | private String subject; 12 | private String message; 13 | } 14 | -------------------------------------------------------------------------------- /spring/spring-security-basics/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:h2:mem:testdb; 2 | spring.datasource.driverClassName=org.h2.Driver 3 | spring.datasource.username=sa 4 | spring.datasource.password= 5 | spring.h2.console.enabled=true 6 | spring.jpa.hibernate.ddl-auto=create 7 | spring.datasource.data=classpath:db/data.sql 8 | -------------------------------------------------------------------------------- /nestjs/nest-auth/src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get } from '@nestjs/common'; 2 | import { AppService } from './app.service'; 3 | 4 | @Controller() 5 | export class AppController { 6 | constructor(private readonly appService: AppService) {} 7 | 8 | @Get() 9 | getHello(): string { 10 | return this.appService.getHello(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /nestjs/gcp-storage/src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get } from '@nestjs/common'; 2 | import { AppService } from './app.service'; 3 | 4 | @Controller() 5 | export class AppController { 6 | constructor(private readonly appService: AppService) {} 7 | 8 | @Get() 9 | getHello(): string { 10 | return this.appService.getHello(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /nestjs/nestjs-mongo/src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get } from '@nestjs/common'; 2 | import { AppService } from './app.service'; 3 | 4 | @Controller() 5 | export class AppController { 6 | constructor(private readonly appService: AppService) {} 7 | 8 | @Get() 9 | getHello(): string { 10 | return this.appService.getHello(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring/spring-cloud-stream-rabbitmq/publisher/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8081 2 | 3 | spring.rabbitmq.host=127.0.0.1 4 | spring.rabbitmq.port=5672 5 | spring.rabbitmq.username=guest 6 | spring.rabbitmq.password=guest 7 | 8 | spring.cloud.stream.bindings.input.destination=order 9 | spring.cloud.stream.bindings.output.destination=order 10 | -------------------------------------------------------------------------------- /react/first-app/src/components/about/AboutPage.tsx: -------------------------------------------------------------------------------- 1 | import React, {FunctionComponent} from "react"; 2 | 3 | 4 | const AboutPage: FunctionComponent = () => { 5 | return ( 6 |
7 |
8 | This is the about Page 9 |
10 |
11 | ) 12 | }; 13 | 14 | export default AboutPage; 15 | -------------------------------------------------------------------------------- /react/react-redux/src/components/about/AboutPage.tsx: -------------------------------------------------------------------------------- 1 | import React, {FunctionComponent} from "react"; 2 | 3 | 4 | const AboutPage: FunctionComponent = () => { 5 | return ( 6 |
7 |
8 | This is the about Page 9 |
10 |
11 | ) 12 | }; 13 | 14 | export default AboutPage; 15 | -------------------------------------------------------------------------------- /react/react-thunk/src/components/about/AboutPage.tsx: -------------------------------------------------------------------------------- 1 | import React, {FunctionComponent} from "react"; 2 | 3 | 4 | const AboutPage: FunctionComponent = () => { 5 | return ( 6 |
7 |
8 | This is the about Page 9 |
10 |
11 | ) 12 | }; 13 | 14 | export default AboutPage; 15 | -------------------------------------------------------------------------------- /spring/spring-security-authentication-provider/src/main/java/in/kuros/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package in.kuros.repository; 2 | 3 | import in.kuros.entity.UserEntity; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface UserRepository extends JpaRepository { 7 | 8 | UserEntity findByUserName(String username); 9 | } 10 | -------------------------------------------------------------------------------- /spring/spring-security-basics/src/main/java/in/kuros/blog/code/spring/security/basics/repository/BookRepository.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blog.code.spring.security.basics.repository; 2 | 3 | import in.kuros.blog.code.spring.security.basics.entity.Book; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface BookRepository extends JpaRepository { 7 | } 8 | -------------------------------------------------------------------------------- /terraform/fix-lambda-localstack/index.js: -------------------------------------------------------------------------------- 1 | 2 | const sleep = (ms) => { 3 | return new Promise(resolve => setTimeout(resolve, ms)); 4 | } 5 | 6 | exports.handler = async (event, context) => { 7 | await sleep(10) 8 | 9 | return Promise.resolve({ 10 | statusCode: 200, 11 | headers: {'Content-Type': 'application/json'}, 12 | body: "Hello World", 13 | }); 14 | }; -------------------------------------------------------------------------------- /messaging/messaging-kafka/src/test/java/in/kuros/blogcode/messaging/kafka/MessagingKafkaApplicationTests.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blogcode.messaging.kafka; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class MessagingKafkaApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /react/first-app/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /k8s/machine-ip/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /nbbuild/ 22 | /dist/ 23 | /nbdist/ 24 | /.nb-gradle/ 25 | /build/ 26 | -------------------------------------------------------------------------------- /react/react-redux/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /react/react-thunk/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /nestjs/nestjs-mongo/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "removeComments": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": true, 9 | "target": "es2017", 10 | "sourceMap": true, 11 | "outDir": "./dist", 12 | "baseUrl": "./", 13 | "incremental": true 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /react/first-app/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /spring/spring-security-basics/src/main/resources/db/data.sql: -------------------------------------------------------------------------------- 1 | insert into book(name) values ('A Little Forever'), 2 | ('To Kill a Mockingbird '), 3 | ('A Thousand Splendid Suns'), 4 | ('The Kite Runner'), 5 | ('Harry Potter and the Philosopher''s Stone'), 6 | ('Harry Potter and the Chamber of Secrets'); -------------------------------------------------------------------------------- /react/react-redux/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /react/react-thunk/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /terraform/sqs-lambda-integration-localstack/sqs.tf: -------------------------------------------------------------------------------- 1 | 2 | resource "aws_sqs_queue" "test-queue" { 3 | name = "test-queue" 4 | visibility_timeout_seconds = 300 5 | } 6 | 7 | 8 | resource "aws_lambda_event_source_mapping" "test_queue_lambda_mapping" { 9 | batch_size = 1 10 | event_source_arn = aws_sqs_queue.test-queue.arn 11 | enabled = true 12 | function_name = aws_lambda_function.lambda.function_name 13 | } 14 | -------------------------------------------------------------------------------- /react/react-redux/src/redux/book/bookReducer.ts: -------------------------------------------------------------------------------- 1 | import {Book} from "../../components/book/BookPage"; 2 | import {BookActionType, CREATE_BOOK} from "./bookActionType"; 3 | 4 | export default function BookReducer(state: Book[] = [], action: BookActionType): Book[] { 5 | switch (action.type) { 6 | case CREATE_BOOK: 7 | return [...state, {...action.payload}]; 8 | default: 9 | return state; 10 | } 11 | } -------------------------------------------------------------------------------- /react/react-thunk/src/redux/book/bookReducer.ts: -------------------------------------------------------------------------------- 1 | import {Book} from "../../components/book/BookPage"; 2 | import {BookActionType, CREATE_BOOK} from "./bookActionType"; 3 | 4 | export default function BookReducer(state: Book[] = [], action: BookActionType): Book[] { 5 | switch (action.type) { 6 | case CREATE_BOOK: 7 | return [...state, {...action.payload}]; 8 | default: 9 | return state; 10 | } 11 | } -------------------------------------------------------------------------------- /nestjs/gcp-storage/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | import { StorageModule } from './storage/storage.module'; 5 | import { MediaModule } from './media/media.module'; 6 | 7 | @Module({ 8 | imports: [StorageModule, MediaModule], 9 | controllers: [AppController], 10 | providers: [AppService], 11 | }) 12 | export class AppModule {} 13 | -------------------------------------------------------------------------------- /react/first-app/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 5 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 6 | sans-serif; 7 | -webkit-font-smoothing: antialiased; 8 | -moz-osx-font-smoothing: grayscale; 9 | } 10 | 11 | code { 12 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 13 | monospace; 14 | } 15 | -------------------------------------------------------------------------------- /react/react-redux/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 5 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 6 | sans-serif; 7 | -webkit-font-smoothing: antialiased; 8 | -moz-osx-font-smoothing: grayscale; 9 | } 10 | 11 | code { 12 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 13 | monospace; 14 | } 15 | -------------------------------------------------------------------------------- /react/react-thunk/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 5 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 6 | sans-serif; 7 | -webkit-font-smoothing: antialiased; 8 | -moz-osx-font-smoothing: grayscale; 9 | } 10 | 11 | code { 12 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 13 | monospace; 14 | } 15 | -------------------------------------------------------------------------------- /java/src/main/java/in/kuros/blog/code/java/parallel/ExecutionResult.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blog.code.java.parallel; 2 | 3 | import java.util.List; 4 | 5 | public class ExecutionResult { 6 | 7 | private List result; 8 | 9 | ExecutionResult(final List result) { 10 | this.result = result; 11 | } 12 | 13 | @SuppressWarnings("unchecked") 14 | public T get(final int index) { 15 | return (T) result.get(index); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /k8s/machine-ip/src/main/java/in/kuros/k8s/machineip/MachineIpApplication.java: -------------------------------------------------------------------------------- 1 | package in.kuros.k8s.machineip; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class MachineIpApplication { 8 | 9 | public static void main(final String[] args) { 10 | SpringApplication.run(MachineIpApplication.class, args); 11 | } 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /spring/spring-security-basics/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | /target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | .sts4-cache 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 16 | *.iws 17 | *.iml 18 | *.ipr 19 | 20 | ### NetBeans ### 21 | /nbproject/private/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ 26 | /build/ 27 | 28 | ### VS Code ### 29 | .vscode/ 30 | -------------------------------------------------------------------------------- /spring/spring-security-authentication-provider/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | /target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | .sts4-cache 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 16 | *.iws 17 | *.iml 18 | *.ipr 19 | 20 | ### NetBeans ### 21 | /nbproject/private/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ 26 | /build/ 27 | 28 | ### VS Code ### 29 | .vscode/ 30 | -------------------------------------------------------------------------------- /k8s/machine-ip/src/test/java/in/kuros/k8s/machineip/MachineIpApplicationTests.java: -------------------------------------------------------------------------------- 1 | package in.kuros.k8s.machineip; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class MachineIpApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /messaging/messaging-kafka/src/main/java/in/kuros/blogcode/messaging/kafka/consumer/MessageConsumer.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blogcode.messaging.kafka.consumer; 2 | 3 | import org.springframework.kafka.annotation.KafkaListener; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component 7 | public class MessageConsumer { 8 | 9 | @KafkaListener(topics = "user-name") 10 | public void consume(final String message) { 11 | System.out.println("Received: " + message); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /nestjs/nestjs-mongo/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { MongooseModule } from '@nestjs/mongoose'; 3 | 4 | import { AppController } from './app.controller'; 5 | import { AppService } from './app.service'; 6 | import { UsersModule } from './users/users.module'; 7 | 8 | @Module({ 9 | imports: [MongooseModule.forRoot('mongodb://localhost/demo'), UsersModule], 10 | controllers: [AppController], 11 | providers: [AppService], 12 | }) 13 | export class AppModule {} 14 | -------------------------------------------------------------------------------- /messaging/messaging-kafka/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /messaging/messaging-kafka/src/main/java/in/kuros/blogcode/messaging/kafka/MessagingKafkaApplication.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blogcode.messaging.kafka; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class MessagingKafkaApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(MessagingKafkaApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /nestjs/nestjs-mongo/src/users/schemas/user.schema.ts: -------------------------------------------------------------------------------- 1 | import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose"; 2 | import { Document } from 'mongoose'; 3 | 4 | export type UserDocument = User & Document; 5 | 6 | @Schema() 7 | export class User { 8 | @Prop() 9 | userId: string; 10 | 11 | @Prop() 12 | email: string; 13 | 14 | @Prop() 15 | age: number; 16 | 17 | @Prop([String]) 18 | favoriteFoods: string[] 19 | } 20 | 21 | export const UserSchema = SchemaFactory.createForClass(User); -------------------------------------------------------------------------------- /spring/spring-cloud-stream-rabbitmq/publisher/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /spring/spring-security-oauth/authorization-server/src/main/java/in/kuros/blog/spring/security/oauth/SpringSecurityOauthApplication.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blog.spring.security.oauth; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringSecurityOauthApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringSecurityOauthApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring/spring-security-basics/src/main/java/in/kuros/blog/code/spring/security/basics/SpringSecurityBasicsApplication.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blog.code.spring.security.basics; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringSecurityBasicsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringSecurityBasicsApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring/spring-security-oauth/authorization-server/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | /.mvn/* 33 | -------------------------------------------------------------------------------- /react/first-app/src/components/home/HomePage.tsx: -------------------------------------------------------------------------------- 1 | import React, {Component} from "react"; 2 | import {Link} from "react-router-dom"; 3 | 4 | class HomePage extends Component { 5 | 6 | render() { 7 | return ( 8 |
9 |
10 |

Welcome to your first React App

11 | More 12 |
13 |
14 | ); 15 | } 16 | } 17 | 18 | export default HomePage; -------------------------------------------------------------------------------- /react/react-redux/src/components/home/HomePage.tsx: -------------------------------------------------------------------------------- 1 | import React, {Component} from "react"; 2 | import {Link} from "react-router-dom"; 3 | 4 | class HomePage extends Component { 5 | 6 | 7 | render() { 8 | return ( 9 |
10 |
11 |

Welcome to your first React App

12 | More 13 |
14 |
15 | ); 16 | } 17 | } 18 | 19 | export default HomePage; -------------------------------------------------------------------------------- /react/react-thunk/src/components/home/HomePage.tsx: -------------------------------------------------------------------------------- 1 | import React, {Component} from "react"; 2 | import {Link} from "react-router-dom"; 3 | 4 | class HomePage extends Component { 5 | 6 | 7 | render() { 8 | return ( 9 |
10 |
11 |

Welcome to your first React App

12 | More 13 |
14 |
15 | ); 16 | } 17 | } 18 | 19 | export default HomePage; -------------------------------------------------------------------------------- /spring/spring-cloud-stream-rabbitmq/publisher/src/test/java/in/kuros/blog/publisher/SpringCloudStreamRabbitmqPubApplicationTests.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blog.publisher; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringCloudStreamRabbitmqPubApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring/spring-security-oauth/authorization-server/src/test/java/in/kuros/blog/spring/security/oauth/SpringSecurityOauthApplicationTests.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blog.spring.security.oauth; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringSecurityOauthApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /nestjs/gcp-storage/.gitignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist 3 | /node_modules 4 | 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | pnpm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | lerna-debug.log* 13 | 14 | # OS 15 | .DS_Store 16 | 17 | # Tests 18 | /coverage 19 | /.nyc_output 20 | 21 | # IDEs and editors 22 | /.idea 23 | .project 24 | .classpath 25 | .c9/ 26 | *.launch 27 | .settings/ 28 | *.sublime-workspace 29 | 30 | # IDE - VSCode 31 | .vscode/* 32 | !.vscode/settings.json 33 | !.vscode/tasks.json 34 | !.vscode/launch.json 35 | !.vscode/extensions.json -------------------------------------------------------------------------------- /nestjs/nest-auth/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { APP_GUARD } from '@nestjs/core'; 3 | import { AppController } from './app.controller'; 4 | import { AppService } from './app.service'; 5 | import { RolesGuard } from './users/roles.guard'; 6 | import { UsersModule } from './users/users.module'; 7 | 8 | @Module({ 9 | imports: [UsersModule], 10 | controllers: [AppController], 11 | providers: [AppService, 12 | { 13 | provide: APP_GUARD, 14 | useClass:RolesGuard, 15 | }], 16 | }) 17 | export class AppModule {} 18 | -------------------------------------------------------------------------------- /nestjs/nest-auth/src/users/users.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { UsersService } from './users.service'; 3 | 4 | describe('UsersService', () => { 5 | let service: UsersService; 6 | 7 | beforeEach(async () => { 8 | const module: TestingModule = await Test.createTestingModule({ 9 | providers: [UsersService], 10 | }).compile(); 11 | 12 | service = module.get(UsersService); 13 | }); 14 | 15 | it('should be defined', () => { 16 | expect(service).toBeDefined(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /nestjs/nestjs-mongo/.gitignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist 3 | /node_modules 4 | 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | pnpm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | lerna-debug.log* 13 | 14 | # OS 15 | .DS_Store 16 | 17 | # Tests 18 | /coverage 19 | /.nyc_output 20 | 21 | # IDEs and editors 22 | /.idea 23 | .project 24 | .classpath 25 | .c9/ 26 | *.launch 27 | .settings/ 28 | *.sublime-workspace 29 | 30 | # IDE - VSCode 31 | .vscode/* 32 | !.vscode/settings.json 33 | !.vscode/tasks.json 34 | !.vscode/launch.json 35 | !.vscode/extensions.json -------------------------------------------------------------------------------- /spring/spring-security-basics/src/test/java/in/kuros/blog/code/spring/security/basics/SpringSecurityBasicsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blog.code.spring.security.basics; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringSecurityBasicsApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /messaging/messaging-kafka/src/main/java/in/kuros/blogcode/messaging/kafka/producer/MessageProducer.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blogcode.messaging.kafka.producer; 2 | 3 | import lombok.RequiredArgsConstructor; 4 | import org.springframework.kafka.core.KafkaTemplate; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | @RequiredArgsConstructor 9 | public class MessageProducer { 10 | 11 | private final KafkaTemplate producer; 12 | 13 | public void publishMessage(String message) { 14 | producer.send("user-name", message); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /nestjs/nestjs-mongo/src/users/users.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from "@nestjs/common"; 2 | import { MongooseModule } from "@nestjs/mongoose"; 3 | import { User, UserSchema } from "./schemas/user.schema"; 4 | import { UsersController } from "./users.controller"; 5 | import { UsersRepository } from "./users.repository"; 6 | import { UsersService } from "./users.service"; 7 | 8 | @Module({ 9 | imports: [MongooseModule.forFeature([{ name: User.name, schema: UserSchema }])], 10 | controllers: [UsersController], 11 | providers: [UsersService, UsersRepository] 12 | }) 13 | export class UsersModule {} -------------------------------------------------------------------------------- /terraform/sqs-lambda-integration-localstack/lambda/.gitignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist 3 | /node_modules 4 | 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | pnpm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | lerna-debug.log* 13 | 14 | # OS 15 | .DS_Store 16 | 17 | # Tests 18 | /coverage 19 | /.nyc_output 20 | 21 | # IDEs and editors 22 | /.idea 23 | .project 24 | .classpath 25 | .c9/ 26 | *.launch 27 | .settings/ 28 | *.sublime-workspace 29 | 30 | # IDE - VSCode 31 | .vscode/* 32 | !.vscode/settings.json 33 | !.vscode/tasks.json 34 | !.vscode/launch.json 35 | !.vscode/extensions.json -------------------------------------------------------------------------------- /k8s/machine-ip/Deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: machine-ip 5 | labels: 6 | app: machine-ip 7 | spec: 8 | replicas: 1 9 | template: 10 | metadata: 11 | name: machine-ip 12 | labels: 13 | app: machine-ip 14 | spec: 15 | containers: 16 | - name: machine-ip 17 | image: incrediblevicky/machine-ip:0.0.1 18 | imagePullPolicy: IfNotPresent 19 | ports: 20 | - containerPort: 8080 21 | restartPolicy: Always 22 | selector: 23 | matchLabels: 24 | app: machine-ip 25 | -------------------------------------------------------------------------------- /messaging/messaging-kafka/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | spring: 2 | kafka: 3 | consumer: 4 | bootstrap-servers: localhost:9092 5 | auto-offset-reset: earliest 6 | key-deserializer: org.apache.kafka.common.serialization.StringDeserializer 7 | value-deserializer: org.apache.kafka.common.serialization.StringDeserializer 8 | group-id: myApp 9 | producer: 10 | bootstrap-servers: localhost:9092 11 | key-serializer: org.apache.kafka.common.serialization.StringSerializer 12 | value-serializer: org.apache.kafka.common.serialization.StringSerializer 13 | 14 | -------------------------------------------------------------------------------- /nestjs/gcp-storage/src/media/media.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { MediaController } from './media.controller'; 3 | 4 | describe('MediaController', () => { 5 | let controller: MediaController; 6 | 7 | beforeEach(async () => { 8 | const module: TestingModule = await Test.createTestingModule({ 9 | controllers: [MediaController], 10 | }).compile(); 11 | 12 | controller = module.get(MediaController); 13 | }); 14 | 15 | it('should be defined', () => { 16 | expect(controller).toBeDefined(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /react/react-redux/src/redux/store.ts: -------------------------------------------------------------------------------- 1 | import {applyMiddleware, compose, createStore} from "redux"; 2 | import rootReducer from "./rootReducer"; 3 | import immutableStateInvariantMiddleware from "redux-immutable-state-invariant"; 4 | 5 | 6 | export default function configureStore(initialState?: any) { 7 | 8 | // @ts-ignore 9 | const composeEnhancers = 10 | (window).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; // add support for Redux dev tools 11 | 12 | return createStore(rootReducer, 13 | initialState, 14 | composeEnhancers(applyMiddleware(immutableStateInvariantMiddleware()))) 15 | } -------------------------------------------------------------------------------- /react/react-thunk/src/redux/store.ts: -------------------------------------------------------------------------------- 1 | import {applyMiddleware, compose, createStore} from "redux"; 2 | import rootReducer from "./rootReducer"; 3 | import immutableStateInvariantMiddleware from "redux-immutable-state-invariant"; 4 | 5 | 6 | export default function configureStore(initialState?: any) { 7 | 8 | // @ts-ignore 9 | const composeEnhancers = 10 | (window).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; // add support for Redux dev tools 11 | 12 | return createStore(rootReducer, 13 | initialState, 14 | composeEnhancers(applyMiddleware(immutableStateInvariantMiddleware()))) 15 | } -------------------------------------------------------------------------------- /react/first-app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "module": "esnext", 16 | "moduleResolution": "node", 17 | "resolveJsonModule": true, 18 | "isolatedModules": true, 19 | "noEmit": true, 20 | "jsx": "preserve" 21 | }, 22 | "include": [ 23 | "src" 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /react/react-redux/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "module": "esnext", 16 | "moduleResolution": "node", 17 | "resolveJsonModule": true, 18 | "isolatedModules": true, 19 | "noEmit": true, 20 | "jsx": "preserve" 21 | }, 22 | "include": [ 23 | "src" 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /spring/spring-cloud-stream-rabbitmq/publisher/src/main/java/in/kuros/blog/publisher/SpringCloudStreamRabbitmqPubApplication.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blog.publisher; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.scheduling.annotation.EnableScheduling; 6 | 7 | @SpringBootApplication 8 | @EnableScheduling 9 | public class SpringCloudStreamRabbitmqPubApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringCloudStreamRabbitmqPubApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /react/first-app/src/components/common/Header.tsx: -------------------------------------------------------------------------------- 1 | import React, {FunctionComponent} from "react"; 2 | import {NavLink} from "react-router-dom"; 3 | import './Header.css' 4 | 5 | const Header: FunctionComponent = () => { 6 | 7 | const activeStyle = {color: '#F15B2A'} 8 | return ( 9 | 14 | ) 15 | }; 16 | 17 | export default Header; -------------------------------------------------------------------------------- /java/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | in.kuros.blog.code 8 | java 9 | 0.0.1-SNAPSHOT 10 | 11 | 1.8 12 | 1.8 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /react/first-app/src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import * as serviceWorker from './serviceWorker'; 6 | import {BrowserRouter} from "react-router-dom"; 7 | 8 | ReactDOM.render( 9 | 10 | 11 | , 12 | document.getElementById('root')); 13 | 14 | // If you want your app to work offline and load faster, you can change 15 | // unregister() to register() below. Note this comes with some pitfalls. 16 | // Learn more about service workers: https://bit.ly/CRA-PWA 17 | serviceWorker.unregister(); 18 | -------------------------------------------------------------------------------- /spring/spring-security-authentication-provider/src/test/java/in/kuros/blog/code/spring/security/authentication/provider/SpringSecurityAuthenticationProviderApplicationTests.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blog.code.spring.security.authentication.provider; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringSecurityAuthenticationProviderApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /nestjs/nest-auth/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "removeComments": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": true, 9 | "target": "es2017", 10 | "sourceMap": true, 11 | "outDir": "./dist", 12 | "baseUrl": "./", 13 | "incremental": true, 14 | "skipLibCheck": true, 15 | "strictNullChecks": false, 16 | "noImplicitAny": false, 17 | "strictBindCallApply": false, 18 | "forceConsistentCasingInFileNames": false, 19 | "noFallthroughCasesInSwitch": false 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /nestjs/gcp-storage/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "removeComments": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": true, 9 | "target": "es2017", 10 | "sourceMap": true, 11 | "outDir": "./dist", 12 | "baseUrl": "./", 13 | "incremental": true, 14 | "skipLibCheck": true, 15 | "strictNullChecks": false, 16 | "noImplicitAny": false, 17 | "strictBindCallApply": false, 18 | "forceConsistentCasingInFileNames": false, 19 | "noFallthroughCasesInSwitch": false 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /react/first-app/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | animation: App-logo-spin infinite 20s linear; 7 | height: 40vmin; 8 | pointer-events: none; 9 | } 10 | 11 | .App-header { 12 | background-color: #282c34; 13 | min-height: 100vh; 14 | display: flex; 15 | flex-direction: column; 16 | align-items: center; 17 | justify-content: center; 18 | font-size: calc(10px + 2vmin); 19 | color: white; 20 | } 21 | 22 | .App-link { 23 | color: #61dafb; 24 | } 25 | 26 | @keyframes App-logo-spin { 27 | from { 28 | transform: rotate(0deg); 29 | } 30 | to { 31 | transform: rotate(360deg); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /react/react-redux/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | animation: App-logo-spin infinite 20s linear; 7 | height: 40vmin; 8 | pointer-events: none; 9 | } 10 | 11 | .App-header { 12 | background-color: #282c34; 13 | min-height: 100vh; 14 | display: flex; 15 | flex-direction: column; 16 | align-items: center; 17 | justify-content: center; 18 | font-size: calc(10px + 2vmin); 19 | color: white; 20 | } 21 | 22 | .App-link { 23 | color: #61dafb; 24 | } 25 | 26 | @keyframes App-logo-spin { 27 | from { 28 | transform: rotate(0deg); 29 | } 30 | to { 31 | transform: rotate(360deg); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /react/react-thunk/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | animation: App-logo-spin infinite 20s linear; 7 | height: 40vmin; 8 | pointer-events: none; 9 | } 10 | 11 | .App-header { 12 | background-color: #282c34; 13 | min-height: 100vh; 14 | display: flex; 15 | flex-direction: column; 16 | align-items: center; 17 | justify-content: center; 18 | font-size: calc(10px + 2vmin); 19 | color: white; 20 | } 21 | 22 | .App-link { 23 | color: #61dafb; 24 | } 25 | 26 | @keyframes App-logo-spin { 27 | from { 28 | transform: rotate(0deg); 29 | } 30 | to { 31 | transform: rotate(360deg); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring/spring-cloud-stream-rabbitmq/publisher/src/main/java/in/kuros/blog/publisher/Order.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blog.publisher; 2 | 3 | public class Order { 4 | 5 | private String orderNumber; 6 | 7 | public Order() { 8 | } 9 | 10 | public Order(final String orderNumber) { 11 | this.orderNumber = orderNumber; 12 | } 13 | 14 | public void setOrderNumber(final String orderNumber) { 15 | this.orderNumber = orderNumber; 16 | } 17 | 18 | public String getOrderNumber() { 19 | return orderNumber; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return orderNumber; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /react/react-redux/src/components/common/Header.tsx: -------------------------------------------------------------------------------- 1 | import React, {FunctionComponent} from "react"; 2 | import {NavLink} from "react-router-dom"; 3 | import './Header.css' 4 | 5 | const Header: FunctionComponent = () => { 6 | 7 | const activeStyle = {color: '#F15B2A'} 8 | return ( 9 | 16 | ) 17 | }; 18 | 19 | export default Header; -------------------------------------------------------------------------------- /react/react-thunk/src/components/common/Header.tsx: -------------------------------------------------------------------------------- 1 | import React, {FunctionComponent} from "react"; 2 | import {NavLink} from "react-router-dom"; 3 | import './Header.css' 4 | 5 | const Header: FunctionComponent = () => { 6 | 7 | const activeStyle = {color: '#F15B2A'} 8 | return ( 9 | 16 | ) 17 | }; 18 | 19 | export default Header; -------------------------------------------------------------------------------- /nestjs/nest-auth/src/users/users.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { UsersController } from './users.controller'; 3 | import { UsersService } from './users.service'; 4 | 5 | describe('UsersController', () => { 6 | let controller: UsersController; 7 | 8 | beforeEach(async () => { 9 | const module: TestingModule = await Test.createTestingModule({ 10 | controllers: [UsersController], 11 | providers: [UsersService], 12 | }).compile(); 13 | 14 | controller = module.get(UsersController); 15 | }); 16 | 17 | it('should be defined', () => { 18 | expect(controller).toBeDefined(); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /terraform/sqs-lambda-integration-localstack/lambda/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "removeComments": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": true, 9 | "target": "es2017", 10 | "sourceMap": true, 11 | "outDir": "./dist", 12 | "baseUrl": "./", 13 | "incremental": true, 14 | "skipLibCheck": true, 15 | "strictNullChecks": false, 16 | "noImplicitAny": false, 17 | "strictBindCallApply": false, 18 | "forceConsistentCasingInFileNames": false, 19 | "noFallthroughCasesInSwitch": false 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring/spring-cloud-stream-rabbitmq/publisher/src/main/java/in/kuros/blog/publisher/LoggingListener.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blog.publisher; 2 | 3 | import org.springframework.cloud.stream.annotation.EnableBinding; 4 | import org.springframework.cloud.stream.annotation.StreamListener; 5 | import org.springframework.cloud.stream.messaging.Sink; 6 | import org.springframework.messaging.Message; 7 | import org.springframework.stereotype.Component; 8 | 9 | @Component 10 | @EnableBinding(Sink.class) 11 | public class LoggingListener { 12 | 13 | @StreamListener(Sink.INPUT) 14 | public void log(Message orderMessage) { 15 | System.out.println(orderMessage.getPayload()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /spring/spring-security-authentication-provider/src/main/java/in/kuros/controller/UserControllers.java: -------------------------------------------------------------------------------- 1 | package in.kuros.controller; 2 | 3 | import in.kuros.entity.UserEntity; 4 | import in.kuros.repository.UserRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import java.util.List; 10 | 11 | @RestController 12 | public class UserControllers { 13 | 14 | @Autowired 15 | private UserRepository userRepository; 16 | 17 | @GetMapping("/users") 18 | public List getUsers() { 19 | return userRepository.findAll(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /terraform/sqs-lambda-integration-localstack/lambda/src/main.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | exports.handler = async (event, context) => { 4 | const body = {event: event, context: context} 5 | try { 6 | console.log(JSON.stringify(event)); 7 | const axiosResponse = await axios.post(process.env.URL, body); 8 | console.log(JSON.stringify(axiosResponse)); 9 | return { 10 | statusCode: 200, 11 | headers: {'Content-Type': 'application/json'}, 12 | body: axiosResponse.data?.body || axiosResponse.data 13 | } 14 | } catch (e) { 15 | return { 16 | statusCode: 500, 17 | headers: {'Content-Type': 'application/json'}, 18 | body: JSON.stringify(e.message) 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /nestjs/gcp-storage/src/app.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | 5 | describe('AppController', () => { 6 | let appController: AppController; 7 | 8 | beforeEach(async () => { 9 | const app: TestingModule = await Test.createTestingModule({ 10 | controllers: [AppController], 11 | providers: [AppService], 12 | }).compile(); 13 | 14 | appController = app.get(AppController); 15 | }); 16 | 17 | describe('root', () => { 18 | it('should return "Hello World!"', () => { 19 | expect(appController.getHello()).toBe('Hello World!'); 20 | }); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /nestjs/nest-auth/src/app.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | 5 | describe('AppController', () => { 6 | let appController: AppController; 7 | 8 | beforeEach(async () => { 9 | const app: TestingModule = await Test.createTestingModule({ 10 | controllers: [AppController], 11 | providers: [AppService], 12 | }).compile(); 13 | 14 | appController = app.get(AppController); 15 | }); 16 | 17 | describe('root', () => { 18 | it('should return "Hello World!"', () => { 19 | expect(appController.getHello()).toBe('Hello World!'); 20 | }); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /nestjs/nestjs-mongo/src/app.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | 5 | describe('AppController', () => { 6 | let appController: AppController; 7 | 8 | beforeEach(async () => { 9 | const app: TestingModule = await Test.createTestingModule({ 10 | controllers: [AppController], 11 | providers: [AppService], 12 | }).compile(); 13 | 14 | appController = app.get(AppController); 15 | }); 16 | 17 | describe('root', () => { 18 | it('should return "Hello World!"', () => { 19 | expect(appController.getHello()).toBe('Hello World!'); 20 | }); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /nestjs/gcp-storage/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | parserOptions: { 4 | project: 'tsconfig.json', 5 | sourceType: 'module', 6 | }, 7 | plugins: ['@typescript-eslint/eslint-plugin'], 8 | extends: [ 9 | 'plugin:@typescript-eslint/recommended', 10 | 'plugin:prettier/recommended', 11 | ], 12 | root: true, 13 | env: { 14 | node: true, 15 | jest: true, 16 | }, 17 | ignorePatterns: ['.eslintrc.js'], 18 | rules: { 19 | '@typescript-eslint/interface-name-prefix': 'off', 20 | '@typescript-eslint/explicit-function-return-type': 'off', 21 | '@typescript-eslint/explicit-module-boundary-types': 'off', 22 | '@typescript-eslint/no-explicit-any': 'off', 23 | }, 24 | }; 25 | -------------------------------------------------------------------------------- /nestjs/nest-auth/src/users/users.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { CreateUserDto } from './dto/create-user.dto'; 3 | import { UpdateUserDto } from './dto/update-user.dto'; 4 | 5 | @Injectable() 6 | export class UsersService { 7 | create(createUserDto: CreateUserDto) { 8 | return 'This action adds a new user'; 9 | } 10 | 11 | findAll() { 12 | return `This action returns all users`; 13 | } 14 | 15 | findOne(id: number) { 16 | return `This action returns a #${id} user`; 17 | } 18 | 19 | update(id: number, updateUserDto: UpdateUserDto) { 20 | return `This action updates a #${id} user`; 21 | } 22 | 23 | remove(id: number) { 24 | return `This action removes a #${id} user`; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /nestjs/nest-auth/test/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { INestApplication } from '@nestjs/common'; 3 | import * as request from 'supertest'; 4 | import { AppModule } from './../src/app.module'; 5 | 6 | describe('AppController (e2e)', () => { 7 | let app: INestApplication; 8 | 9 | beforeEach(async () => { 10 | const moduleFixture: TestingModule = await Test.createTestingModule({ 11 | imports: [AppModule], 12 | }).compile(); 13 | 14 | app = moduleFixture.createNestApplication(); 15 | await app.init(); 16 | }); 17 | 18 | it('/ (GET)', () => { 19 | return request(app.getHttpServer()) 20 | .get('/') 21 | .expect(200) 22 | .expect('Hello World!'); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /nestjs/gcp-storage/test/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { INestApplication } from '@nestjs/common'; 3 | import * as request from 'supertest'; 4 | import { AppModule } from './../src/app.module'; 5 | 6 | describe('AppController (e2e)', () => { 7 | let app: INestApplication; 8 | 9 | beforeEach(async () => { 10 | const moduleFixture: TestingModule = await Test.createTestingModule({ 11 | imports: [AppModule], 12 | }).compile(); 13 | 14 | app = moduleFixture.createNestApplication(); 15 | await app.init(); 16 | }); 17 | 18 | it('/ (GET)', () => { 19 | return request(app.getHttpServer()) 20 | .get('/') 21 | .expect(200) 22 | .expect('Hello World!'); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /nestjs/nestjs-mongo/test/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { INestApplication } from '@nestjs/common'; 3 | import * as request from 'supertest'; 4 | import { AppModule } from './../src/app.module'; 5 | 6 | describe('AppController (e2e)', () => { 7 | let app: INestApplication; 8 | 9 | beforeEach(async () => { 10 | const moduleFixture: TestingModule = await Test.createTestingModule({ 11 | imports: [AppModule], 12 | }).compile(); 13 | 14 | app = moduleFixture.createNestApplication(); 15 | await app.init(); 16 | }); 17 | 18 | it('/ (GET)', () => { 19 | return request(app.getHttpServer()) 20 | .get('/') 21 | .expect(200) 22 | .expect('Hello World!'); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /spring/spring-security-basics/src/main/java/in/kuros/blog/code/spring/security/basics/entity/Book.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blog.code.spring.security.basics.entity; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | 6 | import javax.persistence.Basic; 7 | import javax.persistence.Column; 8 | import javax.persistence.Entity; 9 | import javax.persistence.GeneratedValue; 10 | import javax.persistence.GenerationType; 11 | import javax.persistence.Id; 12 | import javax.persistence.Table; 13 | 14 | @Entity 15 | @Table 16 | @Getter 17 | @Setter 18 | public class Book { 19 | 20 | @Id 21 | @GeneratedValue(strategy = GenerationType.IDENTITY) 22 | private Integer id; 23 | 24 | @Basic 25 | @Column(name = "name") 26 | private String name; 27 | } 28 | -------------------------------------------------------------------------------- /spring/spring-security-authentication-provider/src/main/java/in/kuros/SpringSecurityAuthenticationProviderApplication.java: -------------------------------------------------------------------------------- 1 | package in.kuros; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.autoconfigure.domain.EntityScan; 6 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 7 | 8 | @SpringBootApplication 9 | @EntityScan(basePackages = "in.kuros.entity") 10 | @EnableJpaRepositories(basePackages = "in.kuros.repository") 11 | public class SpringSecurityAuthenticationProviderApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(SpringSecurityAuthenticationProviderApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /java/src/main/java/in/kuros/blog/code/java/parallel/ParallelExecutionExceptionExample.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blog.code.java.parallel; 2 | 3 | public class ParallelExecutionExceptionExample { 4 | 5 | public static void main(String[] args) { 6 | final ExecutionResult executionResult = ParallelExecution.of(() -> slowService(1)) 7 | .and(() -> { 8 | throw new RuntimeException("Bam!!"); 9 | }) 10 | .and(() -> slowService(3)) 11 | .close(); 12 | 13 | executionResult.get(0); 14 | } 15 | 16 | private static Integer slowService(final int i) { 17 | try { 18 | Thread.sleep(1000); 19 | } catch (InterruptedException e) { 20 | e.printStackTrace(); 21 | } 22 | 23 | return i; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /react/react-redux/src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import * as serviceWorker from './serviceWorker'; 6 | import {BrowserRouter} from "react-router-dom"; 7 | import configureStore from "./redux/store"; 8 | import {Provider as ReduxProvider} from "react-redux"; 9 | 10 | const store = configureStore(); 11 | 12 | ReactDOM.render( 13 | 14 | 15 | 16 | 17 | , 18 | document.getElementById('root')); 19 | 20 | // If you want your app to work offline and load faster, you can change 21 | // unregister() to register() below. Note this comes with some pitfalls. 22 | // Learn more about service workers: https://bit.ly/CRA-PWA 23 | serviceWorker.unregister(); 24 | -------------------------------------------------------------------------------- /react/react-thunk/src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import * as serviceWorker from './serviceWorker'; 6 | import {BrowserRouter} from "react-router-dom"; 7 | import configureStore from "./redux/store"; 8 | import {Provider as ReduxProvider} from "react-redux"; 9 | 10 | const store = configureStore(); 11 | 12 | ReactDOM.render( 13 | 14 | 15 | 16 | 17 | , 18 | document.getElementById('root')); 19 | 20 | // If you want your app to work offline and load faster, you can change 21 | // unregister() to register() below. Note this comes with some pitfalls. 22 | // Learn more about service workers: https://bit.ly/CRA-PWA 23 | serviceWorker.unregister(); 24 | -------------------------------------------------------------------------------- /java/src/main/java/in/kuros/blog/code/java/parallel/ParallelExecutionExample.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blog.code.java.parallel; 2 | 3 | public class ParallelExecutionExample { 4 | 5 | public static void main(String[] args) { 6 | final ExecutionResult executionResult = ParallelExecution.of(() -> slowService(1)) 7 | .and(() -> slowService(2)) 8 | .and(() -> slowService(3)) 9 | .close(); 10 | 11 | int val = executionResult.get(0); 12 | int val2 = executionResult.get(1); 13 | int val3 = executionResult.get(2); 14 | 15 | System.out.println(val + val2 + val3); 16 | } 17 | 18 | private static Integer slowService(final int i) { 19 | try { 20 | Thread.sleep(1000); 21 | } catch (InterruptedException e) { 22 | e.printStackTrace(); 23 | } 24 | 25 | return i; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /messaging/messaging-kafka/src/main/java/in/kuros/blogcode/messaging/kafka/controller/KafkaController.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blogcode.messaging.kafka.controller; 2 | 3 | import in.kuros.blogcode.messaging.kafka.producer.MessageProducer; 4 | import lombok.RequiredArgsConstructor; 5 | import org.springframework.web.bind.annotation.PostMapping; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestParam; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | @RestController 11 | @RequestMapping(value = "/kafka") 12 | @RequiredArgsConstructor 13 | public class KafkaController { 14 | 15 | private final MessageProducer messageProducer; 16 | 17 | @PostMapping(value = "/publish") 18 | public void sendMessageToKafkaTopic(@RequestParam("message") String message) { 19 | this.messageProducer.publishMessage(message); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /react/first-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "first-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@types/bootstrap": "^4.3.0", 7 | "@types/jest": "24.0.11", 8 | "@types/node": "11.11.3", 9 | "@types/react": "16.8.8", 10 | "@types/react-dom": "16.8.2", 11 | "@types/react-router-dom": "^4.3.1", 12 | "bootstrap": "^4.3.1", 13 | "react": "^16.8.4", 14 | "react-dom": "^16.8.4", 15 | "react-router-dom": "^4.4.0", 16 | "react-scripts": "2.1.8", 17 | "typescript": "3.3.3333" 18 | }, 19 | "scripts": { 20 | "start": "react-scripts start", 21 | "build": "react-scripts build", 22 | "test": "react-scripts test", 23 | "eject": "react-scripts eject" 24 | }, 25 | "eslintConfig": { 26 | "extends": "react-app" 27 | }, 28 | "browserslist": [ 29 | ">0.2%", 30 | "not dead", 31 | "not ie <= 11", 32 | "not op_mini all" 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /spring/spring-cloud-stream-rabbitmq/publisher/src/main/java/in/kuros/blog/publisher/OrderPublisher.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blog.publisher; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.cloud.stream.annotation.EnableBinding; 5 | import org.springframework.cloud.stream.messaging.Source; 6 | import org.springframework.messaging.Message; 7 | import org.springframework.messaging.support.MessageBuilder; 8 | import org.springframework.scheduling.annotation.Scheduled; 9 | import org.springframework.stereotype.Component; 10 | 11 | @Component 12 | @EnableBinding(Source.class) 13 | public class OrderPublisher { 14 | 15 | @Autowired Source source; 16 | 17 | @Scheduled(fixedDelay = 10000) 18 | public void publishOrder() { 19 | final Message message = MessageBuilder.withPayload(new Order("Order Number: " + System.currentTimeMillis())).build(); 20 | source.output().send(message); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /spring/spring-security-basics/src/main/java/in/kuros/blog/code/spring/security/basics/controller/BookController.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blog.code.spring.security.basics.controller; 2 | 3 | import in.kuros.blog.code.spring.security.basics.entity.Book; 4 | import in.kuros.blog.code.spring.security.basics.repository.BookRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import java.util.List; 10 | 11 | @RestController 12 | public class BookController { 13 | 14 | private final BookRepository bookRepository; 15 | 16 | @Autowired 17 | public BookController(final BookRepository bookRepository) { 18 | this.bookRepository = bookRepository; 19 | } 20 | 21 | @GetMapping(path = "books") 22 | public List getBooks() { 23 | return bookRepository.findAll(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /nestjs/nest-auth/src/users/roles.guard.ts: -------------------------------------------------------------------------------- 1 | import { Injectable,CanActivate,ExecutionContext } from "@nestjs/common"; 2 | import { Reflector } from "@nestjs/core"; 3 | import { Observable } from "rxjs"; 4 | import { Role } from "./entities/role.enum"; 5 | import { User } from "./entities/user.entity"; 6 | @Injectable() 7 | export class RolesGuard implements CanActivate{ 8 | constructor(private reflector:Reflector){} 9 | canActivate(context: ExecutionContext): boolean { 10 | const requireRoles=this.reflector.getAllAndOverride('roles',[ 11 | context.getHandler(), 12 | context.getClass(), 13 | ]); 14 | 15 | if (!requireRoles){ 16 | return true; 17 | } 18 | //const {user}=context.switchToHttp().getRequest(); 19 | const user:User={ 20 | name:'Nishant', 21 | roles:[Role.USER] 22 | } 23 | return requireRoles.some(role=>user.roles.includes(role)); 24 | } 25 | } -------------------------------------------------------------------------------- /react/first-app/src/App.tsx: -------------------------------------------------------------------------------- 1 | import React, {Component} from 'react'; 2 | import './App.css'; 3 | import HomePage from "./components/home/HomePage"; 4 | import {Route, Switch} from "react-router-dom"; 5 | import AboutPage from "./components/about/AboutPage"; 6 | import 'bootstrap/dist/css/bootstrap.min.css'; 7 | import Header from "./components/common/Header"; 8 | import NotFoundPage from "./NotFoundPage"; 9 | import BookPage from "./components/book/BookPage"; 10 | 11 | class App extends Component { 12 | render() { 13 | return ( 14 |
15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | ); 24 | } 25 | } 26 | 27 | export default App; 28 | -------------------------------------------------------------------------------- /spring/spring-security-authentication-provider/src/main/java/in/kuros/controller/BookController.java: -------------------------------------------------------------------------------- 1 | package in.kuros.controller; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | @RestController 10 | public class BookController { 11 | 12 | @GetMapping("/books") 13 | public List getBooks() { 14 | final List books = new ArrayList<>(); 15 | books.add("A Little Forever"); 16 | books.add("To Kill a Mockingbird"); 17 | books.add("A Thousand Splendid Suns"); 18 | 19 | return books; 20 | } 21 | 22 | @GetMapping("/secured/books") 23 | public List securedBooks() { 24 | final List books = new ArrayList<>(); 25 | books.add("Harry Potter and the Philosopher's Stone"); 26 | books.add("Harry Potter and the Chamber of Secrets"); 27 | 28 | return books; 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /nestjs/nestjs-mongo/src/users/users.repository.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from "@nestjs/common"; 2 | import { InjectModel } from "@nestjs/mongoose"; 3 | import { FilterQuery, Model } from "mongoose"; 4 | import { User, UserDocument } from "./schemas/user.schema"; 5 | @Injectable() 6 | export class UsersRepository { 7 | constructor(@InjectModel(User.name) private userModel: Model) {} 8 | async findOne(userFilterQuery: FilterQuery): Promise { 9 | return this.userModel.findOne(userFilterQuery); 10 | } 11 | 12 | async find(usersFilterQuery: FilterQuery): Promise { 13 | return this.userModel.find(usersFilterQuery) 14 | } 15 | 16 | async create(user: User): Promise { 17 | const newUser = new this.userModel(user); 18 | return newUser.save() 19 | } 20 | 21 | async findOneAndUpdate(userFilterQuery: FilterQuery, user: Partial): Promise { 22 | return this.userModel.findOneAndUpdate(userFilterQuery, user, { new: true }); 23 | } 24 | } -------------------------------------------------------------------------------- /react/react-redux/src/App.tsx: -------------------------------------------------------------------------------- 1 | import React, {Component} from 'react'; 2 | import './App.css'; 3 | import HomePage from "./components/home/HomePage"; 4 | import {Route, Switch} from "react-router-dom"; 5 | import AboutPage from "./components/about/AboutPage"; 6 | import 'bootstrap/dist/css/bootstrap.min.css'; 7 | import Header from "./components/common/Header"; 8 | import BookPage from "./components/book/BookPage"; 9 | import NotFoundPage from "./NotFoundPage"; 10 | 11 | class App extends Component { 12 | render() { 13 | return ( 14 |
15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | ); 24 | } 25 | } 26 | 27 | export default App; 28 | -------------------------------------------------------------------------------- /react/react-thunk/src/App.tsx: -------------------------------------------------------------------------------- 1 | import React, {Component} from 'react'; 2 | import './App.css'; 3 | import HomePage from "./components/home/HomePage"; 4 | import {Route, Switch} from "react-router-dom"; 5 | import AboutPage from "./components/about/AboutPage"; 6 | import 'bootstrap/dist/css/bootstrap.min.css'; 7 | import Header from "./components/common/Header"; 8 | import BookPage from "./components/book/BookPage"; 9 | import NotFoundPage from "./NotFoundPage"; 10 | 11 | class App extends Component { 12 | render() { 13 | return ( 14 |
15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | ); 24 | } 25 | } 26 | 27 | export default App; 28 | -------------------------------------------------------------------------------- /nestjs/nestjs-mongo/src/users/users.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from "@nestjs/common"; 2 | import { v4 as uuidv4 } from 'uuid'; 3 | import { UpdateUserDto } from "./dto/update-user.dto"; 4 | import { User } from "./schemas/user.schema"; 5 | import { UsersRepository } from "./users.repository"; 6 | @Injectable() 7 | export class UsersService { 8 | constructor(private readonly usersRepository: UsersRepository) {} 9 | async getUserById(userId: string): Promise { 10 | return this.usersRepository.findOne({ userId }) 11 | } 12 | async getUsers(): Promise { 13 | return this.usersRepository.find({}); 14 | } 15 | async createUser(email: string, age: number): Promise { 16 | return this.usersRepository.create({ 17 | userId: uuidv4(), 18 | email, 19 | age, 20 | favoriteFoods: [] 21 | }) 22 | } 23 | async updateUser(userId: string, userUpdates: UpdateUserDto): Promise { 24 | return this.usersRepository.findOneAndUpdate({ userId }, userUpdates); 25 | } 26 | } -------------------------------------------------------------------------------- /java/src/main/java/in/kuros/blog/code/java/streams/CustomCollector.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blog.code.java.streams; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashSet; 5 | import java.util.List; 6 | import java.util.Set; 7 | import java.util.stream.Collector; 8 | import java.util.stream.IntStream; 9 | 10 | public class CustomCollector { 11 | 12 | public static Collector, List> unique() { 13 | return Collector.of( 14 | HashSet::new, 15 | Set::add, 16 | (result1, result2) -> { 17 | result1.addAll(result2); 18 | return result1; 19 | }, 20 | ArrayList::new, 21 | Collector.Characteristics.CONCURRENT, 22 | Collector.Characteristics.UNORDERED); 23 | } 24 | 25 | 26 | public static void main(String[] args) { 27 | final List result = IntStream.of(1, 2, 3, 4, 3, 4, 5) 28 | .boxed() 29 | .collect(CustomCollector.unique()); 30 | 31 | System.out.println(result); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /k8s/machine-ip/src/main/java/in/kuros/k8s/machineip/rest/IpController.java: -------------------------------------------------------------------------------- 1 | package in.kuros.k8s.machineip.rest; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | import java.net.InetAddress; 7 | import java.net.UnknownHostException; 8 | 9 | @RestController 10 | public class IpController { 11 | 12 | @GetMapping(path = "/ip") 13 | public ResponseModel getIp() throws UnknownHostException { 14 | InetAddress inetAddress = InetAddress.getLocalHost(); 15 | return new ResponseModel(inetAddress.getHostAddress(), inetAddress.getHostName()); 16 | } 17 | 18 | private class ResponseModel { 19 | private final String ip; 20 | private final String hostname; 21 | 22 | public ResponseModel(final String ip, final String hostname) { 23 | this.ip = ip; 24 | this.hostname = hostname; 25 | } 26 | 27 | public String getIp() { 28 | return ip; 29 | } 30 | 31 | public String getHostname() { 32 | return hostname; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /nestjs/nestjs-mongo/src/users/users.controller.ts: -------------------------------------------------------------------------------- 1 | import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'; 2 | import { CreateUserDto } from './dto/create-user.dto'; 3 | import { UpdateUserDto } from './dto/update-user.dto'; 4 | 5 | import { User } from './schemas/user.schema'; 6 | import { UsersService } from './users.service'; 7 | 8 | @Controller('users') 9 | export class UsersController { 10 | constructor(private readonly usersService: UsersService) {} 11 | 12 | @Get(':userId') 13 | async getUser(@Param('userId') userId: string): Promise { 14 | return this.usersService.getUserById(userId); 15 | } 16 | 17 | @Get() 18 | async getUsers(): Promise { 19 | return this.usersService.getUsers(); 20 | } 21 | 22 | @Post() 23 | async createUser(@Body() createUserDto: CreateUserDto): Promise { 24 | return this.usersService.createUser(createUserDto.email, createUserDto.age) 25 | } 26 | 27 | @Patch(':userId') 28 | async updateUser(@Param('userId') userId: string, @Body() updateUserDto: UpdateUserDto): Promise { 29 | return this.usersService.updateUser(userId, updateUserDto); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /java/src/main/java/in/kuros/blog/code/java/parallel/CompletableFutureExample.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blog.code.java.parallel; 2 | 3 | import java.util.concurrent.CompletableFuture; 4 | import java.util.concurrent.ExecutionException; 5 | 6 | public class CompletableFutureExample { 7 | 8 | public static void main(final String[] args) throws ExecutionException, InterruptedException { 9 | 10 | final CompletableFuture service1 = CompletableFuture.supplyAsync(() -> slowService(1)); 11 | final CompletableFuture service2 = CompletableFuture.supplyAsync(() -> slowService(2)); 12 | final CompletableFuture service3 = CompletableFuture.supplyAsync(() -> slowService(3)); 13 | 14 | CompletableFuture.allOf(service1, service2, service3).get(); 15 | 16 | final int value = service1.get() + service2.get() + service3.get(); 17 | 18 | System.out.println(value); 19 | } 20 | 21 | private static Integer slowService(final int i) { 22 | try { 23 | Thread.sleep(1000); 24 | } catch (InterruptedException e) { 25 | e.printStackTrace(); 26 | } 27 | 28 | return i; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /terraform/sqs-lambda-integration-localstack/lambda/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lamda", 3 | "version": "0.0.1", 4 | "description": "", 5 | "main": "main.js", 6 | "scripts": { 7 | "tsc": "tsc -p tsconfig.json && tsc -p tsconfig.build.json", 8 | "prebuild": "rimraf dist", 9 | "build": "npm run tsc", 10 | "test": "echo \"Error: no test specified\" && exit 1" 11 | }, 12 | "author": "", 13 | "license": "ISC", 14 | "devDependencies": { 15 | "@types/jest": "^29.1.1", 16 | "@types/node": "^18.8.1", 17 | "@types/supertest": "^2.0.12", 18 | "jest": "^29.1.2", 19 | "rimraf": "^3.0.2", 20 | "supertest": "^6.3.0", 21 | "ts-jest": "^29.0.3", 22 | "ts-mockito": "^2.6.1", 23 | "typescript": "^4.8.4" 24 | }, 25 | "dependencies": { 26 | "axios": "^0.27.2" 27 | }, 28 | "jest": { 29 | "moduleFileExtensions": [ 30 | "js", 31 | "json", 32 | "ts" 33 | ], 34 | "rootDir": "src", 35 | "testRegex": ".*\\.spec\\.ts$", 36 | "transform": { 37 | "^.+\\.(t|j)s$": "ts-jest" 38 | }, 39 | "collectCoverageFrom": [ 40 | "**/*.(t|j)s" 41 | ], 42 | "coverageDirectory": "../coverage", 43 | "testEnvironment": "node" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /react/react-redux/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kuros-react-redux", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@types/bootstrap": "^4.3.0", 7 | "@types/jest": "24.0.11", 8 | "@types/node": "11.11.3", 9 | "@types/react": "16.8.8", 10 | "@types/react-dom": "16.8.2", 11 | "@types/react-redux": "^7.0.5", 12 | "@types/react-router-dom": "^4.3.1", 13 | "@types/redux-immutable-state-invariant": "^2.1.0", 14 | "bootstrap": "^4.3.1", 15 | "react": "^16.8.4", 16 | "react-dom": "^16.8.4", 17 | "react-redux": "^6.0.1", 18 | "react-router-dom": "^5.0.0", 19 | "react-scripts": "2.1.8", 20 | "redux-immutable-state-invariant": "^2.1.0", 21 | "typescript": "3.3.3333" 22 | }, 23 | "scripts": { 24 | "start": "react-scripts start", 25 | "build": "react-scripts build", 26 | "test": "react-scripts test", 27 | "eject": "react-scripts eject" 28 | }, 29 | "eslintConfig": { 30 | "extends": "react-app" 31 | }, 32 | "browserslist": [ 33 | ">0.2%", 34 | "not dead", 35 | "not ie <= 11", 36 | "not op_mini all" 37 | ], 38 | "devDependencies": { 39 | "@types/redux-devtools": "^3.0.46", 40 | "redux-devtools": "^3.5.0" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /terraform/fix-lambda-localstack/lambda.tf: -------------------------------------------------------------------------------- 1 | resource "aws_iam_role" "iam_for_lambda_fix" { 2 | name = "iam_for_lambda_fix" 3 | 4 | assume_role_policy = < 2 | 5 | 4.0.0 6 | 7 | in.kuros.blog 8 | greenmail 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | 14 | javax.mail 15 | mail 16 | 1.4.5 17 | 18 | 19 | javax.activation 20 | activation 21 | 1.1 22 | 23 | 24 | org.projectlombok 25 | lombok 26 | 1.18.12 27 | provided 28 | 29 | 30 | com.icegreen 31 | greenmail 32 | 1.5.8 33 | test 34 | 35 | 36 | 37 | junit 38 | junit 39 | 4.13 40 | test 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /spring/spring-security-authentication-provider/src/main/java/in/kuros/config/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package in.kuros.config; 2 | 3 | import in.kuros.custom.CustomAuthenticationProvider; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 7 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 8 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 9 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 10 | 11 | @Configuration 12 | @EnableGlobalMethodSecurity(prePostEnabled = true) 13 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 14 | 15 | @Autowired private CustomAuthenticationProvider customAuthenticationProvider; 16 | 17 | @Override 18 | protected void configure(final HttpSecurity http) throws Exception { 19 | http 20 | .headers() 21 | .frameOptions().sameOrigin(); 22 | 23 | http 24 | .csrf() 25 | .disable(); 26 | 27 | http 28 | .authorizeRequests() 29 | .antMatchers("/books").permitAll() 30 | .antMatchers("/secured/**").authenticated(); 31 | http 32 | .formLogin(); 33 | } 34 | 35 | @Override 36 | protected void configure(final AuthenticationManagerBuilder auth) throws Exception { 37 | auth.authenticationProvider(customAuthenticationProvider); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /k8s/machine-ip/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.2.RELEASE 9 | 10 | 11 | in.kuros.k8s 12 | machine-ip 13 | 0.0.1 14 | machine-ip 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | kuros 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-test 31 | test 32 | 33 | 34 | 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-maven-plugin 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /spring/spring-security-authentication-provider/src/main/java/in/kuros/entity/UserEntity.java: -------------------------------------------------------------------------------- 1 | package in.kuros.entity; 2 | 3 | import javax.persistence.Basic; 4 | import javax.persistence.Column; 5 | import javax.persistence.Entity; 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.GenerationType; 8 | import javax.persistence.Id; 9 | import javax.persistence.OneToMany; 10 | import javax.persistence.Table; 11 | import java.util.List; 12 | 13 | @Entity 14 | @Table(name = "users") 15 | public class UserEntity { 16 | 17 | @Id 18 | @Column(name = "id") 19 | @GeneratedValue(strategy = GenerationType.IDENTITY) 20 | private Integer id; 21 | 22 | @Basic 23 | @Column(name = "user_name") 24 | private String userName; 25 | 26 | @Basic 27 | @Column(name = "password") 28 | private String password; 29 | 30 | @OneToMany(mappedBy = "user") 31 | private List userRoles; 32 | 33 | public Integer getId() { 34 | return id; 35 | } 36 | 37 | public void setId(final Integer id) { 38 | this.id = id; 39 | } 40 | 41 | public String getUserName() { 42 | return userName; 43 | } 44 | 45 | public void setUserName(final String userName) { 46 | this.userName = userName; 47 | } 48 | 49 | public String getPassword() { 50 | return password; 51 | } 52 | 53 | public void setPassword(final String password) { 54 | this.password = password; 55 | } 56 | 57 | public List getUserRoles() { 58 | return userRoles; 59 | } 60 | 61 | public void setUserRoles(final List userRoles) { 62 | this.userRoles = userRoles; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /react/first-app/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 15 | 16 | 25 | React App 26 | 27 | 28 | 29 |
30 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /spring/spring-security-authentication-provider/src/main/java/in/kuros/custom/User.java: -------------------------------------------------------------------------------- 1 | package in.kuros.custom; 2 | 3 | import in.kuros.entity.UserEntity; 4 | import in.kuros.entity.UserRoles; 5 | import org.springframework.security.core.GrantedAuthority; 6 | import org.springframework.security.core.userdetails.UserDetails; 7 | 8 | import java.util.Collection; 9 | import java.util.List; 10 | import java.util.stream.Collectors; 11 | 12 | public class User implements UserDetails { 13 | 14 | private String username; 15 | private List roles; 16 | 17 | public User(final UserEntity userEntity) { 18 | this.username = userEntity.getUserName(); 19 | this.roles = userEntity 20 | .getUserRoles() 21 | .stream() 22 | .map(UserRoles::getRole) 23 | .collect(Collectors.toList()); 24 | } 25 | 26 | @Override 27 | public Collection getAuthorities() { 28 | return roles 29 | .stream() 30 | .map(role -> (GrantedAuthority) () -> role) 31 | .collect(Collectors.toList()); 32 | } 33 | 34 | @Override 35 | public String getPassword() { 36 | return null; 37 | } 38 | 39 | @Override 40 | public String getUsername() { 41 | return username; 42 | } 43 | 44 | @Override 45 | public boolean isAccountNonExpired() { 46 | return true; 47 | } 48 | 49 | @Override 50 | public boolean isAccountNonLocked() { 51 | return true; 52 | } 53 | 54 | @Override 55 | public boolean isCredentialsNonExpired() { 56 | return true; 57 | } 58 | 59 | @Override 60 | public boolean isEnabled() { 61 | return true; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /nestjs/gcp-storage/src/media/media.controller.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Body, 3 | Controller, 4 | Get, 5 | NotFoundException, 6 | Param, 7 | Post, 8 | Res, 9 | ServiceUnavailableException, 10 | UploadedFile, 11 | UseInterceptors, 12 | } from '@nestjs/common'; 13 | import { FileInterceptor } from '@nestjs/platform-express'; 14 | import { Response } from 'express'; 15 | import { StorageFile } from 'src/storage/storage-file'; 16 | import { StorageService } from 'src/storage/storage.service'; 17 | 18 | @Controller('media') 19 | export class MediaController { 20 | constructor(private storageService: StorageService) {} 21 | 22 | @Post() 23 | @UseInterceptors( 24 | FileInterceptor('file', { 25 | limits: { 26 | files: 1, 27 | fileSize: 1024 * 1024, 28 | }, 29 | }), 30 | ) 31 | async uploadMedia( 32 | @UploadedFile() file: Express.Multer.File, 33 | @Body('mediaId') mediaId: string, 34 | ) { 35 | await this.storageService.save( 36 | 'media/' + mediaId, 37 | file.mimetype, 38 | file.buffer, 39 | [{ mediaId: mediaId }], 40 | ); 41 | } 42 | 43 | @Get('/:mediaId') 44 | async downloadMedia(@Param('mediaId') mediaId: string, @Res() res: Response) { 45 | let storageFile: StorageFile; 46 | try { 47 | storageFile = await this.storageService.get('media/' + mediaId); 48 | } catch (e) { 49 | if (e.message.toString().includes('No such object')) { 50 | throw new NotFoundException('image not found'); 51 | } else { 52 | throw new ServiceUnavailableException('internal error'); 53 | } 54 | } 55 | res.setHeader('Content-Type', storageFile.contentType); 56 | res.setHeader('Cache-Control', 'max-age=60d'); 57 | res.end(storageFile.buffer); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /react/react-redux/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 15 | 16 | 25 | React App 26 | 27 | 28 | 29 |
30 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /react/react-thunk/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 15 | 16 | 25 | React App 26 | 27 | 28 | 29 |
30 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /testing/greenmail/src/test/java/in/kuros/MailSenderTest.java: -------------------------------------------------------------------------------- 1 | package in.kuros; 2 | 3 | import com.icegreen.greenmail.util.GreenMail; 4 | import com.icegreen.greenmail.util.ServerSetup; 5 | import org.junit.After; 6 | import org.junit.Assert; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | import javax.mail.internet.MimeMessage; 11 | 12 | public class MailSenderTest { 13 | 14 | private GreenMail greenMailServer; 15 | private MailSender mailSender; 16 | 17 | @Before 18 | public void setUp() { 19 | greenMailServer = new GreenMail(new ServerSetup(9000, "localhost", ServerSetup.PROTOCOL_SMTP)); 20 | greenMailServer.start(); 21 | 22 | mailSender = new MailSender(); 23 | } 24 | 25 | @Test 26 | public void shouldSendMailToEmailServer() throws Exception { 27 | final String fromUser = "foo@test.com"; 28 | final String toUser = "foo@test.com"; 29 | greenMailServer.setUser(fromUser, fromUser); 30 | greenMailServer.setUser(toUser, toUser); 31 | 32 | final ServerInfo serverInfo = new ServerInfo("localhost", "9000"); 33 | final String subject = "this is the subject"; 34 | final String message = "this is message body"; 35 | final MailContext mailContext = new MailContext(fromUser, toUser, subject, message); 36 | mailSender.sendMail(serverInfo, mailContext); 37 | 38 | final MimeMessage[] receivedMessages = greenMailServer.getReceivedMessages(); 39 | Assert.assertEquals(1, receivedMessages.length); 40 | Assert.assertEquals(subject, receivedMessages[0].getSubject()); 41 | Assert.assertEquals(message , String.valueOf(receivedMessages[0].getContent()).trim()); 42 | 43 | 44 | } 45 | 46 | @After 47 | public void tearDown() { 48 | greenMailServer.start(); 49 | } 50 | } -------------------------------------------------------------------------------- /java/src/main/java/in/kuros/blog/code/java/parallel/ParallelExecution.java: -------------------------------------------------------------------------------- 1 | package in.kuros.blog.code.java.parallel; 2 | 3 | import java.util.concurrent.CompletableFuture; 4 | import java.util.function.BiFunction; 5 | import java.util.function.Supplier; 6 | import java.util.stream.Collectors; 7 | import java.util.stream.Stream; 8 | 9 | public final class ParallelExecution { 10 | 11 | private Stream futureStream; 12 | 13 | private ParallelExecution(final CompletableFuture completableFuture) { 14 | this(Stream.of(completableFuture)); 15 | } 16 | 17 | private ParallelExecution(final Stream futureStream) { 18 | this.futureStream = futureStream; 19 | } 20 | 21 | public static ParallelExecution of(final Supplier supplier) { 22 | return new ParallelExecution(CompletableFuture.supplyAsync(supplier)); 23 | } 24 | 25 | public static ParallelExecution of(final Supplier supplier, final BiFunction errorHandler) { 26 | return new ParallelExecution(CompletableFuture.supplyAsync(supplier).handle(errorHandler)); 27 | } 28 | 29 | public ParallelExecution and(final Supplier supplier) { 30 | final Stream stream = Stream.of(CompletableFuture.supplyAsync(supplier)); 31 | return new ParallelExecution(Stream.concat(futureStream, stream)); 32 | } 33 | 34 | public ParallelExecution and(final Supplier supplier, final BiFunction errorHandler) { 35 | final Stream stream = Stream.of(CompletableFuture.supplyAsync(supplier).handle(errorHandler)); 36 | return new ParallelExecution(Stream.concat(futureStream, stream)); 37 | } 38 | 39 | public ExecutionResult close() { 40 | return new ExecutionResult(futureStream 41 | .map(CompletableFuture::join) 42 | .collect(Collectors.toList())); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /react/react-redux/src/components/book/BookPage.tsx: -------------------------------------------------------------------------------- 1 | import React, {ChangeEvent, Component, FormEvent, ReactNode} from "react"; 2 | import {connect} from "react-redux"; 3 | import {createBook} from "../../redux/book/bookAction"; 4 | 5 | class BookPage extends Component { 6 | 7 | state = {book: {title: '', author: ''}}; 8 | 9 | render(): ReactNode { 10 | return ( 11 |
12 |
13 |

Books

14 |

Add Books

15 | 19 | 20 | 21 | 22 | { 23 | this.props 24 | .books 25 | .map(book => ( 26 |
{book.title}
27 | )) 28 | } 29 |
30 |
31 | ); 32 | } 33 | 34 | private handleChange = (event: ChangeEvent) => { 35 | const book:Book = { ...this.state.book, title: event.target.value}; 36 | this.setState({ book }); 37 | }; 38 | 39 | private handleSubmit = (event: FormEvent) => { 40 | event.preventDefault(); 41 | this.props.createBook(this.state.book); 42 | } 43 | } 44 | 45 | interface BookProps { 46 | createBook(book: Book): void; 47 | books: Book[]; 48 | } 49 | 50 | export interface BookState { 51 | book: Book; 52 | } 53 | 54 | export interface Book { 55 | title: string, 56 | author: string 57 | } 58 | 59 | export interface BookStoreState { 60 | books: Book[] 61 | } 62 | 63 | function mapStateToProps(state: BookStoreState) { 64 | return { 65 | books: state.books 66 | } 67 | } 68 | 69 | const mapDispatchToProps = { 70 | createBook: createBook 71 | }; 72 | 73 | export default connect(mapStateToProps, mapDispatchToProps)(BookPage); -------------------------------------------------------------------------------- /react/react-thunk/src/components/book/BookPage.tsx: -------------------------------------------------------------------------------- 1 | import React, {ChangeEvent, Component, FormEvent, ReactNode} from "react"; 2 | import {connect} from "react-redux"; 3 | import {createBook} from "../../redux/book/bookAction"; 4 | 5 | class BookPage extends Component { 6 | 7 | state = {book: {title: '', author: ''}}; 8 | 9 | render(): ReactNode { 10 | return ( 11 |
12 |
13 |

Books

14 |

Add Books

15 | 19 | 20 | 21 | 22 | { 23 | this.props 24 | .books 25 | .map(book => ( 26 |
{book.title}
27 | )) 28 | } 29 |
30 |
31 | ); 32 | } 33 | 34 | private handleChange = (event: ChangeEvent) => { 35 | const book:Book = { ...this.state.book, title: event.target.value}; 36 | this.setState({ book }); 37 | }; 38 | 39 | private handleSubmit = (event: FormEvent) => { 40 | event.preventDefault(); 41 | this.props.createBook(this.state.book); 42 | } 43 | } 44 | 45 | interface BookProps { 46 | createBook(book: Book): void; 47 | books: Book[]; 48 | } 49 | 50 | export interface BookState { 51 | book: Book; 52 | } 53 | 54 | export interface Book { 55 | title: string, 56 | author: string 57 | } 58 | 59 | export interface BookStoreState { 60 | books: Book[] 61 | } 62 | 63 | function mapStateToProps(state: BookStoreState) { 64 | return { 65 | books: state.books 66 | } 67 | } 68 | 69 | const mapDispatchToProps = { 70 | createBook: createBook 71 | }; 72 | 73 | export default connect(mapStateToProps, mapDispatchToProps)(BookPage); -------------------------------------------------------------------------------- /react/first-app/README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `npm start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `npm test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `npm run build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `npm run eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 35 | 36 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 37 | 38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | -------------------------------------------------------------------------------- /react/react-redux/README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `npm start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `npm test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `npm run build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `npm run eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 35 | 36 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 37 | 38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | -------------------------------------------------------------------------------- /react/react-thunk/README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `npm start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `npm test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `npm run build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `npm run eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 35 | 36 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 37 | 38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | -------------------------------------------------------------------------------- /messaging/messaging-kafka/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.4.RELEASE 9 | 10 | 11 | in.kuros.blog-code 12 | messaging-kafka 13 | 0.0.1-SNAPSHOT 14 | messaging-kafka 15 | Demo project for Spring Boot 16 | 17 | 18 | 11 19 | 20 | 21 | 22 | 23 | org.springframework.kafka 24 | spring-kafka 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | org.projectlombok 32 | lombok 33 | provided 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-test 39 | test 40 | 41 | 42 | org.junit.vintage 43 | junit-vintage-engine 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-maven-plugin 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /nestjs/nestjs-mongo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nestjs-mongo", 3 | "version": "0.0.1", 4 | "description": "", 5 | "author": "", 6 | "private": true, 7 | "license": "UNLICENSED", 8 | "scripts": { 9 | "prebuild": "rimraf dist", 10 | "build": "nest build", 11 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", 12 | "start": "nest start", 13 | "start:dev": "nest start --watch", 14 | "start:debug": "nest start --debug --watch", 15 | "start:prod": "node dist/main", 16 | "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", 17 | "test": "jest", 18 | "test:watch": "jest --watch", 19 | "test:cov": "jest --coverage", 20 | "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", 21 | "test:e2e": "jest --config ./test/jest-e2e.json" 22 | }, 23 | "dependencies": { 24 | "@nestjs/common": "^7.0.0", 25 | "@nestjs/core": "^7.0.0", 26 | "@nestjs/mongoose": "^7.2.3", 27 | "@nestjs/platform-express": "^7.0.0", 28 | "mongoose": "^5.11.17", 29 | "reflect-metadata": "^0.1.13", 30 | "rimraf": "^3.0.2", 31 | "rxjs": "^6.5.4", 32 | "uuid": "^8.3.2" 33 | }, 34 | "devDependencies": { 35 | "@nestjs/cli": "^7.0.0", 36 | "@nestjs/schematics": "^7.0.0", 37 | "@nestjs/testing": "^7.0.0", 38 | "@types/express": "^4.17.3", 39 | "@types/jest": "25.2.3", 40 | "@types/node": "^13.9.1", 41 | "@types/supertest": "^2.0.8", 42 | "@typescript-eslint/eslint-plugin": "3.0.2", 43 | "@typescript-eslint/parser": "3.0.2", 44 | "eslint": "7.1.0", 45 | "eslint-config-prettier": "^6.10.0", 46 | "eslint-plugin-import": "^2.20.1", 47 | "jest": "26.0.1", 48 | "prettier": "^1.19.1", 49 | "supertest": "^4.0.2", 50 | "ts-jest": "26.1.0", 51 | "ts-loader": "^6.2.1", 52 | "ts-node": "^8.6.2", 53 | "tsconfig-paths": "^3.9.0", 54 | "typescript": "^3.7.4" 55 | }, 56 | "jest": { 57 | "moduleFileExtensions": [ 58 | "js", 59 | "json", 60 | "ts" 61 | ], 62 | "rootDir": "src", 63 | "testRegex": ".spec.ts$", 64 | "transform": { 65 | "^.+\\.(t|j)s$": "ts-jest" 66 | }, 67 | "coverageDirectory": "../coverage", 68 | "testEnvironment": "node" 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /nestjs/gcp-storage/src/storage/storage.service.ts: -------------------------------------------------------------------------------- 1 | import {StorageFile} from "./storage-file"; 2 | import {DownloadResponse, Storage} from "@google-cloud/storage"; 3 | import {Injectable} from "@nestjs/common"; 4 | import StorageConfig from "./storage-config"; 5 | 6 | @Injectable() 7 | export class StorageService { 8 | 9 | private storage: Storage; 10 | private bucket: string; 11 | 12 | constructor() { 13 | this.storage = new Storage({ 14 | projectId: StorageConfig.projectId, 15 | credentials: { 16 | client_email: StorageConfig.client_email, 17 | private_key: StorageConfig.private_key, 18 | } 19 | }); 20 | 21 | this.bucket = StorageConfig.mediaBucket; 22 | } 23 | 24 | async delete(path: string) { 25 | await this.storage.bucket(this.bucket).file(path).delete({ignoreNotFound: true}) 26 | } 27 | 28 | async get(path: string): Promise { 29 | const fileResponse:DownloadResponse = await this.storage.bucket(this.bucket).file(path).download(); 30 | const [buffer] = fileResponse; 31 | const storageFile = new StorageFile(); 32 | storageFile.buffer = buffer; 33 | storageFile.metadata = new Map() 34 | return storageFile; 35 | } 36 | 37 | async getWithMetaData(path: string): Promise { 38 | const [metadata] = await this.storage.bucket(this.bucket).file(path).getMetadata(); 39 | const fileResponse:DownloadResponse = await this.storage.bucket(this.bucket).file(path).download(); 40 | const [buffer] = fileResponse; 41 | 42 | const storageFile = new StorageFile(); 43 | storageFile.buffer = buffer; 44 | storageFile.metadata = new Map(Object.entries(metadata || {})) 45 | storageFile.contentType = storageFile.metadata.get("contentType"); 46 | return storageFile; 47 | } 48 | 49 | async save(path: string, contentType: string, media: Buffer, metadata: { [key: string]: string }[]) { 50 | const object = metadata.reduce( 51 | (obj, item) => Object.assign(obj, item), {}) 52 | const file = this.storage.bucket(this.bucket).file(path); 53 | const stream = file.createWriteStream(); 54 | stream.on("finish", async () => { 55 | return await file.setMetadata( { 56 | metadata: object 57 | }) 58 | }); 59 | stream.end(media); 60 | } 61 | } -------------------------------------------------------------------------------- /nestjs/nest-auth/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nest-authorization", 3 | "version": "0.0.1", 4 | "description": "", 5 | "author": "", 6 | "private": true, 7 | "license": "UNLICENSED", 8 | "scripts": { 9 | "prebuild": "rimraf dist", 10 | "build": "nest build", 11 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", 12 | "start": "nest start", 13 | "start:dev": "nest start --watch", 14 | "start:debug": "nest start --debug --watch", 15 | "start:prod": "node dist/main", 16 | "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", 17 | "test": "jest", 18 | "test:watch": "jest --watch", 19 | "test:cov": "jest --coverage", 20 | "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", 21 | "test:e2e": "jest --config ./test/jest-e2e.json" 22 | }, 23 | "dependencies": { 24 | "@nestjs/common": "^8.0.0", 25 | "@nestjs/core": "^8.0.0", 26 | "@nestjs/mapped-types": "*", 27 | "@nestjs/platform-express": "^8.0.0", 28 | "reflect-metadata": "^0.1.13", 29 | "rimraf": "^3.0.2", 30 | "rxjs": "^7.2.0" 31 | }, 32 | "devDependencies": { 33 | "@nestjs/cli": "^8.0.0", 34 | "@nestjs/schematics": "^8.0.0", 35 | "@nestjs/testing": "^8.0.0", 36 | "@types/express": "^4.17.13", 37 | "@types/jest": "27.0.2", 38 | "@types/node": "^16.0.0", 39 | "@types/supertest": "^2.0.11", 40 | "@typescript-eslint/eslint-plugin": "^5.0.0", 41 | "@typescript-eslint/parser": "^5.0.0", 42 | "eslint": "^8.0.1", 43 | "eslint-config-prettier": "^8.3.0", 44 | "eslint-plugin-prettier": "^4.0.0", 45 | "jest": "^27.2.5", 46 | "prettier": "^2.3.2", 47 | "source-map-support": "^0.5.20", 48 | "supertest": "^6.1.3", 49 | "ts-jest": "^27.0.3", 50 | "ts-loader": "^9.2.3", 51 | "ts-node": "^10.0.0", 52 | "tsconfig-paths": "^3.10.1", 53 | "typescript": "^4.3.5" 54 | }, 55 | "jest": { 56 | "moduleFileExtensions": [ 57 | "js", 58 | "json", 59 | "ts" 60 | ], 61 | "rootDir": "src", 62 | "testRegex": ".*\\.spec\\.ts$", 63 | "transform": { 64 | "^.+\\.(t|j)s$": "ts-jest" 65 | }, 66 | "collectCoverageFrom": [ 67 | "**/*.(t|j)s" 68 | ], 69 | "coverageDirectory": "../coverage", 70 | "testEnvironment": "node" 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /spring/spring-security-basics/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.4.RELEASE 9 | 10 | 11 | in.kuros.blog.code 12 | spring-security-basics 13 | 0.0.1-SNAPSHOT 14 | spring-security-basics 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-data-jpa 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-security 33 | 34 | 35 | com.h2database 36 | h2 37 | runtime 38 | 39 | 40 | org.projectlombok 41 | lombok 42 | true 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-test 47 | test 48 | 49 | 50 | 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-maven-plugin 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /nestjs/gcp-storage/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gcp-storage", 3 | "version": "0.0.1", 4 | "description": "", 5 | "author": "", 6 | "private": true, 7 | "license": "UNLICENSED", 8 | "scripts": { 9 | "prebuild": "rimraf dist", 10 | "build": "nest build", 11 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", 12 | "start": "nest start", 13 | "start:dev": "nest start --watch", 14 | "start:debug": "nest start --debug --watch", 15 | "start:prod": "node dist/main", 16 | "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", 17 | "test": "jest", 18 | "test:watch": "jest --watch", 19 | "test:cov": "jest --coverage", 20 | "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", 21 | "test:e2e": "jest --config ./test/jest-e2e.json" 22 | }, 23 | "dependencies": { 24 | "@google-cloud/storage": "^5.15.3", 25 | "@nestjs/common": "^8.0.0", 26 | "@nestjs/core": "^8.0.0", 27 | "@nestjs/platform-express": "^8.0.0", 28 | "reflect-metadata": "^0.1.13", 29 | "rimraf": "^3.0.2", 30 | "rxjs": "^7.2.0" 31 | }, 32 | "devDependencies": { 33 | "@nestjs/cli": "^8.0.0", 34 | "@nestjs/schematics": "^8.0.0", 35 | "@nestjs/testing": "^8.0.0", 36 | "@types/express": "^4.17.13", 37 | "@types/jest": "^27.0.1", 38 | "@types/multer": "^1.4.7", 39 | "@types/node": "^16.0.0", 40 | "@types/supertest": "^2.0.11", 41 | "@typescript-eslint/eslint-plugin": "^5.0.0", 42 | "@typescript-eslint/parser": "^5.0.0", 43 | "dotenv": "^10.0.0", 44 | "env-cmd": "^10.1.0", 45 | "eslint": "^8.0.1", 46 | "eslint-config-prettier": "^8.3.0", 47 | "eslint-plugin-prettier": "^4.0.0", 48 | "jest": "^27.2.5", 49 | "prettier": "^2.3.2", 50 | "source-map-support": "^0.5.20", 51 | "supertest": "^6.1.3", 52 | "ts-jest": "^27.0.3", 53 | "ts-loader": "^9.2.3", 54 | "ts-node": "^10.0.0", 55 | "tsconfig-paths": "^3.10.1", 56 | "typescript": "^4.3.5" 57 | }, 58 | "jest": { 59 | "moduleFileExtensions": [ 60 | "js", 61 | "json", 62 | "ts" 63 | ], 64 | "rootDir": "src", 65 | "testRegex": ".*\\.spec\\.ts$", 66 | "transform": { 67 | "^.+\\.(t|j)s$": "ts-jest" 68 | }, 69 | "collectCoverageFrom": [ 70 | "**/*.(t|j)s" 71 | ], 72 | "coverageDirectory": "../coverage", 73 | "testEnvironment": "node" 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /spring/spring-security-authentication-provider/src/main/java/in/kuros/custom/CustomAuthenticationProvider.java: -------------------------------------------------------------------------------- 1 | package in.kuros.custom; 2 | 3 | import in.kuros.entity.UserEntity; 4 | import in.kuros.entity.UserRoles; 5 | import in.kuros.repository.UserRepository; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.security.authentication.AuthenticationProvider; 8 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 9 | import org.springframework.security.core.Authentication; 10 | import org.springframework.security.core.AuthenticationException; 11 | import org.springframework.security.core.GrantedAuthority; 12 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 13 | import org.springframework.stereotype.Component; 14 | 15 | import java.util.Collection; 16 | import java.util.List; 17 | import java.util.stream.Collectors; 18 | 19 | @Component 20 | public class CustomAuthenticationProvider implements AuthenticationProvider { 21 | 22 | @Autowired 23 | private UserRepository userRepository; 24 | 25 | @Override 26 | public Authentication authenticate(final Authentication authentication) throws AuthenticationException { 27 | final String username = authentication.getName(); 28 | final String password = authentication.getCredentials().toString(); 29 | 30 | final List userRoles = getUserIfAuthenticated(username, password); 31 | 32 | return new UsernamePasswordAuthenticationToken(username, null, getGrantedAuthorities(userRoles)); 33 | } 34 | 35 | private Collection getGrantedAuthorities(final List userRoles) { 36 | return userRoles 37 | .stream() 38 | .map(role -> (GrantedAuthority) role::getRole) 39 | .collect(Collectors.toList()); 40 | } 41 | 42 | private List getUserIfAuthenticated(final String username, final String password) { 43 | final UserEntity entity = userRepository.findByUserName(username); 44 | 45 | if (entity == null) { 46 | throw new UsernameNotFoundException("Authentication failed"); 47 | } 48 | 49 | if (!entity.getPassword().equals(password)) { 50 | throw new UsernameNotFoundException("Authentication failed"); 51 | } 52 | 53 | return entity.getUserRoles(); 54 | } 55 | 56 | @Override 57 | public boolean supports(final Class aClass) { 58 | return aClass.equals(UsernamePasswordAuthenticationToken.class); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /react/first-app/src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /react/react-redux/src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /react/react-thunk/src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /spring/spring-security-authentication-provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.4.RELEASE 9 | 10 | 11 | in.kuros.blog.code 12 | spring-security-authentication-provider 13 | 0.0.1-SNAPSHOT 14 | spring-security-authentication-provider 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-security 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-data-jpa 34 | 35 | 36 | com.h2database 37 | h2 38 | runtime 39 | 40 | 41 | org.projectlombok 42 | lombok 43 | true 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-test 48 | test 49 | 50 | 51 | org.springframework.security 52 | spring-security-test 53 | test 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /spring/spring-security-oauth/authorization-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.7.RELEASE 9 | 10 | 11 | in.kuros.blog 12 | spring-security-oauth-server 13 | 0.0.1-SNAPSHOT 14 | spring-security-oauth 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-data-jpa 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-security 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-web 33 | 34 | 35 | org.springframework.cloud 36 | spring-cloud-starter-oauth2 37 | 38 | 39 | 40 | com.h2database 41 | h2 42 | runtime 43 | 44 | 45 | org.projectlombok 46 | lombok 47 | true 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-starter-test 52 | test 53 | 54 | 55 | org.springframework.security 56 | spring-security-test 57 | test 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | org.springframework.cloud 66 | spring-cloud-dependencies 67 | Greenwich.RELEASE 68 | pom 69 | import 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | org.springframework.boot 78 | spring-boot-maven-plugin 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /spring/spring-cloud-stream-rabbitmq/publisher/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.6.RELEASE 9 | 10 | 11 | in.kuros.blog 12 | spring-cloud-stream-rabbitmq-pub 13 | 0.0.1-SNAPSHOT 14 | spring-cloud-stream-rabbitmq-pub 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | Greenwich.SR1 20 | 21 | 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-stream 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-stream-binder-rabbit 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-stream-test-support 40 | test 41 | 42 | 43 | org.apache.commons 44 | commons-lang3 45 | 46 | 47 | commons-lang 48 | commons-lang 49 | 2.6 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.cloud 57 | spring-cloud-dependencies 58 | ${spring-cloud.version} 59 | pom 60 | import 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-maven-plugin 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /nestjs/gcp-storage/README.md: -------------------------------------------------------------------------------- 1 |

2 | Nest Logo 3 |

4 | 5 | [circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 6 | [circleci-url]: https://circleci.com/gh/nestjs/nest 7 | 8 |

A progressive Node.js framework for building efficient and scalable server-side applications.

9 |

10 | NPM Version 11 | Package License 12 | NPM Downloads 13 | CircleCI 14 | Coverage 15 | Discord 16 | Backers on Open Collective 17 | Sponsors on Open Collective 18 | 19 | Support us 20 | 21 |

22 | 24 | 25 | ## Description 26 | 27 | [Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. 28 | 29 | ## Installation 30 | 31 | ```bash 32 | $ npm install 33 | ``` 34 | 35 | ## Running the app 36 | 37 | ```bash 38 | # development 39 | $ npm run start 40 | 41 | # watch mode 42 | $ npm run start:dev 43 | 44 | # production mode 45 | $ npm run start:prod 46 | ``` 47 | 48 | ## Test 49 | 50 | ```bash 51 | # unit tests 52 | $ npm run test 53 | 54 | # e2e tests 55 | $ npm run test:e2e 56 | 57 | # test coverage 58 | $ npm run test:cov 59 | ``` 60 | 61 | ## Support 62 | 63 | Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). 64 | 65 | ## Stay in touch 66 | 67 | - Author - [Kamil Myśliwiec](https://kamilmysliwiec.com) 68 | - Website - [https://nestjs.com](https://nestjs.com/) 69 | - Twitter - [@nestframework](https://twitter.com/nestframework) 70 | 71 | ## License 72 | 73 | Nest is [MIT licensed](LICENSE). 74 | -------------------------------------------------------------------------------- /nestjs/nestjs-mongo/README.md: -------------------------------------------------------------------------------- 1 |

2 | Nest Logo 3 |

4 | 5 | [travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master 6 | [travis-url]: https://travis-ci.org/nestjs/nest 7 | [linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux 8 | [linux-url]: https://travis-ci.org/nestjs/nest 9 | 10 |

A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.

11 |

12 | NPM Version 13 | Package License 14 | NPM Downloads 15 | Travis 16 | Linux 17 | Coverage 18 | Gitter 19 | Backers on Open Collective 20 | Sponsors on Open Collective 21 | 22 | 23 |

24 | 26 | 27 | ## Description 28 | 29 | [Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. 30 | 31 | ## Installation 32 | 33 | ```bash 34 | $ npm install 35 | ``` 36 | 37 | ## Running the app 38 | 39 | ```bash 40 | # development 41 | $ npm run start 42 | 43 | # watch mode 44 | $ npm run start:dev 45 | 46 | # production mode 47 | $ npm run start:prod 48 | ``` 49 | 50 | ## Test 51 | 52 | ```bash 53 | # unit tests 54 | $ npm run test 55 | 56 | # e2e tests 57 | $ npm run test:e2e 58 | 59 | # test coverage 60 | $ npm run test:cov 61 | ``` 62 | 63 | ## Support 64 | 65 | Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). 66 | 67 | ## Stay in touch 68 | 69 | - Author - [Kamil Myśliwiec](https://kamilmysliwiec.com) 70 | - Website - [https://nestjs.com](https://nestjs.com/) 71 | - Twitter - [@nestframework](https://twitter.com/nestframework) 72 | 73 | ## License 74 | 75 | Nest is [MIT licensed](LICENSE). 76 | -------------------------------------------------------------------------------- /spring/spring-security-basics/.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | 10 | https://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an 14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, either express or implied. See the License for the 16 | specific language governing permissions and limitations 17 | under the License. 18 | */ 19 | 20 | import java.io.File; 21 | import java.io.FileInputStream; 22 | import java.io.FileOutputStream; 23 | import java.io.IOException; 24 | import java.net.URL; 25 | import java.nio.channels.Channels; 26 | import java.nio.channels.ReadableByteChannel; 27 | import java.util.Properties; 28 | 29 | public class MavenWrapperDownloader { 30 | 31 | /** 32 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 33 | */ 34 | private static final String DEFAULT_DOWNLOAD_URL = 35 | "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; 36 | 37 | /** 38 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 39 | * use instead of the default one. 40 | */ 41 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 42 | ".mvn/wrapper/maven-wrapper.properties"; 43 | 44 | /** 45 | * Path where the maven-wrapper.jar will be saved to. 46 | */ 47 | private static final String MAVEN_WRAPPER_JAR_PATH = 48 | ".mvn/wrapper/maven-wrapper.jar"; 49 | 50 | /** 51 | * Name of the property which should be used to override the default download url for the wrapper. 52 | */ 53 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 54 | 55 | public static void main(String args[]) { 56 | System.out.println("- Downloader started"); 57 | File baseDirectory = new File(args[0]); 58 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 59 | 60 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 61 | // wrapperUrl parameter. 62 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 63 | String url = DEFAULT_DOWNLOAD_URL; 64 | if (mavenWrapperPropertyFile.exists()) { 65 | FileInputStream mavenWrapperPropertyFileInputStream = null; 66 | try { 67 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 68 | Properties mavenWrapperProperties = new Properties(); 69 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 70 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 71 | } catch (IOException e) { 72 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 73 | } finally { 74 | try { 75 | if (mavenWrapperPropertyFileInputStream != null) { 76 | mavenWrapperPropertyFileInputStream.close(); 77 | } 78 | } catch (IOException e) { 79 | // Ignore ... 80 | } 81 | } 82 | } 83 | System.out.println("- Downloading from: : " + url); 84 | 85 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 86 | if (!outputFile.getParentFile().exists()) { 87 | if (!outputFile.getParentFile().mkdirs()) { 88 | System.out.println( 89 | "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 90 | } 91 | } 92 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 93 | try { 94 | downloadFileFromURL(url, outputFile); 95 | System.out.println("Done"); 96 | System.exit(0); 97 | } catch (Throwable e) { 98 | System.out.println("- Error downloading"); 99 | e.printStackTrace(); 100 | System.exit(1); 101 | } 102 | } 103 | 104 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 105 | URL website = new URL(urlString); 106 | ReadableByteChannel rbc; 107 | rbc = Channels.newChannel(website.openStream()); 108 | FileOutputStream fos = new FileOutputStream(destination); 109 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 110 | fos.close(); 111 | rbc.close(); 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /spring/spring-cloud-stream-rabbitmq/publisher/.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | 10 | https://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an 14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, either express or implied. See the License for the 16 | specific language governing permissions and limitations 17 | under the License. 18 | */ 19 | 20 | import java.io.File; 21 | import java.io.FileInputStream; 22 | import java.io.FileOutputStream; 23 | import java.io.IOException; 24 | import java.net.URL; 25 | import java.nio.channels.Channels; 26 | import java.nio.channels.ReadableByteChannel; 27 | import java.util.Properties; 28 | 29 | public class MavenWrapperDownloader { 30 | 31 | /** 32 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 33 | */ 34 | private static final String DEFAULT_DOWNLOAD_URL = 35 | "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; 36 | 37 | /** 38 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 39 | * use instead of the default one. 40 | */ 41 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 42 | ".mvn/wrapper/maven-wrapper.properties"; 43 | 44 | /** 45 | * Path where the maven-wrapper.jar will be saved to. 46 | */ 47 | private static final String MAVEN_WRAPPER_JAR_PATH = 48 | ".mvn/wrapper/maven-wrapper.jar"; 49 | 50 | /** 51 | * Name of the property which should be used to override the default download url for the wrapper. 52 | */ 53 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 54 | 55 | public static void main(String args[]) { 56 | System.out.println("- Downloader started"); 57 | File baseDirectory = new File(args[0]); 58 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 59 | 60 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 61 | // wrapperUrl parameter. 62 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 63 | String url = DEFAULT_DOWNLOAD_URL; 64 | if (mavenWrapperPropertyFile.exists()) { 65 | FileInputStream mavenWrapperPropertyFileInputStream = null; 66 | try { 67 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 68 | Properties mavenWrapperProperties = new Properties(); 69 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 70 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 71 | } catch (IOException e) { 72 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 73 | } finally { 74 | try { 75 | if (mavenWrapperPropertyFileInputStream != null) { 76 | mavenWrapperPropertyFileInputStream.close(); 77 | } 78 | } catch (IOException e) { 79 | // Ignore ... 80 | } 81 | } 82 | } 83 | System.out.println("- Downloading from: : " + url); 84 | 85 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 86 | if (!outputFile.getParentFile().exists()) { 87 | if (!outputFile.getParentFile().mkdirs()) { 88 | System.out.println( 89 | "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 90 | } 91 | } 92 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 93 | try { 94 | downloadFileFromURL(url, outputFile); 95 | System.out.println("Done"); 96 | System.exit(0); 97 | } catch (Throwable e) { 98 | System.out.println("- Error downloading"); 99 | e.printStackTrace(); 100 | System.exit(1); 101 | } 102 | } 103 | 104 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 105 | URL website = new URL(urlString); 106 | ReadableByteChannel rbc; 107 | rbc = Channels.newChannel(website.openStream()); 108 | FileOutputStream fos = new FileOutputStream(destination); 109 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 110 | fos.close(); 111 | rbc.close(); 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /messaging/messaging-kafka/.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import java.net.*; 18 | import java.io.*; 19 | import java.nio.channels.*; 20 | import java.util.Properties; 21 | 22 | public class MavenWrapperDownloader { 23 | 24 | private static final String WRAPPER_VERSION = "0.5.6"; 25 | /** 26 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 27 | */ 28 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" 29 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; 30 | 31 | /** 32 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 33 | * use instead of the default one. 34 | */ 35 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 36 | ".mvn/wrapper/maven-wrapper.properties"; 37 | 38 | /** 39 | * Path where the maven-wrapper.jar will be saved to. 40 | */ 41 | private static final String MAVEN_WRAPPER_JAR_PATH = 42 | ".mvn/wrapper/maven-wrapper.jar"; 43 | 44 | /** 45 | * Name of the property which should be used to override the default download url for the wrapper. 46 | */ 47 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 48 | 49 | public static void main(String args[]) { 50 | System.out.println("- Downloader started"); 51 | File baseDirectory = new File(args[0]); 52 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 53 | 54 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 55 | // wrapperUrl parameter. 56 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 57 | String url = DEFAULT_DOWNLOAD_URL; 58 | if (mavenWrapperPropertyFile.exists()) { 59 | FileInputStream mavenWrapperPropertyFileInputStream = null; 60 | try { 61 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 62 | Properties mavenWrapperProperties = new Properties(); 63 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 64 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 65 | } catch (IOException e) { 66 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 67 | } finally { 68 | try { 69 | if (mavenWrapperPropertyFileInputStream != null) { 70 | mavenWrapperPropertyFileInputStream.close(); 71 | } 72 | } catch (IOException e) { 73 | // Ignore ... 74 | } 75 | } 76 | } 77 | System.out.println("- Downloading from: " + url); 78 | 79 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 80 | if (!outputFile.getParentFile().exists()) { 81 | if (!outputFile.getParentFile().mkdirs()) { 82 | System.out.println( 83 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 84 | } 85 | } 86 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 87 | try { 88 | downloadFileFromURL(url, outputFile); 89 | System.out.println("Done"); 90 | System.exit(0); 91 | } catch (Throwable e) { 92 | System.out.println("- Error downloading"); 93 | e.printStackTrace(); 94 | System.exit(1); 95 | } 96 | } 97 | 98 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 99 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { 100 | String username = System.getenv("MVNW_USERNAME"); 101 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); 102 | Authenticator.setDefault(new Authenticator() { 103 | @Override 104 | protected PasswordAuthentication getPasswordAuthentication() { 105 | return new PasswordAuthentication(username, password); 106 | } 107 | }); 108 | } 109 | URL website = new URL(urlString); 110 | ReadableByteChannel rbc; 111 | rbc = Channels.newChannel(website.openStream()); 112 | FileOutputStream fos = new FileOutputStream(destination); 113 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 114 | fos.close(); 115 | rbc.close(); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /react/first-app/src/serviceWorker.ts: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.1/8 is considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | type Config = { 24 | onSuccess?: (registration: ServiceWorkerRegistration) => void; 25 | onUpdate?: (registration: ServiceWorkerRegistration) => void; 26 | }; 27 | 28 | export function register(config?: Config) { 29 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 30 | // The URL constructor is available in all browsers that support SW. 31 | const publicUrl = new URL( 32 | (process as { env: { [key: string]: string } }).env.PUBLIC_URL, 33 | window.location.href 34 | ); 35 | if (publicUrl.origin !== window.location.origin) { 36 | // Our service worker won't work if PUBLIC_URL is on a different origin 37 | // from what our page is served on. This might happen if a CDN is used to 38 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 39 | return; 40 | } 41 | 42 | window.addEventListener('load', () => { 43 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 44 | 45 | if (isLocalhost) { 46 | // This is running on localhost. Let's check if a service worker still exists or not. 47 | checkValidServiceWorker(swUrl, config); 48 | 49 | // Add some additional logging to localhost, pointing developers to the 50 | // service worker/PWA documentation. 51 | navigator.serviceWorker.ready.then(() => { 52 | console.log( 53 | 'This web app is being served cache-first by a service ' + 54 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 55 | ); 56 | }); 57 | } else { 58 | // Is not localhost. Just register service worker 59 | registerValidSW(swUrl, config); 60 | } 61 | }); 62 | } 63 | } 64 | 65 | function registerValidSW(swUrl: string, config?: Config) { 66 | navigator.serviceWorker 67 | .register(swUrl) 68 | .then(registration => { 69 | registration.onupdatefound = () => { 70 | const installingWorker = registration.installing; 71 | if (installingWorker == null) { 72 | return; 73 | } 74 | installingWorker.onstatechange = () => { 75 | if (installingWorker.state === 'installed') { 76 | if (navigator.serviceWorker.controller) { 77 | // At this point, the updated precached content has been fetched, 78 | // but the previous service worker will still serve the older 79 | // content until all client tabs are closed. 80 | console.log( 81 | 'New content is available and will be used when all ' + 82 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 83 | ); 84 | 85 | // Execute callback 86 | if (config && config.onUpdate) { 87 | config.onUpdate(registration); 88 | } 89 | } else { 90 | // At this point, everything has been precached. 91 | // It's the perfect time to display a 92 | // "Content is cached for offline use." message. 93 | console.log('Content is cached for offline use.'); 94 | 95 | // Execute callback 96 | if (config && config.onSuccess) { 97 | config.onSuccess(registration); 98 | } 99 | } 100 | } 101 | }; 102 | }; 103 | }) 104 | .catch(error => { 105 | console.error('Error during service worker registration:', error); 106 | }); 107 | } 108 | 109 | function checkValidServiceWorker(swUrl: string, config?: Config) { 110 | // Check if the service worker can be found. If it can't reload the page. 111 | fetch(swUrl) 112 | .then(response => { 113 | // Ensure service worker exists, and that we really are getting a JS file. 114 | const contentType = response.headers.get('content-type'); 115 | if ( 116 | response.status === 404 || 117 | (contentType != null && contentType.indexOf('javascript') === -1) 118 | ) { 119 | // No service worker found. Probably a different app. Reload the page. 120 | navigator.serviceWorker.ready.then(registration => { 121 | registration.unregister().then(() => { 122 | window.location.reload(); 123 | }); 124 | }); 125 | } else { 126 | // Service worker found. Proceed as normal. 127 | registerValidSW(swUrl, config); 128 | } 129 | }) 130 | .catch(() => { 131 | console.log( 132 | 'No internet connection found. App is running in offline mode.' 133 | ); 134 | }); 135 | } 136 | 137 | export function unregister() { 138 | if ('serviceWorker' in navigator) { 139 | navigator.serviceWorker.ready.then(registration => { 140 | registration.unregister(); 141 | }); 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /react/react-redux/src/serviceWorker.ts: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.1/8 is considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | type Config = { 24 | onSuccess?: (registration: ServiceWorkerRegistration) => void; 25 | onUpdate?: (registration: ServiceWorkerRegistration) => void; 26 | }; 27 | 28 | export function register(config?: Config) { 29 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 30 | // The URL constructor is available in all browsers that support SW. 31 | const publicUrl = new URL( 32 | (process as { env: { [key: string]: string } }).env.PUBLIC_URL, 33 | window.location.href 34 | ); 35 | if (publicUrl.origin !== window.location.origin) { 36 | // Our service worker won't work if PUBLIC_URL is on a different origin 37 | // from what our page is served on. This might happen if a CDN is used to 38 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 39 | return; 40 | } 41 | 42 | window.addEventListener('load', () => { 43 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 44 | 45 | if (isLocalhost) { 46 | // This is running on localhost. Let's check if a service worker still exists or not. 47 | checkValidServiceWorker(swUrl, config); 48 | 49 | // Add some additional logging to localhost, pointing developers to the 50 | // service worker/PWA documentation. 51 | navigator.serviceWorker.ready.then(() => { 52 | console.log( 53 | 'This web app is being served cache-first by a service ' + 54 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 55 | ); 56 | }); 57 | } else { 58 | // Is not localhost. Just register service worker 59 | registerValidSW(swUrl, config); 60 | } 61 | }); 62 | } 63 | } 64 | 65 | function registerValidSW(swUrl: string, config?: Config) { 66 | navigator.serviceWorker 67 | .register(swUrl) 68 | .then(registration => { 69 | registration.onupdatefound = () => { 70 | const installingWorker = registration.installing; 71 | if (installingWorker == null) { 72 | return; 73 | } 74 | installingWorker.onstatechange = () => { 75 | if (installingWorker.state === 'installed') { 76 | if (navigator.serviceWorker.controller) { 77 | // At this point, the updated precached content has been fetched, 78 | // but the previous service worker will still serve the older 79 | // content until all client tabs are closed. 80 | console.log( 81 | 'New content is available and will be used when all ' + 82 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 83 | ); 84 | 85 | // Execute callback 86 | if (config && config.onUpdate) { 87 | config.onUpdate(registration); 88 | } 89 | } else { 90 | // At this point, everything has been precached. 91 | // It's the perfect time to display a 92 | // "Content is cached for offline use." message. 93 | console.log('Content is cached for offline use.'); 94 | 95 | // Execute callback 96 | if (config && config.onSuccess) { 97 | config.onSuccess(registration); 98 | } 99 | } 100 | } 101 | }; 102 | }; 103 | }) 104 | .catch(error => { 105 | console.error('Error during service worker registration:', error); 106 | }); 107 | } 108 | 109 | function checkValidServiceWorker(swUrl: string, config?: Config) { 110 | // Check if the service worker can be found. If it can't reload the page. 111 | fetch(swUrl) 112 | .then(response => { 113 | // Ensure service worker exists, and that we really are getting a JS file. 114 | const contentType = response.headers.get('content-type'); 115 | if ( 116 | response.status === 404 || 117 | (contentType != null && contentType.indexOf('javascript') === -1) 118 | ) { 119 | // No service worker found. Probably a different app. Reload the page. 120 | navigator.serviceWorker.ready.then(registration => { 121 | registration.unregister().then(() => { 122 | window.location.reload(); 123 | }); 124 | }); 125 | } else { 126 | // Service worker found. Proceed as normal. 127 | registerValidSW(swUrl, config); 128 | } 129 | }) 130 | .catch(() => { 131 | console.log( 132 | 'No internet connection found. App is running in offline mode.' 133 | ); 134 | }); 135 | } 136 | 137 | export function unregister() { 138 | if ('serviceWorker' in navigator) { 139 | navigator.serviceWorker.ready.then(registration => { 140 | registration.unregister(); 141 | }); 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /react/react-thunk/src/serviceWorker.ts: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.1/8 is considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | type Config = { 24 | onSuccess?: (registration: ServiceWorkerRegistration) => void; 25 | onUpdate?: (registration: ServiceWorkerRegistration) => void; 26 | }; 27 | 28 | export function register(config?: Config) { 29 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 30 | // The URL constructor is available in all browsers that support SW. 31 | const publicUrl = new URL( 32 | (process as { env: { [key: string]: string } }).env.PUBLIC_URL, 33 | window.location.href 34 | ); 35 | if (publicUrl.origin !== window.location.origin) { 36 | // Our service worker won't work if PUBLIC_URL is on a different origin 37 | // from what our page is served on. This might happen if a CDN is used to 38 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 39 | return; 40 | } 41 | 42 | window.addEventListener('load', () => { 43 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 44 | 45 | if (isLocalhost) { 46 | // This is running on localhost. Let's check if a service worker still exists or not. 47 | checkValidServiceWorker(swUrl, config); 48 | 49 | // Add some additional logging to localhost, pointing developers to the 50 | // service worker/PWA documentation. 51 | navigator.serviceWorker.ready.then(() => { 52 | console.log( 53 | 'This web app is being served cache-first by a service ' + 54 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 55 | ); 56 | }); 57 | } else { 58 | // Is not localhost. Just register service worker 59 | registerValidSW(swUrl, config); 60 | } 61 | }); 62 | } 63 | } 64 | 65 | function registerValidSW(swUrl: string, config?: Config) { 66 | navigator.serviceWorker 67 | .register(swUrl) 68 | .then(registration => { 69 | registration.onupdatefound = () => { 70 | const installingWorker = registration.installing; 71 | if (installingWorker == null) { 72 | return; 73 | } 74 | installingWorker.onstatechange = () => { 75 | if (installingWorker.state === 'installed') { 76 | if (navigator.serviceWorker.controller) { 77 | // At this point, the updated precached content has been fetched, 78 | // but the previous service worker will still serve the older 79 | // content until all client tabs are closed. 80 | console.log( 81 | 'New content is available and will be used when all ' + 82 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 83 | ); 84 | 85 | // Execute callback 86 | if (config && config.onUpdate) { 87 | config.onUpdate(registration); 88 | } 89 | } else { 90 | // At this point, everything has been precached. 91 | // It's the perfect time to display a 92 | // "Content is cached for offline use." message. 93 | console.log('Content is cached for offline use.'); 94 | 95 | // Execute callback 96 | if (config && config.onSuccess) { 97 | config.onSuccess(registration); 98 | } 99 | } 100 | } 101 | }; 102 | }; 103 | }) 104 | .catch(error => { 105 | console.error('Error during service worker registration:', error); 106 | }); 107 | } 108 | 109 | function checkValidServiceWorker(swUrl: string, config?: Config) { 110 | // Check if the service worker can be found. If it can't reload the page. 111 | fetch(swUrl) 112 | .then(response => { 113 | // Ensure service worker exists, and that we really are getting a JS file. 114 | const contentType = response.headers.get('content-type'); 115 | if ( 116 | response.status === 404 || 117 | (contentType != null && contentType.indexOf('javascript') === -1) 118 | ) { 119 | // No service worker found. Probably a different app. Reload the page. 120 | navigator.serviceWorker.ready.then(registration => { 121 | registration.unregister().then(() => { 122 | window.location.reload(); 123 | }); 124 | }); 125 | } else { 126 | // Service worker found. Proceed as normal. 127 | registerValidSW(swUrl, config); 128 | } 129 | }) 130 | .catch(() => { 131 | console.log( 132 | 'No internet connection found. App is running in offline mode.' 133 | ); 134 | }); 135 | } 136 | 137 | export function unregister() { 138 | if ('serviceWorker' in navigator) { 139 | navigator.serviceWorker.ready.then(registration => { 140 | registration.unregister(); 141 | }); 142 | } 143 | } 144 | --------------------------------------------------------------------------------