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
/** | |
* The command to see the animation: | |
* curl localhost:3000 | |
* | |
* @see https://github.com/alexeyraspopov/picocolors/blob/main/picocolors.js | |
* @see https://github.com/sindresorhus/ansi-escapes/blob/main/index.js | |
* @see https://github.com/sindresorhus/cli-spinners | |
*/ | |
import { Readable } from "node:stream"; | |
import { fastify } from "fastify"; |
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 Component from '@ember/component'; | |
export default Component.extend({ | |
tagName: '', | |
key: undefined, | |
keys: Ember.computed('key', function () { | |
return [{ | |
key: String(this.get("key")) | |
}]; | |
}).readOnly(), |
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
export class ScopedStorage implements Storage { | |
[name: string]: any; | |
#storage: Storage; | |
#prefix: string; | |
constructor(storage: Storage, prefix: string) { | |
this.#storage = storage; | |
this.#prefix = prefix; |
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 ResizeObserver from "resize-observer-polyfill"; | |
import * as React from "react"; | |
import ReactDOM from "react-dom"; | |
type DOMRectReadOnly = ResizeObserverEntry["contentRect"]; | |
const callbacks = new Map<Element, (_: DOMRectReadOnly) => void>(); | |
const ro = new ResizeObserver(entries => { | |
ReactDOM.unstable_batchedUpdates(() => { |
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"; | |
export function usePreviousValue<T>(value: T): T { | |
const refPrevious = React.useRef(value); | |
const refCurrent = React.useRef(value); | |
if (refPrevious.current !== refCurrent.current) { | |
refPrevious.current = refCurrent.current; | |
} |
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 asArray(target) { | |
if (!Immutable.List.isList(target)) { | |
throw new TypeError("target is not Immutable.List"); | |
} | |
return new Proxy(new Array(target.size), { | |
get(__, key, receiver) { | |
if (typeof key !== "symbol") { | |
const index = parseInt(key, 10); |
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"; | |
type RenderT<State> = ( | |
state: State, | |
update: <K extends keyof State>(key: K, value: State[K]) => void, | |
) => React.ReactNode; | |
interface Props<State> { | |
state: State; | |
render: RenderT<State>; |
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
<body onload=' | |
K = onkeydown = ({ keyCode: k }) => { | |
if (k > 36 && k < 41) { | |
ox = (k -= 38)==2?0:k; | |
oy = k==-1?0:k-1; | |
A = M[y][x]; | |
B = M[y + oy][x + ox] || "#"; | |
C = (Y=M[y + oy * 2]||[])[x + ox * 2]; | |
a = A == "+" ? "." : " "; |
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
var obj = { | |
_fooValue: 1, | |
_fooGetterShouldReturnThis: false, | |
get foo() { | |
var value = this._fooGetterShouldReturnThis ? this : this._fooValue; | |
this._fooGetterShouldReturnThis = false; | |
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
// Source #1: http://ideasintosoftware.com/typescript-advanced-tricks/ | |
// Source #2: https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-308052919 | |
type Diff<T extends string, U extends string> = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T]; | |
type Omit<T, K extends keyof T> = {[P in Diff<keyof T, K>]: T[P]}; | |
// Example: type TCleanedUser = Omit<IUser, 'privateField1' | 'privateField2'>; |
NewerOlder