Skip to content

Instantly share code, notes, and snippets.

@HaloFour
HaloFour / NoCurseWordsAnalyzer.cs
Created January 3, 2023 18:31
ChatGPT Roslyn Analyzer
using System;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
namespace MyAnalyzers
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
@HaloFour
HaloFour / TestProject.java
Last active October 13, 2021 14:10
Reactor Netty using context-aware HTTP server metrics
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.time.Duration;
import reactor.core.publisher.Mono;
import reactor.netty.Connection;
import reactor.netty.ConnectionObserver;
import reactor.netty.http.server.ContextAwareHttpServerMetricsRecorder;
@HaloFour
HaloFour / Example.java
Created September 21, 2021 15:26
TracingOperator with Context
import java.util.function.BiFunction;
import java.util.function.Function;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Scope;
@HaloFour
HaloFour / TypeArgumentResolver.java
Created June 6, 2021 16:16
Helper class for resolving actual type arguments of a generic superclass
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.instrumentation.api.tracer;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
@HaloFour
HaloFour / NettyTest.java
Last active March 14, 2021 15:47
Test Netty Reactor Connection Pooling
import java.time.Duration;
import java.util.Random;
import java.util.concurrent.atomic.AtomicReference;
import io.netty.handler.codec.http.HttpHeaderNames;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.publisher.Sinks;
import reactor.netty.http.client.HttpClient;
import reactor.netty.http.server.HttpServer;
@HaloFour
HaloFour / Async.java
Created July 17, 2020 00:18
Async/Await in Loom
package sandbox;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import org.reactivestreams.Subscription;
import reactor.core.CoreSubscriber;
import reactor.core.Exceptions;
import reactor.core.publisher.Mono;
@HaloFour
HaloFour / Generators.java
Created July 17, 2020 00:18
Generators in Loom
package sandbox;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.function.Consumer;
public class Generators {
private static final ContinuationScope continuationScope = new ContinuationScope("Generators");
public static <T> Iterable<T> createGenerator(Consumer<Consumer<T>> consumer) {
@HaloFour
HaloFour / LoomTest.java
Created July 15, 2020 22:26
Experiments with Project Loom
package sandbox;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.CountDownLatch;
@HaloFour
HaloFour / StreamingJsonArrayExtractor.java
Created April 23, 2020 14:25
Reactive JSON Array Extractor
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonPointer;
@HaloFour
HaloFour / Test.cs
Last active March 31, 2020 17:32
Test inheritance with struct builders
/*
public record class Person {
public required int ID { get; init; }
public string FirstName { get; init; }
public string LastName { get; init; }
Person {
if (ID < 0) throw new ArgumentOutOfRangeException(nameof(ID));
}
}