Skip to content

Instantly share code, notes, and snippets.

View stanio's full-sized avatar

Stanimir Stamenkov stanio

View GitHub Profile
/*
* Copyright (C) 2023 by Stanio <stanio AT yahoo DOT com>
* Released under BSD Zero Clause License: https://spdx.org/licenses/0BSD
*/
package io.github.stanio.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@stanio
stanio / DynamicImageTranscoder.java
Last active October 14, 2023 22:00
(Batik) Rendering a dynamic SVG document to an offscreen buffer
/*
* Copyright (C) 2023 by Stanio <stanio AT yahoo DOT com>
* Released under BSD Zero Clause License: https://spdx.org/licenses/0BSD
*/
package io.github.stanio.batik;
// java.base
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Path;
@stanio
stanio / FloatTest.java
Created October 3, 2023 16:03
Debugging float bits
//package ;
import java.math.BigDecimal;
import java.util.Locale;
public class FloatTest {
// FloatConsts.SIGNIFICAND_WIDTH - 1
static final int SIGNIF_SIZE = 23;
@stanio
stanio / Sync.java
Last active August 21, 2023 08:19
Utility for working with Locks (replacing synchronized blocks)
/*
* This module, both source code and documentation,
* is in the Public Domain, and comes with NO WARRANTY.
*/
package net.example.concurrent;
import static java.util.Objects.requireNonNull;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
@stanio
stanio / VolatileResources.java
Created June 19, 2023 08:11
Fail-safe Resource Initialization
/*
* This module, both source code and documentation,
* is in the Public Domain, and comes with NO WARRANTY.
*/
//package ;
import java.util.ArrayList;
import java.util.List;
/**
@stanio
stanio / XMLDoctype.java
Last active May 19, 2023 13:59
Fast XML document type detection
/*
* This module, both source code and documentation,
* is in the Public Domain, and comes with NO WARRANTY.
*/
//package ;
import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE; // requires java.xml
// requires java.base
import java.io.IOException;
@stanio
stanio / ObjectDump.java
Created December 11, 2020 06:30
Dump object's internal state
package net.example.util;
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@stanio
stanio / HTMLEditorKitWorkaround.java
Last active December 11, 2020 17:13
HTMLEditorKit: CSS relative font-size bug
package net.example.swing;
import java.io.Serializable;
import java.util.Enumeration;
import javax.swing.text.AttributeSet;
import javax.swing.text.Document;
import javax.swing.text.StyleConstants;
import javax.swing.text.View;
import javax.swing.text.html.CSS;
import javax.swing.text.html.HTMLDocument;
@stanio
stanio / MrImageObserverLeakTest.java
Last active June 21, 2021 06:54
MultiResolutionToolkitImage.ObserverCache memory leak
package net.example.swing;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
@stanio
stanio / Avg.java
Last active October 11, 2020 13:43
Calculating the average incrementally
//package ;
/**
* @see <a href="https://ubuntuincident.wordpress.com/2012/04/25/calculating-the-average-incrementally/">Calculating the average incrementally</a>
*/
public class Avg {
private double value = Double.NaN;
private long count;