Skip to content

Instantly share code, notes, and snippets.

View raphw's full-sized avatar

Rafael Winterhalter raphw

View GitHub Profile
@raphw
raphw / ChecksumDiff.java
Created November 27, 2023 18:27
Computes checksums from a file
import java.io.BufferedReader;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.MessageDigest;
@raphw
raphw / TaskGraph.java
Created November 24, 2023 13:34
TaskGraph for build tool
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.Executor;
import java.util.function.BiFunction;
import java.util.function.Function;
public class TaskGraph<IDENTITY, INPUT, OUTPUT> implements Function<OUTPUT, CompletionStage<OUTPUT>> {
private final Executor executor;
@raphw
raphw / Build.java
Created November 23, 2023 21:53
Mock-up for Java-based build tool (single source execution)
import javax.tools.*;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
System.out.println(1 + 2);
/exit
@raphw
raphw / timestamps.txt
Last active November 9, 2022 20:59
Timestamps handled by Oracle/Postgres.
What is the general difference when handling timestamps?
Postgres: Does not store time zone, only displays column time zone aware.
Oracle: Stores time zone as part of type.
What does CURRENT_TIMESTAMP return?
Postgres: TIMESTAMP WITH TIMEZONE displaying in session time zone.
Oracle: TIMESTAMP WITH TIMEZONE in session time zone.
What happens when converting a TIMESTAMP (without time zone) with "AT TIME ZONE '<name>'"?
Postgres: Assumes TIMESTAMP to be in zone <name>.
@raphw
raphw / TimestampTest.java
Created November 8, 2022 08:36
Timestamps with JDBC
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Calendar;
package net.bytebuddy.build.gradle;
import net.bytebuddy.utility.OpenedClassReader;
import net.bytebuddy.utility.nullability.MaybeNull;
import org.objectweb.asm.*;
import java.util.HashMap;
import java.util.Map;
public class UnwrappingClassVisitor extends ClassVisitor {
@raphw
raphw / OracleNotificationTest.java
Created August 12, 2022 20:45
Oracle change notification issue
import oracle.jdbc.OracleConnection;
import oracle.jdbc.OracleStatement;
import oracle.jdbc.dcn.DatabaseChangeEvent;
import oracle.jdbc.dcn.DatabaseChangeListener;
import oracle.jdbc.dcn.DatabaseChangeRegistration;
import oracle.jdbc.pool.OracleDataSource;
import org.junit.Rule;
import org.junit.Test;
import org.testcontainers.Testcontainers;
import org.testcontainers.containers.JdbcDatabaseContainer;
@raphw
raphw / run.sh
Last active February 18, 2024 08:48
Runs Mockito on Graal VM
#!/bin/bash
set -x
set -e
if [[ -z $1 ]]; then
echo "Specify location of Graal VM as first argument"
exit 1
fi
$1/bin/gu install native-image
rm -rf META-INF sample sample.build_artifacts.txt Sample.* *.jar
echo "public class Sample {
@raphw
raphw / XsdSample.java
Last active August 14, 2021 20:56
Sample for use of schemata without location specification.
import org.w3c.dom.ls.LSInput;
import javax.xml.XMLConstants;
import javax.xml.bind.util.JAXBSource;
import javax.xml.transform.dom.DOMSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;