This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Converts an iterable to an object, keeping only key/value pairs that are both strings. | |
*/ | |
function pickStringKeysAndValues< | |
T extends { entries(): IterableIterator<[unknown, unknown]> }, | |
>(iterable: T): Record<string, string> { | |
let result: Record<string, string> = {}; | |
for (let [key, value] of iterable.entries()) { | |
if (typeof key === 'string' && typeof value === 'string') { | |
result[key] = value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Module-level variable where all of the global dependency injection | |
* overrides are stored. | |
*/ | |
const provisions = new Map<unknown, unknown>(); | |
/** | |
* Adds an override to the global dependency injection context. | |
* TypeScript ensures that the signature of the override is the same | |
* as that of the dependency being overridden. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function keyMirror<Obj>(...args: (keyof Obj)[]): Readonly<{ [Key in keyof Obj]: Key }> { | |
let obj = {}; | |
for (let arg of args) { | |
Object.defineProperty(obj, arg, { | |
configurable: false, | |
enumerable: true, | |
value: arg, | |
writable: false, | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const $dependencyContext = Symbol(); | |
/** | |
* The provide function would be called at the root of the application, | |
* or at the "root" of a dynamically imported module. | |
*/ | |
function provide<T extends Record<symbol, any>>(deps: T) { | |
(globalThis as any)[$dependencyContext] = { | |
...(globalThis as any)[$dependencyContext], | |
...deps, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function windowIpsum(numberOfWords) { | |
const keys = Object.keys(window); | |
return [...Array(numberOfWords)] | |
.map(() => { | |
return keys[Math.floor(Math.random() * keys.length)]; | |
}) | |
.join(' '); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.plugins-container').replaceChildren(...Array.from($('.plugins-container').children).sort((a,b)=>parseInt(b.children[2].textContent.replace(/\D/g,''))-parseInt(a.children[2].textContent.replace(/\D/g,'')))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const robot = require('robotjs'); | |
const screenSize = robot.getScreenSize(); | |
(async () => { | |
while (true) { | |
robot.moveMouseSmooth( | |
Math.random() * screenSize.width, | |
Math.random() * screenSize.height, | |
1 | |
); | |
await new Promise((resolve) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const FileTreeStyles = styled.ul` | |
button { | |
font-family: monospace; | |
background: none; | |
border: 0; | |
padding: 0.125em 0; | |
&:hover { | |
background: #f002; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Methods I wish existed in the Array prototype | |
Array.prototype.filterEqual = function filterEqual(item) { | |
return this.filter(x => x === item); | |
} | |
Array.prototype.filterEqualBy = function filterEqualBy(key, item) { | |
return this.filter(x => x[key] === item); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
function useProxy<T>(initialValue: T) { | |
const [state, setState] = React.useState(initialValue); | |
const proxy = React.useMemo(() => { | |
return new Proxy( | |
{ value: state }, | |
{ | |
set(obj, prop, value) { | |
if (prop === 'value') { |
NewerOlder