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 / Dexie.min.js
Last active November 25, 2015 22:45 — forked from nolanlawson/Dexie.min.js
IndexedDB+Dexie+Lunr MTG full-text search demo
(function(n,t,i,r){"use strict";function h(n,t){return typeof t!="object"&&(t=t()),Object.keys(t).forEach(function(i){n[i]=t[i]}),n}function y(n){return{from:function(t){return n.prototype=Object.create(t.prototype),n.prototype.constructor=n,{extend:function(i){h(n.prototype,typeof i!="object"?i(t.prototype):i)}}}}}function p(n,t){return t(n)}function f(t){function or(){if(i)w.on("versionchange",function(t){w.close();t.newVersion&&n.location.reload(!0)})}function ki(n){this._cfg={version:n,storesSource:null,dbschema:{},tables:{},contentUpgrade:null};this.stores({})}function sr(n,t,i,r){var e,f,o,h,l,c;if(n==0)Object.keys(pt).forEach(function(n){di(t,n,pt[n].primKey,pt[n].indexes)}),e=w._createTransaction(kt,ri,pt),e.idbtrans=t,e.idbtrans.onerror=s(i,["populating database"]),e.on("error").subscribe(i),u.newPSD(function(){u.PSD.trans=e;try{w.on("populate").fire(e)}catch(n){r.onerror=t.onerror=function(n){n.preventDefault()};try{t.abort()}catch(f){}t.db.close();i(n)}});else{if(f=[],o=ii.filter(function(t){return
@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;
}