Skip to content

Instantly share code, notes, and snippets.

@ufuk
ufuk / force-to-delete-pod.sh
Created April 22, 2022 12:55
How to force k8s to delete a pod via kubectl?
kubectl delete pods your-pod-name --grace-period=0 --force -n your-namespace-name
@ufuk
ufuk / git-empty-commit.sh
Created March 12, 2022 17:54
How to force git allowing to commit with empty content?
git commit --allow-empty -m "trigger pipeline with an empty commit"
@ufuk
ufuk / intellij-code-template-for-service-dao-tests.vm
Last active March 12, 2022 17:59
IntelliJ Code Template for Service and DAO Tests
#set ($IS_SERVICE_TEST = ${NAME.endsWith("ServiceTest")})
#set ($IS_VIEW_TEST = ${NAME.endsWith("ViewTest")})
#set ($IS_CONTROLLER_TEST = ${NAME.endsWith("ControllerTest")})
#set ($IS_MOCK_TEST = ${IS_SERVICE_TEST} or ${IS_VIEW_TEST} or ${IS_CONTROLLER_TEST})
#set ($IS_DAO_TEST = ${NAME.endsWith("DaoTest")})
#set ($IS_MOCK_OR_DAO_TEST = ${IS_MOCK_TEST} or ${IS_DAO_TEST})
#set ($TESTING_CLASS_NAME = ${NAME.split("Test")[0]})
@ufuk
ufuk / HtmlToTextUtils.java
Created October 6, 2021 13:13
Utility method to convert HTML text to plain text while preserving newlines (using jsoup as main dependency)
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.nodes.TextNode;
import java.util.List;
import java.util.stream.Collectors;
@ufuk
ufuk / XmlUtils.java
Last active November 12, 2021 13:36
Various XML utilities, such as unmarshal and consume XML input stream by target element name (and -optional- target element depth).
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.util.StreamReaderDelegate;
@ufuk
ufuk / BaseMockito2JUnit4Test.java
Last active October 24, 2021 17:52
Performs "verify no more interactions" check automatically for all mock objects (works with Mockito version 2 or higher & JUnit version 4 and 5). For detailed description: https://ufukuzun.wordpress.com/2019/04/09/ne-olup-bittiginden-habersiz-testlere-derman-mockscollector/ (Turkish)
import org.apache.commons.lang3.ArrayUtils;
import org.junit.After;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.junit.MockitoJUnitRunner;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@RunWith(MockitoJUnitRunner.class)
@ufuk
ufuk / TextUtils.java
Last active April 8, 2021 07:03
Curated text utils for specific use cases
import org.apache.commons.lang3.StringUtils;
import java.text.Normalizer;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@ufuk
ufuk / SpringDataPageUtils.java
Last active February 8, 2021 13:04
SpringDataPageUtils to convert paged entities to paged model objects
import org.springframework.data.domain.Page;
import org.springframework.data.support.PageableExecutionUtils;
import java.util.function.Function;
import java.util.stream.Collectors;
public final class SpringDataPageUtils {
public static <T, C> Page<C> convertPage(Page<T> page, Function<T, C> converter) {
return PageableExecutionUtils.getPage(
@ufuk
ufuk / HttpServletRequestResponsePrinter.java
Created September 5, 2019 06:54
Utility to generate logging-purpose text for HttpServletRequest/Response
package ...;
import ...JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.util.ContentCachingRequestWrapper;
import org.springframework.web.util.WebUtils;
<properties>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<jaxb.version>2.3.3</jaxb.version>
...
</properties>