Skip to content

Instantly share code, notes, and snippets.

View bric3's full-sized avatar
💭
🤨

Brice Dutheil bric3

💭
🤨
View GitHub Profile
/*
* DiscusToGiscus.java
*
* Copyright (c) 2021,today - Brice Dutheil <brice.dutheil@gmail.com>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
///usr/bin/env jbang "$0" ; exit $?
@bric3
bric3 / Stonks.java
Last active December 19, 2023 12:59
/*
* Stonks.java
*
* Copyright (c) 2021,today - Brice Dutheil <brice.dutheil@gmail.com>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
///usr/bin/env jbang "$0" ; exit $?
@bric3
bric3 / HttpClientBug.java
Created September 5, 2022 10:38
Work-around for JDK-8217627 (HttpClient hangs/blocks) when using a BodySubscribers.mapping with a GZIPInputStream. Fixed in JDK13.
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.function.Function;
@bric3
bric3 / InteractiveTableCellsMain.java
Last active September 2, 2022 12:28
Swing dance with JTable to have readonly interactive cells
import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.Objects;
import javax.swing.*;
import javax.swing.event.MouseInputAdapter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableColumn;
public final class InteractiveTableCellsMain extends JPanel {
@bric3
bric3 / GraalJsDemo.java
Last active January 7, 2023 14:27
Simple snippet showcasing hello-word scenario to run the Graal JS Engine.
/*
* GraalJsDemo.java
*
* Copyright (c) 2021,today - Brice Dutheil <brice.dutheil@gmail.com>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
///usr/bin/env jbang "$0" ; exit $?
@bric3
bric3 / # async-profiler - 2022-05-17_16-03-41.txt
Created May 17, 2022 14:11
async-profiler (bric3/tap/async-profiler) on macOS 12.3 - Homebrew build logs
Homebrew build logs for bric3/tap/async-profiler on macOS 12.3
Build date: 2022-05-17 16:03:41
val fireplaceLocation = extra.has("fireplaceLocation").let {
if (it) extra.get("fireplaceLocation") as String
else null
}
if (!fireplaceLocation.isNullOrEmpty()) {
val location = when {
fireplaceLocation.startsWith("\$HOME") || fireplaceLocation.startsWith("~") -> {
fireplaceLocation.replaceFirst("~|\$HOME".toRegex(), System.getProperty("user.home"))
}
@bric3
bric3 / java-dep-size-init.gradle.kts
Created February 10, 2022 11:27
Gradle init script that adds `depsize` task that will display the size of each dependencies.
/*
* Registers tasks to get the dependency size
*/
fun listConfigurationDependencies(configuration: Configuration ) {
val multiplier = 1024.0
val formatStr = "%,10.2f"
val size = configuration.map { it.length() / (multiplier * multiplier) }.sum()
@bric3
bric3 / ExponentialBackoff.java
Last active February 3, 2022 10:47
Exponential backoff counter implementing the Full Jitter algorithm from AWS article by Marc Brooker
import java.util.Random;
/**
* Exponential backoff counter implementing the Full Jitter algorithm from <a href="https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/">aws</a> by Marc Brooker.
*
* <p>
* The idea of backoff is to introduce a delay between retries, so that client don't compete
* on the same resource. However it has been observed that clients may retry at the same time,
* thus clustering calls on the same resource.
* </p>
@bric3
bric3 / ShadowTest.java
Created February 1, 2022 10:51 — forked from mattdesl/ShadowTest.java
Simple Dynamic Shadows in Java2D
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Polygon;
import java.awt.RadialGradientPaint;
import java.awt.RenderingHints;
import java.awt.Shape;