Skip to content

Instantly share code, notes, and snippets.

@peterkeller
peterkeller / LdapExtension.java
Last active June 7, 2020 08:56
Starting in memory ldap server for JUnit 5 tests
package ch.keller.test.extension;
import com.unboundid.ldap.listener.InMemoryDirectoryServer;
import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig;
import com.unboundid.ldap.listener.InMemoryListenerConfig;
import com.unboundid.ldif.LDIFReader;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.slf4j.Logger;
@peterkeller
peterkeller / script.sh
Created June 3, 2020 15:47
Test smtp with telnet (always finish your mail with a dot "."):
telnet smtp.mydomain.com 25
ehlo mydomain.com
mail from: from@mydomain.com
rcpt to: to@foreigndomain.com
data
subject: My subject
blah blah
blah blah
.
@peterkeller
peterkeller / script.sh
Created March 14, 2020 08:17
Find all commits in the git history where a file was involved in
git log --all --full-history -- "**/*.xml"
@peterkeller
peterkeller / WireMockMatchingXPathTest.java
Last active September 1, 2019 09:51
Wire Mock matchingXPath examples (using com.github.tomakehurst:wiremock:2.24.1)
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.matchingXPath;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
package ch.keller.spring;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.transaction.Transactional;
@peterkeller
peterkeller / script.sh
Created June 20, 2019 17:38
Count number of code lines in git repository per user. Taken from https://gist.github.com/amitchhajer/4461043#gistcomment-1858398
git ls-files | while read f; do git blame --line-porcelain $f | grep '^author '; done | sort -f | uniq -ic | sort -n

Import Gradle multi-module into Eclipse

Add configuration file $HOME/.gradle/init.d/eclipse.gradle:

allprojects {
    apply plugin: 'eclipse'
    if (project != rootProject) {
        eclipse.project.name = (rootProject.name + project.path).replaceAll(':', '.')
 }
@peterkeller
peterkeller / JaxbWriter.java
Last active March 22, 2019 08:04
JAXB formatted marshalling but without indents
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.nio.charset.Charset;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.stream.XMLOutputFactory;
@peterkeller
peterkeller / SSL_CHEAT_SHEET.md
Last active March 22, 2019 07:56
SSL Cheat Sheet

openssl

Inspect a SSL certificate:

openssl x509 -in FILE.crt -noout -text

Look at a website's certificate: