Skip to content

Instantly share code, notes, and snippets.

View bmaggi's full-sized avatar

Benoit Maggi bmaggi

  • Bordeaux, France
View GitHub Profile
@bmaggi
bmaggi / ExampleTest.java
Created January 6, 2021 16:25
Junit 5 Custom Parameter Source with NaughtyString https://github.com/minimaxir/big-list-of-naughty-strings
class ExampleTest {
@ParameterizedTest
@NaughtyStringSource
void myTest( String ex) {
Assertions.assertNotNull(ex);
}
}
@bmaggi
bmaggi / BooleanArgumentsProvider.java
Created December 16, 2020 14:20
Junit 5 Custom Parameter Source with Boolean as Example
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.support.AnnotationConsumer;
import java.util.stream.Stream;
public class BooleanArgumentsProvider implements ArgumentsProvider, AnnotationConsumer<BooleanSource> {
BooleanArgumentsProvider() {

Stevey's Google Platforms Rant

I was at Amazon for about six and a half years, and now I've been at Google for that long. One thing that struck me immediately about the two companies -- an impression that has been reinforced almost daily -- is that Amazon does everything wrong, and Google does everything right. Sure, it's a sweeping generalization, but a surprisingly accurate one. It's pretty crazy. There are probably a hundred or even two hundred different ways you can compare the two companies, and Google is superior in all but three of them, if I recall correctly. I actually did a spreadsheet at one point but Legal wouldn't let me show it to anyone, even though recruiting loved it.

I mean, just to give you a very brief taste: Amazon's recruiting process is fundamentally flawed by having teams hire for themselves, so their hiring bar is incredibly inconsistent across teams, despite various efforts they've made to level it out. And their operations are a mess; they don't real

@bmaggi
bmaggi / RedissonManualLock.java
Created October 9, 2019 10:00
a simple way to lock key in Redis using Redisson
import org.redisson.Redisson;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import java.util.concurrent.TimeUnit;
class RedissonManualLock {
// a simple way to lock key in Redis using Redisson
@bmaggi
bmaggi / FunIsOptional.java
Created October 9, 2019 09:42
Small reminder that orElse parameter is evaluated
import java.util.Optional;
public class FunIsOptional {
public static void main(String[] args) {
Integer i = 0;
System.out.println(Optional.of(i).map(v -> v++).orElse(i--));
// => res = 0 (orElse is evaluated even when not empty)
}
@bmaggi
bmaggi / TimeChange.java
Created April 5, 2019 15:49
Example of date change (France,Brasil)
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.util.Date;
import java.util.TimeZone;
class TimeChange {
public static void main(String[] args) throws ParseException {
timeForward("Europe/Paris", "2019-03-31 01:59:59", Duration.ofSeconds(2).toMillis()); // FRANCE +1
@bmaggi
bmaggi / JavaRandom
Last active July 26, 2019 07:11
Java Random primitive generation (basic Api only)
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.time.Instant;
class JavaRandom {
public static void main(String[] args) {
@bmaggi
bmaggi / Scratch.java
Last active July 8, 2022 02:34
Transform KafakFuture <-> CompletableFuture
// See https://issues.apache.org/jira/browse/KAFKA-6987 for ongoing work on KafkaFuture implementation of CompletableFuture
private <T> CompletableFuture<T> toCompletableFuture(final KafkaFuture<T> kafkaFuture) {
final CompletableFuture<T> wrappingFuture = new CompletableFuture<>();
kafkaFuture.whenComplete((value, throwable) -> {
if (throwable != null) {
wrappingFuture.completeExceptionally(throwable);
} else {
wrappingFuture.complete(value);
}
});