Skip to content

Instantly share code, notes, and snippets.

View TrooperT's full-sized avatar
🎉

Sam TrooperT

🎉
  • Dayton, OH, USA
View GitHub Profile
func typeCache[T any](compute func(t reflect.Type) T) func(t reflect.Type) T {
cache := map[reflect.Type]T{}
return func(t reflect.Type) T {
if v, ok := cache[t]; ok {
return v
}
v := compute(t) // but compute cant recurse
cache[t] = v
return v
}
@TrooperT
TrooperT / waitForKeyElements.js
Created January 30, 2020 15:21 — forked from BrockA/waitForKeyElements.js
A utility function, for Greasemonkey scripts, that detects and handles AJAXed content.
/*--- waitForKeyElements(): A utility function, for Greasemonkey scripts,
that detects and handles AJAXed content.
Usage example:
waitForKeyElements (
"div.comments"
, commentCallbackFunction
);