Skip to content

Instantly share code, notes, and snippets.

@cherrydev
cherrydev / ListIntersection.kt
Created March 18, 2022 04:25
Fast functions for intersecting sorted lists in Kotlin, returning Lists or Sequences
import kotlin.math.*
object ListIntersection {
fun <T : Comparable<T>> safeIntersection(l1: List<T>, l2: List<T>) : List<T> {
return l1.intersect(l2).sorted()
}
// https://stackoverflow.com/a/33963306/480176
@cherrydev
cherrydev / gist:5c7168c8947eb1a1b5b8
Created April 30, 2015 01:04
Creating a testable service that accesses the current ClaimsPrincipal
public interface ICurrentPrincipalAccessor {
ClaimsPrincipal CurrentPrincipal { get; }
}
public class HttpContextCurrentPrincipalAccessor : ICurrentPrincipalAccessor {
private IHttpContextAccessor _httpContextAccessor;
public HttpContextCurrentPrincipalAccessor(IHttpContextAccessor httpContextAccessor) {
_httpContextAccessor = httpContextAccessor;
}