Skip to content

Instantly share code, notes, and snippets.

View justADeni's full-sized avatar

Deni justADeni

View GitHub Profile
@justADeni
justADeni / Java Periodic table of elements.java
Last active March 29, 2023 15:25 — forked from felixdivo/Java Periodic table of elements.java
This Java enum (=singleton) provides information about the elements of the periodic table (PTE). (Symbol, full name, atomic number, average atomic mass and electron negativity by Pauling) It can be searched by symbol and atomic number.
package divo.felix.chem.pte;
import java.util.HashMap;
import java.util.Map;
/**
* Holds information of the periodic table of elements.
*
* @author Felix Divo
*/
// Allows for packing coordinates ranging from -67_108_864 to 67_108_863
// on X and Z axis, and -64 to 320 on Y axis into one compact long
enum XYZ {
X,
Y,
Z;
public static long pack(int x, int y, int z) {
@justADeni
justADeni / Result.java
Created June 17, 2025 19:17
Utility for launching N amount of threads at the same time and getting a result once the first succeeds or all fail.
public sealed interface Result<T> permits Result.Success, Result.Failure {
record Success<T>(T value) implements Result<T> {}
final class Failure<T> implements Result<T> {}
}
@justADeni
justADeni / build.yml
Last active August 3, 2025 16:31
Actions workflow to tag, build and release a maven project
name: Auto Tag, Build, and Release
on:
workflow_dispatch:
push:
paths:
- 'pom.xml'
- 'src/**'
pull_request:
paths:
@justADeni
justADeni / Quaternion.java
Created October 26, 2025 15:22
Rotate a vector about a center at angle and axis
import org.joml.Quaternionf;
import org.joml.Vector3f;
public class Main {
public static void main(String[] args) {
Vector3f display = new Vector3f(0,10,0);
Vector3f center = new Vector3f(0,0,0);
float angle = 90f;
Vector3f axis = new Vector3f(1,0,0);
@justADeni
justADeni / Lazy.java
Last active November 25, 2025 23:10
Lazy Supplier
import java.util.function.Supplier;
@FunctionalInterface
interface Lazy<T> extends Supplier<T> {
T get();
static <T> Lazy<T> of(Supplier<T> supplier) {
return new LazyImpl<>(supplier);
}
}
@justADeni
justADeni / Species.java
Created November 29, 2025 03:41
Util method for getting the right species size when working with Java Vector API
import jdk.incubator.vector.VectorShape;
import jdk.incubator.vector.VectorSpecies;
private static <T> VectorSpecies<T> findSpecies(Class<?> type, int amount) {
int bitsize = VectorSpecies.elementSize(type) * amount;
VectorShape vectorShape = VectorShape.forBitSize(bitsize);
return (VectorSpecies<T>) VectorSpecies.of(type, vectorShape);
}