Skip to content

Instantly share code, notes, and snippets.

View felix19350's full-sized avatar

Bruno Félix felix19350

View GitHub Profile
@felix19350
felix19350 / build.part.gradle
Created February 9, 2021 23:54
Gradle (groovy) task definitions to be able to run AWS CDK in a project with a main class
/**
* AWS CDK integration. Changes the mainClassName variable and calls run
* */
def cdkMainClassName = "com.rideal.infrastructure.aws.RidealApp"
def originalMainClassName = mainClassName
tasks.register("run-cdk") {
description "Specific run-script for AWS CDK integration"
group "CDK"
@felix19350
felix19350 / gradle-notes.md
Created January 15, 2021 17:06
Gradle notes

Gradle notes

Test dependencies in multi-module projects

Scenario:

Gradle multi-module project that is comprised of two modules A, B and C. Module A exposes functionality (e.g. json serialization configurations) that is consumed by module B and C. Module A also has a set of test helpers (in src/test/) that are useful so that modules B and C are not concerned with bootstrapping the serialization part on their unit tests.

@felix19350
felix19350 / aws-cognito-token-validation.kt
Last active January 14, 2021 22:53
Notes on cognito JWT token validation
/***
* AWS Cognito signs the tokens using the RS256 algorithm. Contrary to most common examples (using HMAC + SHA256) that use
* a shared secret, the RS256 uses assymetric crytography, so in order to validate the JWT we need to obtain the public key
* that matches the private key used to generate the token signature.
* Therefore, the critical step is to download the public key from the discovery endpoint.
* Cognito makes this available as a JWKS, JSON Web Key Set, available at a well known location of your user pool
* e.g. https://cognito-idp.{region}.amazonaws.com/{user-pool-id}/.well-known/jwks.json
* Furthermore, the issuer of the token is the user pool (the iss clamin is the user pool URL) and the audience is the
* particular client that was configured on the user pool (the aud claim is set to a specific client id of that pool).
* See: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-client-apps.html
@felix19350
felix19350 / ktor-full-example.kt
Last active July 15, 2023 12:42
Barebones Ktor REST API example
package org.example
import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
import io.ktor.application.call
import io.ktor.http.HttpStatusCode
import io.ktor.request.receive
import io.ktor.response.respond
import io.ktor.routing.Route
import io.ktor.routing.get
@felix19350
felix19350 / api-versioning-content-type-headers.kt
Created October 18, 2018 22:33
Ktor API versioning via content type headers examples
import io.ktor.http.ContentType
// Resource definition
data class MyResource(val name:String)
// Content-type definition
object MyContentTypes {
object v1 {
val MyResource = ContentType("application", "vnd.app.myResource-v1+json")
}
@felix19350
felix19350 / pagination-headers-sample.kt
Last active June 3, 2022 16:36
Ktor REST style pagination headers
import io.ktor.application.ApplicationCall
import io.ktor.http.URLBuilder
import io.ktor.http.takeFrom
import io.ktor.util.createFromCall
import io.ktor.application.call
import io.ktor.http.HttpStatusCode
import io.ktor.request.receive
import io.ktor.response.respond
import io.ktor.routing.*
@felix19350
felix19350 / MimeTypeDetector.kt
Last active February 20, 2022 22:32
Kotlin simple mimetype/file extension detector
import org.slf4j.LoggerFactory
class MimeTypeDetector private constructor() {
private val log = LoggerFactory.getLogger(MimeTypeDetector::class.java)
private var extensionToMimeTypeMapping: MutableMap<String, String> = mutableMapOf()
private var mimeTypeToExtensionMapping: MutableMap<String, String> = mutableMapOf()
companion object {
@felix19350
felix19350 / Searchable.groovy
Created July 14, 2014 22:52
Seachable.groovy bulk index config
/**
* Should the database be indexed at startup (using Compass:GPS)?
*
* Possible values: true|false|"fork"
*
* The value may be a boolean true|false or a string "fork", which means true,
* and fork a thread for it
*
* If you use BootStrap.groovy to insert your data then you should use "true",
* which means do a non-forking, otherwise "fork" is recommended