Skip to content

Instantly share code, notes, and snippets.

View bric3's full-sized avatar
💭
🤨

Brice Dutheil bric3

💭
🤨
View GitHub Profile
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 / develop-jmc-ij.md
Last active March 20, 2022 23:50
Develop JDK Mission Control within IntelliJ

Opening in IJ

JMC with IntelliJ

At this stage there’s two approach:

  • If you only need to work on the core libraries, then you only need those, and they can be imported as a maven project with some configuration
  • If you need the full blown JMC, then you need the other import approach, that is a mix of .project - .classpath and Maven projects.

Working on the on the core libraries

  1. File | Open… , then select the core folder in the JMC cloned repository,
  2. Trust the project (also tick the Trust projects in <JMC clone path> as well)
@bric3
bric3 / task-info.gradle.kts
Last active February 10, 2022 12:43
Apply task-info in order to access tiTree task on all gradle project. Pu this in `~/.gradle/init.d/taskinfo.gradle.kts`
initscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath("gradle.plugin.org.barfuin.gradle.taskinfo:gradle-taskinfo:1.3.1")
}
}
// don't use rootProject as it may not be ready
allprojects {
@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;
@bric3
bric3 / upgrade-nashorn-to-graaljs.adoc
Last active January 20, 2022 17:55
Upgrade to / use GraalJS (instead of nashorn)

Nashorn is deprecated since Java 11, it has been removed in Java 15. In order to run javascript, it is necessary to upgrade the script engine. The most common alternative as of now is GraalVM JS engine.

build.gralde
  dependencies {
+     implementation("org.graalvm.js:js:22.0.0")
+     implementation("org.graalvm.js:js-scriptengine:22.0.0")
@bric3
bric3 / RaAssembler.java
Last active December 25, 2021 15:42
Simple script that can assemble an ebook from Ra chapters available on qntm.
///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 17
//DEPS org.jsoup:jsoup:1.14.3
/*
* MIT License
*
* Copyright (c) 2021 Brice Dutheil <brice.dutheil@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
@bric3
bric3 / Main.java
Created September 25, 2021 00:04
Issue with swift and symbol lookup
import jdk.incubator.foreign.CLinker;
import jdk.incubator.foreign.FunctionDescriptor;
import jdk.incubator.foreign.MemoryAddress;
import jdk.incubator.foreign.ResourceScope;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.HexFormat;
public class Main {
@bric3
bric3 / JavaPmapInspector.java
Last active September 23, 2021 08:42
Inspect pmap -X output of a java process, requires Java11, may not be 100% accurate
/*
Moved here => https://github.com/bric3/java-pmap-inspector
*/
public class JavaPmapInspector {
public static void main(String[] args) throws IOException {
System.err.println("Go to:");