Skip to content

Instantly share code, notes, and snippets.

View cykl's full-sized avatar

Clément MATHIEU cykl

View GitHub Profile
@cykl
cykl / Wither.java
Created May 16, 2022 08:34
Reflection based record wither prototype
interface Wither<T extends Record> {
default <V> T with( SerializableSupplier<V> accessor, V newValue ) {
try {
var providedAccessor = accessor.method( );
var components = R.class.getRecordComponents( );
var accessors = Arrays.stream( components )
.map( RecordComponent::getAccessor )
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.logging.LoggingApplicationListener;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.boot.logging.logback.LogbackLoggingSystem;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.GenericApplicationListener;
import org.springframework.core.ResolvableType;
import org.springframework.core.env.ConfigurableEnvironment;
@cykl
cykl / TypeResolverTest.java
Last active July 5, 2017 21:11
Code sample to figure out how to check whether the return type of two methods are equals (including generics). See https://github.com/joel-costigliola/assertj-core/issues/1005
package cma.sandox;
import com.google.common.reflect.TypeResolver;
import org.assertj.core.api.WithAssertions;
import org.junit.Test;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
@cykl
cykl / DTFBenchmark.java
Created October 9, 2016 14:29
DateTimeFormatter benchmark
package info.unportant.gist.jsr310;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
@cykl
cykl / HyperthymesticMRPipeline.java
Last active January 6, 2016 14:10
[Crunch] POC: Avoid the MateralizableIterable dance by storing all the PipelineResults in the pipeline instance.
package fr.mediametrie.internet.weball.crunch;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.apache.crunch.PipelineResult;
import org.apache.crunch.impl.mr.MRPipeline;
import org.apache.crunch.impl.mr.MRPipelineExecution;
import org.apache.hadoop.conf.Configuration;
@cykl
cykl / Main.java
Created January 1, 2015 17:39
Demonstrate how to "abuse" ApplicationClassLoader to relieve JAR version conflicts in Hadoop launchers. (Has been fixed in Hadoop 2.6.0, see https://issues.apache.org/jira/browse/HADOOP-10893)
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
public class Main {
private static String TOOL_CL_NAME = "MyTool";
public static void main(String[] args) throws Exception {
RunJarClassLoader toolClassLoader = RunJarClassLoader.fromContextClassLoader();
toolClassLoader.installAsContextClassLoader();
@cykl
cykl / Main.java
Created August 20, 2014 06:33
HashMap VS TreeMap memory footprint
import org.openjdk.jol.info.GraphLayout;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
public class Main {
static final int SIZE = 1<<18;
static final double LOAD_FACTOR = 0.75;
@cykl
cykl / JMH_output.txt
Last active August 29, 2015 13:57
Companion code for JDK 8 @contended article
# Run progress: 0.00% complete, ETA 00:07:21
# VM invoker: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.0.x86_64/jre/bin/java
# VM options: -XX:-RestrictContended
# Fork: 1 of 3
# Warmup: 3 iterations, 1 s each
# Measurement: 6 iterations, 3 s each
# Threads: 4 threads, will synchronize iterations
# Benchmark mode: Average time, time/op
# Benchmark: gist.contended.Benchmarks.contendedArray
# Warmup Iteration 1: 66.198 ns/op
@cykl
cykl / HLLMergeBenchmark.java
Created June 2, 2013 18:32
Benchmarks for stream-lib/faster_hll
package bench;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.BenchmarkType;
import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.State;
@cykl
cykl / CyclicBarrierExample.java
Last active December 14, 2015 18:39
Demonstrate how to use Semaphore, Exchanger and CyclicBarrier to achieve following behavior: * two cooperating threads * mutual exclusion * Each thread execute after the other following a strict round robin schedule
package info.unportant.test.testnb;
import java.util.concurrent.CyclicBarrier;
public class CyclicBarrierExample {
static private void sleep(String msg) {
int msec = (int) (Math.random() * 1000);
System.out.println(msg + " sleep");
try {