Skip to content

Instantly share code, notes, and snippets.

@netcall-jlo
netcall-jlo / findInObject.js
Created August 8, 2023 07:48
Allows an object to be searched to try and find a specific key or value. Useful for debugging
/**
* Finds any matches within the given object that satisfy the given search
* function.
*
* @param {Object} object
* Object to search.
* @param {Function} search
* Function that will identify a match. The function is passed the
* key, the value, and the full path. If it returns any truthy value
* then the result will be considered a match.
@netcall-jlo
netcall-jlo / getScrollingParent.js
Created August 8, 2023 07:50
A function that takes an element and finds the parent element that scrolls. Useful in very specific circumstances
/**
* Takes an element and finds the parent element that would scroll.
*
* @param {Element} element
* Element whose scrolling parent should be returned.
* @return {Element|null}
* Parent element that scrolls. If no parent can be found, null is
* returned.
*/
function getScrollingParent(element) {
@netcall-jlo
netcall-jlo / responsive.html
Created January 30, 2024 09:45
A quick demonstration of responsive JavaScript - based on a video whose URL I no longer remember
<!doctype html>
<html lang="en-GB">
<head>
<title>Testing reactivity</title>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,width=device-width">
</head>
@netcall-jlo
netcall-jlo / cache.ts
Last active February 2, 2024 10:59
Playing with a type-safe cache
export class Cache<
TLookupMap extends Record<string, any> = {},
K extends keyof TLookupMap = keyof TLookupMap
> {
private key: string;
private storage: Record<K, TLookupMap[K]>;
constructor(key: string) {