Skip to content

Instantly share code, notes, and snippets.

View diyan's full-sized avatar

Oleksii Diian diyan

View GitHub Profile
@diyan
diyan / google_http_client_gson_integration.md
Last active June 28, 2023 20:54
Bridge between Gson/GsonBuilder and Google HTTP Client.

Note that JsonHttpContent class from com.google.http-client/google-http-client-gson does not support the full feature set of Gson library.

Instead it just relies on the JsonParser provided by Gson.

Code snippet below provides a bridge between full featured Gson/GsonBuilder and Google HTTP Client.

See https://stackoverflow.com/questions/34690059/configuring-the-gsonfactory-of-google-http-client

See https://github.com/googleapis/google-http-java-client/tree/main/google-http-client-gson/src/main/java/com/google/api/client/json/gson

@diyan
diyan / apache_http_components_for_google_http_client.md
Last active June 28, 2023 18:46
Configure Apache HttpComponents backend for Google HTTP Client
package com.example.project;

import java.io.IOException;

import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpVersion;
import org.apache.http.client.methods.HttpRequestWrapper;

Apache HttpComponents

ArrayList<NameValuePair> formParams = new ArrayList<>();
formParams.add(new BasicNameValuePair("paramA", "valueA"));
formParams.add(new BasicNameValuePair("paramB", "valueB"));
formParams.add(new BasicNameValuePair("paramC", "valueC"));

BusinessObject businessObject = new BusinessObject();

CloseableHttpClient httpClient = HttpClientBuilder.create().build();
package loose
import (
"encoding/json"
"testing"
"time"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
package com.example.akka.stream
import akka.NotUsed
import akka.stream.FlowShape
import akka.stream.javadsl.Balance
import akka.stream.javadsl.Flow
import akka.stream.javadsl.GraphDSL
import akka.stream.javadsl.Merge
// Most likely those classes are useless
@diyan
diyan / docker_buildx_kotlin_gradle.md
Created December 4, 2020 19:53
Gradle build time on AMD64 vs ARM64 using Docker multi-arch build feature

Gradle build time on AMD64 vs ARM64 using Docker multi-arch build feature

AMD64. docker buildx build --platform=linux/amd64 --tag=sample-app:amd64 .
ARM64. docker buildx build --platform=linux/arm64 --tag=sample-app:arm64 .

AMD64. An attempt to start the daemon took 1.883 secs.
ARM64. An attempt to start the daemon took 51.799 secs.

AMD64. :compileKotlin (Thread[Execution worker for ':' Thread 5,5,main]) completed. Took 25.839 secs.

Sharded Redis Cluster Behavior

Provision Sharded Redis Cluster using Docker Compose

$ curl -sSL https://raw.githubusercontent.com/bitnami/bitnami-docker-redis-cluster/master/docker-compose.yml > docker-compose.yml
$ docker-compose up

Write sample dataset

@diyan
diyan / terraform_iam.md
Last active April 28, 2020 22:33
Examples of Terraform and AWS IAM resources

AWS IAM using Terraform

Example 1

// Data Resource for IAM Policy Document
// String interpolation
// Separate IAM Policy attached to IAM Role
data "aws_iam_policy_document" "cloudwatch_logs_write_policy" {
  statement {
    actions = [
@diyan
diyan / Dockerfile
Created April 27, 2020 18:20
Dockerfile for Kotlin app using multi-stage build and FatJar
FROM openjdk:8-alpine as builder
# johnrengelman/shadow v5.2.0 requires Gradle v5
# but openjdk:8-alpine packaged with Alpine v3.9
# which packaged with Gradle v4.10.3
RUN set -x \
&& apk add --update --no-cache --repository=http://nl.alpinelinux.org/alpine/v3.10/community gradle
# Install deps before copying code, use docker cache for external packages
WORKDIR app
@diyan
diyan / LooseMapDeserializerTest.kt
Last active April 14, 2020 18:19
Kotlin, Jackson, JUnit5, AssertJ
package com.project.json
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.fasterxml.jackson.module.kotlin.readValue
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance