Skip to content

Instantly share code, notes, and snippets.

@joeyslalom
joeyslalom / github-docker-artifact-registry.yaml
Created March 16, 2022 00:08
GitHub Action - docker build and push to Artifact Registry
# 1. Create service account
#. * Service Account Token Creator
#. * Artifact Registry Writer
# 2. Generate service account key
#. * In GitHub project -> Settings -> Secrets -> Actions -> New Repository Secret
#. Name: GCP_CREDENTIALS
#. Value: key.json contents
# 3. Create repo in artifact repository
#. * Name: $env.REPOSITORY below
#. * Region: $env.GAR_LOCATION below
@joeyslalom
joeyslalom / gcloud-get-policy.sh
Last active March 1, 2022 01:21
gcloud roles by member
gcloud projects get-iam-policy $GCP_PROJECT_NAME --flatten="bindings[].members" --format="value(bindings.role)" --filter="bindings.members=serviceAccount:<projectId>-compute@developer.gserviceaccount.com"
gcloud projects get-iam-policy $GCP_PROJECT_NAME \
--flatten="bindings[].members" \
--format="value(bindings.role)" \
--filter="bindings.members=serviceAccount:<projectId>-compute@developer.gserviceaccount.com"
@joeyslalom
joeyslalom / IntegrationTestApp.java
Last active February 14, 2020 18:45
Running JUnit5 as an application
@SpringBootApplication
public class IntegrationTestApp {
public static void main(String[] args) {
ConfigurableApplicationContext appContext = new SpringApplicationBuilder()
.initializers((ApplicationContextInitializer<GenericApplicationContext>) context ->
context.registerBean(Junit5Runner.class,
() -> new Junit5Runner(ExplicitlyDeclaredTest.class))
)
.sources(IntegrationTestApp.class)
@joeyslalom
joeyslalom / CoroutinesUtils.kt
Last active January 9, 2020 21:57 — forked from jivimberg/CoroutinesUtils.kt
SQS Consumer using Kotlin coroutines and pool of workers.
package com.jivimberg.sqs.published
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.isActive
import kotlinx.coroutines.yield
import java.lang.Thread.currentThread
suspend fun CoroutineScope.repeatUntilCancelled(block: suspend () -> Unit) {
while (isActive) {
@joeyslalom
joeyslalom / gradle.properties
Created July 28, 2019 17:28
Gradle properties
org.gradle.caching=true
org.gradle.console=verbose
org.gradle.parallel=true
org.gradle.warning.mode=all
@joeyslalom
joeyslalom / gist:bac94919a81f01ef3330e970da7a40ae
Created July 8, 2019 22:04
palantir git describe version plugin
Using id 'com.palantir.git-version' version '0.11.0'
export V=$(grep build.version rest-api/build/resources/main/META-INF/build-info.properties | cut -d '=' -f2)
echo ${V%.dirty} > rest-api/version.txt
Due to https://github.com/palantir/gradle-git-version/issues/28
when using submodules, every version was "dirty".
@joeyslalom
joeyslalom / RestTemplateConfig.java
Last active June 6, 2019 22:19
Log requests and responses
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.client.RestTemplateCustomizer;
@joeyslalom
joeyslalom / shell.kt
Last active November 21, 2018 00:04
Spring Shell + Kotlin fun
// read a file in classpath
private fun fileToLines(classpathResource: String): List<String> {
val output = ByteArrayOutputStream()
ClassPathResource(classpathResource).inputStream.use {
it.copyTo(output)
}
return output.toString().split("\n")
}
@joeyslalom
joeyslalom / SmokeTest.java
Created October 3, 2018 19:53
smoke test annotation
/**
* Convenience annotation for a Spring Boot Test + Junit5 + per class lifecycle
*/
@Target(ElementType.TYPE)
@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(SpringExtension.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
@joeyslalom
joeyslalom / Junit5Runner.kt
Last active February 12, 2020 17:30
spring boot junit test runner
@SpringBootApplication
class BitsApp
fun main(args: Array<String>) {
val context = SpringApplicationBuilder().initializers(
beans {
bean {
Junit5Runner(listOf(
FirstTests::class.java,