Skip to content

Instantly share code, notes, and snippets.

View bric3's full-sized avatar
💭
🤨

Brice Dutheil bric3

💭
🤨
View GitHub Profile
@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 / 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 / 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 / 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 / IsATTY.java
Created June 8, 2021 15:42
Allows to determine if standard stream are connected to a terminal. Calls native isatty C function, and dynamically build the wrapper code.
/*
* 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
* 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
@bric3
bric3 / Sparkline.java
Last active May 17, 2021 13:59
Sparkline in java (requires JDK 16, because of Stream::toArray and raw Strings)
package sandbox;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@bric3
bric3 / Jacoco.md
Created May 5, 2021 22:33
Jacoco and Java 15
 > Task :testjava.lang.instrument.IllegalClassFormatException: Error while instrumenting sun/util/resources/cldr/provider/CLDRLocaleDataMetaInfo.
	at org.jacoco.agent.rt.internal_43f5073.CoverageTransformer.transform(CoverageTransformer.java:94)
	at java.instrument/java.lang.instrument.ClassFileTransformer.transform(ClassFileTransformer.java:246)
	at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
	at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:563)
	at java.base/java.lang.ClassLoader.defineClass2(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1108)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:183)
@bric3
bric3 / jdk-mission-control-snapshot.rb
Created November 30, 2020 10:37
Brew formula for JDK Mission Control 8 SNAPSHOT
# 1. brew cask create jdk-mission-control
# 2. brew edit jdk-mission-control-snapshot
# 3. Then paste this content
cask 'jdk-mission-control-snapshot' do
version :latest
sha256 :no_check
url do
# was 'https://ci.adoptopenjdk.net/view/JMC/job/jmc-build/job/master/lastSuccessfulBuild/artifact/target/products/org.openjdk.jmc-macosx.cocoa.x86_64.tar.gz'
'https://ci.adoptopenjdk.net/view/JMC/job/jmc-build/job/master/lastSuccessfulBuild/artifact/target/products/org.openjdk.jmc-8.0.0-SNAPSHOT-macosx.cocoa.x86_64.tar.gz'
@bric3
bric3 / pod-analysis.json
Last active February 18, 2021 16:00
Kubernetes JVM pod analysis using Micrometer, Istio, and Kube state metrics
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"limit": 100,