Skip to content

Instantly share code, notes, and snippets.

View bric3's full-sized avatar
💭
🤨

Brice Dutheil bric3

💭
🤨
View GitHub Profile
@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:");
@bric3
bric3 / docker-tag-groups.sh
Last active July 9, 2021 13:22
Group all docker tags by image
#!/usr/bin/env bash
set -euo pipefail
#set -o xtrace
image=${1};
wanted_tag=${2:-""};
max_pages=10;
grouped_tags_tmp=$(mktemp);
@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 / UTF-8-demo.txt
Last active March 10, 2021 08:14
Shell (commands) tips accumulated over years
UTF-8 encoded sample plain-text file
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
Markus Kuhn [ˈmaʳkʊs kuːn] <http://www.cl.cam.ac.uk/~mgk25/> — 2002-07-25 CC BY
The ASCII compatible UTF-8 encoding used in this plain-text file
is defined in Unicode, ISO 10646-1, and RFC 2279.
@bric3
bric3 / PrivateConstructors.java
Created August 27, 2020 08:13
Uses MethodHandle to access private package
public abstract class PrivateConstructors {
// public class CustomIterable<V> implements Iterable<V> {
// CustomIterable() {}
// }
@SuppressWarnings("unchecked")
private static <I extends T, T> I newInstanceOf(Class<T> clazz) throws Throwable {
MethodHandles.Lookup lookup = MethodHandles.privateLookupIn(clazz, MethodHandles.lookup());
MethodHandle methodHandle = lookup.findConstructor(clazz, MethodType.methodType(void.class));
@bric3
bric3 / CryptoHackerUsageTest.java
Last active March 9, 2021 15:06
Pre-JKD8u151 that allows to modify the AES key length
import org.junit.Test;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
@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,
@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'