- Make sure you have a modern-ish version of Node.js installed.
- Type
npx https://gist.github.com/kfox/1280c2f0ee8324067dba15300e0f2fd3
- Connect to it from a client, e.g.
netcat
or similar:nc localhost 9000
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'; | |
const useIsFirstRender = (): boolean => { | |
const isFirst = React.useRef(true); | |
if (isFirst.current) { | |
isFirst.current = false; | |
return true; | |
} else { |
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
"use client"; | |
import { cache, unstable_postpone } from "react"; | |
import { preload } from "react-dom"; | |
const loadImage = cache((src: string) => { | |
return new Promise<void>((resolve, reject) => { | |
const img = new Image(); | |
img.src = src; |
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 createLongLastingContext<T>(factory: () => T) { | |
const defaultValue = typeof document !== "undefined" ? factory() : null; | |
const ctx = React.createContext<T | null>(defaultValue); | |
return { | |
useContext: () => { | |
const value = React.useContext(ctx); | |
if (!value) { | |
throw new Error("Context not initialized."); | |
} | |
return 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
<%* | |
const editor = app.workspace.activeLeaf.view.editor; | |
if(editor.somethingSelected() === true) { | |
let selectedText = editor.getSelection(); | |
let splitLines = selectedText.split('\n'); | |
let finalOutput = ''; | |
let listItem = false; | |
let codeBlock = false; | |
splitLines.forEach(eachLine => { |
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
/*! | |
* ExternalTemplateRemotesPlugin | |
* License: MIT (https://mit-license.org/) | |
*/ | |
const extractUrlAndGlobal = require('webpack/lib/util/extractUrlAndGlobal'); | |
const { RawSource } = require('webpack-sources'); | |
const PLUGIN_NAME = 'ExternalTemplateRemotesPlugin'; |
This loader optimizes the output of mini-css-extract-plugin
and/or css-loader
,
entirely removing the potentially large CSS classname mappings normally inlined into your bundle when using CSS Modules.
Run npm install constant-locals-loader
, then make these changes in your Webpack config:
module.exports = {
module: {
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
type ValidationResult<T, U> = Partial<{ [Key in keyof T]: U }>; | |
type Validation<T, U> = (input: T) => ValidationResult<T, U>; | |
const mergeAll = <T, U>( | |
results: ValidationResult<T, U>[] | |
): ValidationResult<T, U> => | |
results.reduce((acc, a) => Object.assign(acc, a), {}); | |
const validate = <T, U = boolean | string>( | |
validations: Validation<T, U>[] |
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
// create context with no upfront defaultValue | |
// without having to do undefined check all the time | |
function createCtx<A>() { | |
const ctx = React.createContext<A | undefined>(undefined) | |
function useCtx() { | |
const c = React.useContext(ctx) | |
if (!c) throw new Error("useCtx must be inside a Provider with a value") | |
return c | |
} | |
return [useCtx, ctx.Provider] as const |
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 { useEffect } from 'react' | |
import hotkeys from 'hotkeys-js' | |
export const useHotkeys = (key: string, cb: () => any, inputs?: any[]) => { | |
useEffect(() => { | |
hotkeys(key, cb) | |
return () => hotkeys.unbind(key) | |
}, inputs) | |
} |
NewerOlder