Skip to content

Instantly share code, notes, and snippets.

@ufuk
ufuk / jcmd.sh
Created December 6, 2022 14:12
Display a Java process' system properties or flags (https://docs.oracle.com/en/java/javase/17/docs/specs/man/jcmd.html)
# list Java processes
jcmd -l
# list running JVM's system properties or flags (select a 'pid' from above command's result list)
jcmd pid VM.system_properties
jcmd pid VM.flags
kubectl rollout restart deployment name-of-my-deployment
@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 / 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;
<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>
<properties>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<jakarta-activation-api.version>2.0.0</jakarta-activation-api.version>
<jakarta.xml.soap-api.version>2.0.0</jakarta.xml.soap-api.version>
...
</properties>
@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;
// Print line by line
document.querySelectorAll('pre.msg-payload').forEach(it => console.log(it.innerText));
// Pretty-printed JSON array (If payloads are JSON)
JSON.stringify(Array.from(document.querySelectorAll('pre.msg-payload')).map(it => JSON.parse(it.innerText)), null, 2);