Skip to content

Instantly share code, notes, and snippets.

View stanio's full-sized avatar

Stanimir Stamenkov stanio

View GitHub Profile
@stanio
stanio / CommandLine.java
Created October 17, 2023 21:43
Poor man's command-line parser
/*
* 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 / SuperXBR.java
Last active October 18, 2022 01:24
Super-xBR Scaler: https://pastebin.com/cbH8ZQQT (Java version)
/*
* Copyright (c) 2016 Hyllian - sergiogdb@gmail.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@stanio
stanio / MySQLLockService.java
Last active March 25, 2022 20:19
Liquibase LockService using database session-level locks (moved to https://github.com/blagerweij/liquibase-sessionlock)
/*
* This module, both source code and documentation,
* is in the Public Domain, and comes with NO WARRANTY.
*/
package net.example.liquibase.lockservice.ext;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@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 / 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;