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 October 11, 2019 08:46
How to add a custom trusted certificate for making HTTP requests against external sites

Thoughts on how to add trusted store for connection to external sites that use that certificate for HTTPS

Option 1: global configuration

One can just provide the -Djavax.net.ssl.trustStore=<path/to/store> -Djavax.net.ssl.trustStorePassword=<password> options when running the Java application

However, this is not always possible (for example, when run in the cloud).

And if you want to use server.ssl.trust-store/server.ssl.trust-store-password options from Spring Boot, be aware that with those you also have to provide key-store options as well. And, basically that would be an abuse, because this configuration is specifically for server side of your application.

@62mkv
62mkv / README.md
Last active December 14, 2023 13:14
Wikidata SPARQL queries

Examples of SPARQL Wikidata queries:

List of hills in Estonia without defined elevation

SELECT ?item ?itemLabel ?geo ?elevation WHERE {
  ?item wdt:P31 wd:Q54050;
    wdt:P17 wd:Q191;
        wdt:P625 ?geo.
    OPTIONAL { ?item wdt:P2044 ?elevation }
    SERVICE wikibase:label { bd:serviceParam wikibase:language "et" } 
@62mkv
62mkv / README.md
Last active July 28, 2020 06:59
Java useful tips

To wire-print requests/responses over HTTP for SOAP/XML:

-Dcom.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true -Dcom.sun.xml.ws.transport.http.HttpAdapter.dump=true -Dcom.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump=true -Dcom.sun.xml.internal.ws.transport.http.HttpAdapter.dump=true -Dcom.sun.xml.internal.ws.transport.http.HttpAdapter.dumpTreshold=true

Snippet to quickly get Java system properties:

public class My {
  public static void main(String[] argc) {
 System.getProperties().stringPropertyNames().forEach(name -&gt; System.out.println(name + "=" + System.getProperty(name)));
@62mkv
62mkv / README.md
Created March 6, 2020 10:10
Docker Desktop is not respecting proxy settings under Windows 10 Professional

Docker Desktop is not respecting proxy settings under Windows 10 Professional

SOLUTION:

  • Option 1:configure Docker Desktop to use Manual proxy settings: the "whale" context menu / Settings / Resources / Proxies / Manual proxy configuration
  • Option 2: (might work, didn't test) set HTTP_PROXY / HTTPS_PROXY / NO_PROXY as system environment variables, not user ones

In both cases, restart Docker Server

Original Problem:

@62mkv
62mkv / README.md
Last active March 15, 2022 15:00
PowerShell cheatsheet

Getting help on any topic:

help _topic_

or

man _topic_

Read all lines from text file

@62mkv
62mkv / README.md
Created April 15, 2020 14:41
How to validate an XML document with XMLSpy

Ensure that root element of the XML file will contain something like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:PrintData xmlns:ns2="http://iopm.int.kn/iopm4xml/meta/v1.4" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://iopm.int.kn/iopm4xml/meta/v1.4 path/to/xsd/file/schema.xsd">

and then click F8

@62mkv
62mkv / README.md
Created April 17, 2020 16:09
Tricky Testcontainers execution case (Jenkins, Docker, and tests failing under Gradle)

The excerpt from logs:

 14:56:01.405 [Test worker] INFO  org.testcontainers.dockerclient.DockerClientProviderStrategy - Loaded org.testcontainers.dockerclient.EnvironmentAndSystemPropertyClientProviderStrategy from ~/.testcontainers.properties, will try it first
    14:56:01.942 [ducttape-0] DEBUG org.testcontainers.dockerclient.DockerClientProviderStrategy - Pinging docker daemon...
    14:56:01.987 [ducttape-0] DEBUG com.github.dockerjava.core.command.AbstrDockerCmd - Cmd: 
    14:56:02.699 [ducttape-0] DEBUG org.testcontainers.dockerclient.DockerClientProviderStrategy - Pinging docker daemon...
    14:56:02.699 [ducttape-0] DEBUG com.github.dockerjava.core.command.AbstrDockerCmd - Cmd: 
    14:56:03.200 [ducttape-0] DEBUG org.testcontainers.dockerclient.DockerClientProviderStrategy - Pinging docker daemon...
    14:56:03.209 [ducttape-0] DEBUG com.github.dockerjava.core.command.AbstrDockerCmd - Cmd: 
    14:56:03.712 [ducttape-0] DEBUG org.testcontainers.dockerclient.DockerClientProviderStrategy - Pin
@62mkv
62mkv / README.md
Last active December 1, 2021 10:45
Gradle cookbook

Tests verbosity

Executing gradle commands with -i seem to seriously enhance debugging experience, especially when tests are failing to initialize (as if when Testcontainers fail to connect to Docker daemon) and there're almost no logs in the JUnit XML reports

./gradlew -i clean test

Also see here: https://docs.gradle.org/current/userguide/java_testing.html

@62mkv
62mkv / README.md
Created May 5, 2020 14:19
How to catch those flaky tests

Today I've run into situation where some of the tests started failing randomly. Sometimes, 3 times in a row they could be executed successfully, but then would fail.

In order to collect more statistics I created this test.bat:

for /L %%i in (1,1,10) do (
   gradlew clean test
   zip -r0q build%%i build/ 
)
@62mkv
62mkv / example.sql
Created May 20, 2020 11:36
How to use XPath against XML text fields with PostgreSQL
/* real-world example */
select xpath('/ns2:PrintData/Meta/Document/@id', xmlparse (document payload),
ARRAY[ARRAY['ns2', 'http://iopm.int.kn/iopm4xml/meta/v1.4']]) from request_history_step_payload rhsp
join request_history_step rhs on rhs.step_uuid = rhsp.step_uuid
where rhs.step_type = 'PRINTER_REQUEST' and rhs.started_at between '2020-05-19' and now()