Skip to content

Instantly share code, notes, and snippets.

@markotny
markotny / fromFetchStream.ts
Last active October 26, 2023 18:05
Fetch streaming to rxjs (e.g. .NET IAsyncEnumerable)
import {Observable} from 'rxjs';
/**
* Stream server data (e.g. from endpoint returning IAsyncEnumerable)
* @type T type of stream element
* @param input input param of {@link fetch}
* @param init init param of {@link fetch} (excluding abort signal)
* @return stream of array elements one by one
*/
export function fromFetchStream<T>(input: RequestInfo, init?: RequestInit): Observable<T> {
@markotny
markotny / TestOutputBuffer.cs
Created March 29, 2022 17:53
xUnit ITestOutputHelper integration with MEL
using Microsoft.Extensions.Logging;
namespace XunitLogging;
/// <summary>
/// Buffers all logs in a queue until an actual ILogger is registered
/// </summary>
internal class TestOutputBuffer : ILogger
{
private readonly Queue<Action<ILogger>> _bufferedLogs = new();
@markotny
markotny / ExpressionExtensions.cs
Last active December 9, 2022 13:40
IQueryable LeftJoin extension
using System.Linq.Expressions;
namespace LeftJoin;
public static class ExpressionExtensions
{
/// <inheritdoc cref="Compose{TFunc}"/>
public static Expression<Func<P1, TRes>> Compose<P1, TP1, TRes>(
this Expression<Func<TP1, TRes>> function,
Expression<Func<P1, TP1>> firstParamSelector)