Skip to content

Instantly share code, notes, and snippets.

View amarchenkov's full-sized avatar

Andrei Marchenkov amarchenkov

View GitHub Profile
@amarchenkov
amarchenkov / Dockerfile
Created June 20, 2025 15:41
Minimal Docker image for Go application
FROM golang:1.24-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# Build the Go application.
# CGO_ENABLED=0 disables CGO, making the binary statically linked and independent of system libraries.
# -ldflags="-s -w" removes symbol table and debug information, further reducing binary size.
@amarchenkov
amarchenkov / Dockerfile
Created May 28, 2025 07:42
Ideal Dockerfile for Spring Boot application
FROM bellsoft/liberica-openjdk-alpine:23-cds AS builder
WORKDIR /application
COPY . .
RUN --mount=type=cache,target=/root/.m2 chmod +x mvnw && ./mvnw clean install -Dmaven.test.skip
FROM bellsoft/liberica-openjre-alpine:23-cds AS layers
WORKDIR /application
COPY --from=builder /application/target/*.jar app.jar
RUN java -Djarmode=tools -jar app.jar extract --layers --destination extracted
@amarchenkov
amarchenkov / postgres_optimiation.sql
Created February 15, 2025 15:52
Optimization approaches of SQL queries for Postgres
# Using VALUES instead of IN
# BEFORE
EXPLAIN
SELECT *
FROM public.salesorder
WHERE shipcity IN ('Madrid', 'Lyon')
AND custid = '69'
AND shipperid = 3
@amarchenkov
amarchenkov / cds_java.sh
Created October 2, 2024 16:05
How to start your application with CDS enabled
#!/usr/bin/env bash
# Extract jar archive -> app.jar + libs/*
java -Djarmode=tools -jar my-app.jar extract --destination application
# -Dspring.context.exit is for Spring only
# Create *.jsa file with a common context
java -XX:ArchiveClassesAtExit=application.jsa -Dspring.context.exit=onRefresh -jar application/my-app.jar
# Run app using common context
@amarchenkov
amarchenkov / pom.xml
Last active July 9, 2025 15:59
Useful libraries in Java
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- Detecting text encoding -->
@amarchenkov
amarchenkov / AsyncFileWalker.java
Last active September 29, 2024 13:52
Async implementation of file walker in Java. Based on RecursiveAction and ForkJoinPool
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
@amarchenkov
amarchenkov / download_layer.sh
Created November 3, 2023 11:30
Manually download docker image
#!/bin/bash
BLOBSUM="sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4"
curl \
--silent \
--location \
--request GET \
--header "Authorization: Bearer ${TOKEN}" \
"https://registry-1.docker.io/v2/library/ubuntu/blobs/${BLOBSUM}" \
@amarchenkov
amarchenkov / list_docker_repos.sh
Created November 3, 2023 11:19
Get list of user's repositories in DockerHub
#!/bin/bash
set -e
# set username and password
UNAME="username"
UPASS="password"
# get token to be able to talk to Docker Hub
TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'${UNAME}'", "password": "'${UPASS}'"}' https://hub.docker.com/v2/users/login/ | jq -r .token)
@amarchenkov
amarchenkov / manifest_and_tags.sh
Last active November 3, 2023 10:12
Get image manifest and tags via Registry HTTP API V2
#!/bin/sh
DOCKERHUB_USERNAME=$(jq -r '.username' < ~/.secrets/docker.json)
DOCKERHUB_PASSWORD=$(jq -r '.password' < ~/.secrets/docker.json)
TARGET_NS_REPO=library/debian
# yes, you need a new token for each repository, maybe you can have multiple scopes though?
PARAMS="service=registry.docker.io&scope=repository:$TARGET_NS_REPO:pull"
TOKEN=$(curl --user "$DOCKERHUB_USERNAME:$DOCKERHUB_PASSWORD" \
@amarchenkov
amarchenkov / install_mitmproxy.sh
Last active November 3, 2023 10:12
Install and uninstall mitmproxy
#!/bin/sh
# Download mitmproxy
echo "DOWNLOAD mitmproxy"
wget https://downloads.mitmproxy.org/10.1.1/mitmproxy-10.1.1-linux.tar.gz
# Extract archive to ~/.local
echo "EXTRACTING archive"
tar -xfv mitmproxy-10.1.1-linux.tar.gz mitmproxy -C ~/.local
rm ./mitmproxy-10.1.1-linux.tar.gz