Skip to content

Instantly share code, notes, and snippets.

@reyronald
reyronald / startDurationMeasurement.ts
Last active December 4, 2023 13:47
Measures timing using the NodeJS performance API "perf_hooks"
import { PerformanceObserver, performance } from "node:perf_hooks";
import type { PerformanceEntry } from "node:perf_hooks";
export function startDurationMeasurement(name: string) {
const id = crypto.randomUUID();
const measurementName = `${name}-measurementName-${id}`;
const startMark = `${name}-startMark-${id}`;
const endMark = `${name}-endMark-${id}`;
class FindAndPopCollection<T> {
private _array: T[];
constructor(_array: T[]) {
this._array = _array.slice();
}
findAndRemove(predicate: (value: T) => boolean) {
const index = this._array.findIndex(predicate);
if (index !== -1) {
import { convertLongMonthDayToShort } from "server/domain/client/convertLongMonthDayToShort";
describe("convertLongMonthDayToShort", () => {
it.each([
[undefined, undefined],
[null, null],
["1/1", "1/1"],
["8/31", "8/31"],
["3/31", "3/31"],
["4/30", "4/30"],
@reyronald
reyronald / 1 toBeAriaDisabled.ts
Last active September 7, 2023 14:07
toBeAriaDisabled
import type { MatcherFunction } from "expect";
function assertIsElement(el: unknown): asserts el is HTMLElement {
const isElement = el instanceof HTMLElement;
if (!isElement) {
throw new TypeError("Not an HTMLElement");
}
}
export const toBeAriaDisabled: MatcherFunction<[element: unknown]> = function (element) {
@reyronald
reyronald / getNockPayloadCapturer.sample.ts
Last active August 24, 2023 19:53
getNockPayloadCapturer.ts
const mockServer = nock("http://localhost", { allowUnmocked: false });
mockServer.put(`/api/clients/${client.id}/bills/bulk`).reply(200, bills);
const getCapturedPayload = getNockPayloadCapturer(mockServer);
await userEvent.click(screen.getByRole("button", { name: "Save" }));
const capturedPayload = await waitFor(getCapturedPayload);
// https://twitter.com/GabrielVergnaud/status/1622899119856525313
type Prettify<T> = {
[K in keyof T]: T[K]
} & {}
<?php
/**
* CiscoSSH.php
*
* Designed to execute commands over SSH in
* Cisco devices (switches, routers, etc.).
* Only tested with Cisco (hence the name),
* but could also work with other brands or NEs.
*
type ValidateShape<T, Shape> =
T extends Shape ?
Exclude<keyof T, keyof Shape> extends never ?
T : never : never;
type Exact<A, B> =
A extends B ?
B extends A ? A
: never
: never;
git commit --amend

git commit --fixup head~0
git rebase -i head~2
git rebase -i --root

git reflog

git reset
import React from "react";
import { BrowserRouter, Redirect } from "react-router-dom";
import { CompatRouter, Routes, Route } from "react-router-dom-v5-compat";
import { Internal1 } from "./Internal1";
import { Loadable } from "./Loadable";
const Loading = () => (
<div style={{ width: "100%", height: "100vh", background: "red" }}>Loading</div>
);