Skip to content

Instantly share code, notes, and snippets.

@Crydust
Crydust / jpaToHql.java
Last active March 26, 2024 10:11
convert jpa TypedQuery to hibernate hql (=jpql)
// @see http://antoniogoncalves.org/2012/05/24/how-to-get-the-jpqlsql-string-from-a-criteriaquery-in-jpa/
TypedQuery<X> q = entityManager.createQuery(cq);
try {
Class<?> hibernateQueryClass = Class.forName("org.hibernate.Query");
Object hibernateQuery = q.unwrap(hibernateQueryClass);
java.lang.reflect.Method getQueryStringMethod = hibernateQueryClass.getMethod("getQueryString");
Object hql = getQueryStringMethod.invoke(hibernateQuery);
LOGGER.warn("hql = {}", hql);
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | java.lang.reflect.InvocationTargetException ex) {
ex.printStackTrace();
@Crydust
Crydust / pom-shade-proguard.xml
Created August 14, 2015 10:35
reduce size of jar with shade and proguard
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>x</groupId>
<artifactId>y</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>y</name>
@Crydust
Crydust / Git.java
Last active November 8, 2023 16:40
run git commands from java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
@Crydust
Crydust / XmlStax.java
Last active August 30, 2023 14:03
Read xml using stax api in java
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.events.EndElement;

Git worktree

# clone the repo, but switch it to a dummybranch so other worktrees can checkout the main branch
git clone --no-checkout URL_HERE repo.git
cd repo.git
git switch -c dummy

# add a worktree
git worktree add ../repo_main main
@Crydust
Crydust / my-winutil.ps1
Created February 18, 2023 16:44
remove junk from windows 10
Write-Host "Creating Restore Point in case something bad happens"
Enable-ComputerRestore -Drive "$env:SystemDrive"
Checkpoint-Computer -Description "RestorePoint1" -RestorePointType "MODIFY_SETTINGS"
#WPFEssTweaksDVR
If (!(Test-Path "HKCU:\System\GameConfigStore")) {
New-Item -Path "HKCU:\System\GameConfigStore" -Force
}
Set-ItemProperty -Path "HKCU:\System\GameConfigStore" -Name "GameDVR_DXGIHonorFSEWindowsCompatible" -Type DWord -Value 1
Set-ItemProperty -Path "HKCU:\System\GameConfigStore" -Name "GameDVR_HonorUserFSEBehaviorMode" -Type DWord -Value 1
@Crydust
Crydust / transparent-pixel.html
Created February 8, 2023 13:13
transparent pixel
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="/>
@Crydust
Crydust / LogHttpServletRequest.java
Last active February 7, 2023 10:26
log HttpServletRequest
sb.append("*** request.getMethod() = ").append(request.getMethod()).append("\n");
sb.append("*** request.getContextPath() = ").append(request.getContextPath()).append("\n");
sb.append("*** request.getRequestURI() = ").append(request.getRequestURI()).append("\n");
sb.append("*** request.getServletPath() = ").append(request.getServletPath()).append("\n");
sb.append("*** request.getPathInfo() = ").append(request.getPathInfo()).append("\n");
final ArrayList<String> headerNames = Collections.list(request.getHeaderNames());
for (final String headerName : headerNames) {
final ArrayList<String> headers = Collections.list(request.getHeaders(headerName));
for (int i = 0; i < headers.size(); i++) {
final String header = headers.get(i);
@Crydust
Crydust / XmlDocument.java
Last active October 20, 2022 13:39
encapsulate org.w3c.dom.Document and javax.xml.xpath.XPath to parse a small xml document (needs more testing, not thread safe, ...)
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.xml.XMLConstants;