Skip to content

Instantly share code, notes, and snippets.

View bric3's full-sized avatar
💭
🤨

Brice Dutheil bric3

💭
🤨
View GitHub Profile
@bric3
bric3 / svg-patch.gradle.kts
Last active October 21, 2024 13:07
SVG Patcher for gradle using Stax Approach (does not maintain order)
import java.io.StringWriter
import javax.xml.namespace.QName
import javax.xml.stream.XMLEventFactory
import javax.xml.stream.XMLInputFactory
import javax.xml.stream.XMLOutputFactory
import javax.xml.stream.events.Attribute
import javax.xml.stream.events.StartElement
tasks.register<GenerateDarkIconVariant>("patchSVG")
abstract class GenerateDarkIconVariant @Inject constructor(project: Project) : DefaultTask() {
@bric3
bric3 / CodeBlockNodeRenderer.kt
Last active May 6, 2024 14:01
HTML `JEditor` pane for IntelliJ (and markdown code snippet with highlighting), for pre `JBHtmlPane`
import com.intellij.lang.Language
import com.intellij.lang.documentation.DocumentationSettings
import com.intellij.lang.documentation.DocumentationSettings.InlineCodeHighlightingMode.NO_HIGHLIGHTING
import com.intellij.lang.documentation.DocumentationSettings.InlineCodeHighlightingMode.SEMANTIC_HIGHLIGHTING
import com.intellij.openapi.editor.HighlighterColors
import com.intellij.openapi.editor.colors.EditorColorsManager
import com.intellij.openapi.editor.richcopy.HtmlSyntaxInfoUtil
import com.intellij.openapi.fileTypes.PlainTextLanguage
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.text.StringUtil
/*
* DiscusToGiscus.java
*
* Copyright (c) 2021,today - Brice Dutheil <[email protected]>
*
* 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 <[email protected]>
*
* 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 <[email protected]>
*
* 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()