Skip to content

Instantly share code, notes, and snippets.

@nieldw
nieldw / postman_bittrex_v3_pre-request.js
Created June 27, 2023 13:29
Postman pre-request script for signing requests to Bittrex V3 api
// You can import the Bittrex v3 API collection into Postman: https://github.com/Bittrex/bittrex.github.io/tree/master/src/_data
// To use this script ensure the following is available in Postman:
// A Collection Variable `baseUrl`
// An Environment Variable BITTREX_API_KEY
// An Environment Variable BITTREX_API_SECRET
// set up vars
let timestamp = new Date().getTime()
let url = pm.request['url']
@nieldw
nieldw / build.gradle
Last active July 25, 2019 14:46
XJC code generation with Gradle and Kotlin
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Kotlin application project to get you started.
*/
plugins {
// Apply the Kotlin JVM plugin to add support for Kotlin on the JVM.
id 'org.jetbrains.kotlin.jvm' version '1.3.21'
@nieldw
nieldw / RateLimitObserving.kt
Created May 1, 2019 10:06
Observe a rate limit when interacting with an expensive resource
import kotlinx.coroutines.*
import kotlin.random.Random
fun main() = runBlocking {
val start = System.nanoTime()
val result = observeRateLimitAsync(1000) {
someExpensiveOperationWithRateLimit()
}.await()
println("Result [$result] retrieved in ${(System.nanoTime() - start) / 1_000_000} ms")
}
@nieldw
nieldw / Dockerfile
Created March 7, 2019 15:14
Caching gradle binaries in a docker build when using the gradle wrapper
# Stage 1, build container
ARG VERSION=8u181
FROM openjdk:${VERSION}-jdk-slim as BUILD
# Get gradle distribution
COPY *.gradle gradle.* gradlew /src/
COPY gradle /src/gradle
WORKDIR /src
RUN ./gradlew --version
@nieldw
nieldw / ClockFixingTest.kt
Created February 14, 2019 16:29
Use MockK to fix the system clock
import io.mockk.every
import io.mockk.mockkStatic
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.time.Clock
import java.time.Instant
import java.time.ZoneId
internal class ClockFixingTest {
@nieldw
nieldw / delete_build_trigger.sh
Last active January 3, 2019 17:44
Delete Google Cloud Build trigger
#!/usr/bin/env bash
PROJECT_ID=$(gcloud config get-value core/project --quiet)
TRIGGER_ID=$1
curl -s -XDELETE -H"Authorization: Bearer $(gcloud config config-helper --format='value(credential.access_token)')" https://cloudbuild.googleapis.com/v1/projects/${PROJECT_ID}/triggers/${TRIGGER_ID} | jq '.'
@nieldw
nieldw / update_build_trigger.sh
Created January 3, 2019 16:58
Update Google Cloud Build trigger
#!/usr/bin/env bash
PROJECT_ID=$(gcloud config get-value core/project --quiet)
JSON=$1
TRIGGER_ID=$(jq -r '.id' ${JSON})
curl -s -XPATCH -T ${JSON} -H"Authorization: Bearer $(gcloud config config-helper --format='value(credential.access_token)')" https://cloudbuild.googleapis.com/v1/projects/${PROJECT_ID}/triggers/${TRIGGER_ID} | jq '.'
@nieldw
nieldw / get_build_trigger.sh
Created January 3, 2019 16:54
Get Google Cloud Build trigger
#!/usr/bin/env bash
PROJECT_ID=$(gcloud config get-value core/project --quiet)
TRIGGER_ID=$1
curl -s -XGET -H"Authorization: Bearer $(gcloud config config-helper --format='value(credential.access_token)')" https://cloudbuild.googleapis.com/v1/projects/${PROJECT_ID}/triggers/${TRIGGER_ID} | jq '.'
@nieldw
nieldw / create_build_trigger.sh
Created January 3, 2019 16:48
Create Google Cloud Build trigger
#!/usr/bin/env bash
PROJECT_ID=$(gcloud config get-value core/project --quiet)
JSON=$1
curl -s -XPOST -T ${JSON} -H"Authorization: Bearer $(gcloud config config-helper --format='value(credential.access_token)')" https://cloudbuild.googleapis.com/v1/projects/${PROJECT_ID}/triggers | jq '.'
@nieldw
nieldw / list_build_triggers.sh
Created January 3, 2019 16:44
List Google Cloud Build triggers
#!/usr/bin/env bash
PROJECT_ID=$(gcloud config get-value core/project --quiet)
curl -s -XGET -H"Authorization: Bearer $(gcloud config config-helper --format='value(credential.access_token)')" https://cloudbuild.googleapis.com/v1/projects/${PROJECT_ID}/triggers | jq '.'