Skip to content

Instantly share code, notes, and snippets.

View 62mkv's full-sized avatar

Kirill M 62mkv

  • Breakwater Technology
  • Tallinn, Estonia
View GitHub Profile
@62mkv
62mkv / README.md
Created November 22, 2023 15:34
Postgre recipes

Show table size in bytes with a percentage of all tables size

with t as (select * from pg_catalog.pg_tables
where schemaname = 'public'), 
sizes as (
select t.tablename, pg_total_relation_size(t.tablename::regclass) _size from t
order by 2 desc),
total as (select sum(_size) _size from sizes)
select sizes.tablename, sizes._size, to_char(sizes._size / total._size * 100.0,'999D99%') from sizes, total;
@62mkv
62mkv / README.md
Last active May 28, 2023 10:39
How to run "Zipkin2 + Elasticsearch" with Docker Desktop on Windows 10 with WSL2 backend

Problem

Turns out, Zipkin, when run "simply" with something like docker run openzipkin/zipkin:latest, dies out of OOM very soon, under any meaningful load. To prevent this from happening, one would want to run it together with a storage backend, like Elasticsearch. Unfortunately, Zipkin docs are probably hopelessly outdated, at least, I could not achieve this based on their README alone.

Solution

Create this docker-compose.yaml:

package org.example;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.trace.Span;
import io.r2dbc.proxy.core.*;
import io.r2dbc.proxy.listener.ProxyMethodExecutionListener;
import static java.util.stream.Collectors.joining;
@62mkv
62mkv / jQAssistant-Java.md
Last active May 24, 2022 13:48
Cypher samples

Some jQAssistant Java-plugin graphs related Cypher queries

Add a label to "root" JARs (relevant for Spring Boot JARs)

Explanation: graph, created with jqassistant scan -f libs/, will created a lot of :Jar entries, but most of them will be "library" JARs, located under BOOT-INF/ folder. So the only JAR that represents the actual application code, will have fileName starting with something else (e.g. /application-name.jar)

MATCH (j:Jar)
WHERE left(j.fileName, 2) <> '/B'

When we have source.json file with a following structure:

{
    "groupId": "bla-bla-bla",
    "members": 25,
    "topics": 25,
    "simple": false,
    "partitionAssignor": "range",
    "state": "STABLE",

How to dump H2 database contents on every Spring test class

Sometimes, you get into weird situations when test class passes when run alone, but fails, when run as part of a suite (i.e. alongside some other tests)

In order to get better visibility into what is happening, you might resort to dumping the whole H2 database content (or just selected tables)

For that, we can create a TestExecutionListener like this:

@Slf4j
/**
Can be tested quickly with Javasript REPL extension for VS Code
*//
function test_string(str) {
var par_count = 0;
for (var i = 0; i < str.length; i++) {
if (str[i] == '(') par_count++;
else if (str[i] == ')') par_count--;
@62mkv
62mkv / README.md
Last active May 5, 2021 10:21
OpenShift useful notes

Deploy an S2I-based application, based on Java 11, using custom output imagestream

Prepare "builder image"

First, we need to have a suitable (Java 11) builder image in our project

# pulling image locally
docker pull fabric8/s2i-java:latest-java11
@62mkv
62mkv / README.md
Last active April 10, 2021 13:26
Hosting FTP in Docker with Docker Desktop under Windows 10

Sneak on docker containers' traffic:

docker run --rm --net=host -v $PWD/tcpdump:/tcpdump kaazing/tcpdump

This will save tcpdump.pcap to tcpdump folder under current directory. That file can be opened with WireShark (sometimes it fails to open the file - check if any concurrent instances of tcpdump container are still running)

Run vsftpd container with mapped volume:

@62mkv
62mkv / README.md
Last active March 25, 2021 09:02
useful JHipster commands

Useful JHipster commands:

How to ensure that your locally developed JHipster is used:

  • remove globally installed "regular" JHipster npm unlink -g generator-jhipster
  • in the "generator-jhipster" folder: npm link (this will link this local folder to global npm node_modules)
  • in the "blueprint" folder: npm link generator-jhipster (this way your locally developed blueprint will also use your locally developed JHipster)
  • in the "blueprint" folder: npm link
  • in the "app" folder: npm link generator-jhipster; npm link <your-blueprint>