Skip to content

Instantly share code, notes, and snippets.

Boost Prompt

A prompt to boost your lazy "do this" prompts. Install with one of the buttons below.

Install in VS Code Install in VS Code Insiders

Use

@t3dotgg
t3dotgg / try-catch.ts
Last active November 7, 2025 22:15
Theo's preferred way of handling try/catch in TypeScript
// Types for the result object with discriminated union
type Success<T> = {
data: T;
error: null;
};
type Failure<E> = {
data: null;
error: E;
};
@theprashant-one
theprashant-one / withDisableBundleCompression.js
Last active March 22, 2025 03:39
A Config Plugin for Expo that disables bundle compression in build.gradle by ensuring "bundle" is included in noCompress. Reference (https://x.com/margelo_io/status/1890789725872525381?t=sZABYYbVSb4Re3A8aww7Ew&s=19)
const { withAppBuildGradle } = require("@expo/config-plugins")
/**
* A Config Plugin to disable bundle compression in Android build.gradle.
* @param {import('@expo/config-plugins').ConfigPlugin} config
* @returns {import('@expo/config-plugins').ConfigPlugin}
*/
const withDisableBundleCompression = (config) => {
return withAppBuildGradle(config, (config) => {
let buildGradle = config.modResults.contents
import { ServerResponse, type IncomingMessage } from "node:http";
import { Http2ServerRequest, Http2ServerResponse } from "node:http2";
import { isArrayBufferView } from "node:util/types";
const INTERNAL_BODY = Symbol("internal_body");
const GlobalResponse = Response;
globalThis.Response = class Response extends GlobalResponse {
[INTERNAL_BODY]: BodyInit | null | undefined = null;
@wbern
wbern / bump-caniuse-lite.js
Last active May 12, 2022 20:27
Update caniuse-lite i pnpm-lock.yaml (mostly for Rush users) - PUT INSIDE `scripts/` IN THE REPO ROOT FOR PATHS TO WORK
#!/bin/node
// Script bumps caniuse-lite in common/config/rush/pnpm-lock.yaml
const path = require("path");
const fs = require("fs");
const { execSync } = require("child_process");
async function main() {
const repoRoot = path.join(__dirname, "../");
@slikts
slikts / advanced-memo.md
Last active February 25, 2025 15:19
Advanced memoization and effects in React

nelabs.dev

Advanced memoization and effects in React

Memoization is a somewhat fraught topic in the React world, meaning that it's easy to go wrong with it, for example, by [making memo() do nothing][memo-pitfall] by passing in children to a component. The general advice is to avoid memoization until the profiler tells you to optimize, but not all use cases are general, and even in the general use case you can find tricky nuances.

Discussing this topic requires some groundwork about the technical terms, and I'm placing these in once place so that it's easy to skim and skip over:

  • Memoization means caching the output based on the input; in the case of functions, it means caching the return value based on the arguments.
  • Values and references are unfortunately overloaded terms that can refer to the low-level implementation details of assignments in a language like C++, for example, or to memory
@franky47
franky47 / use100vh.js
Created January 11, 2020 07:44
React hook to fix the 100vh issue on mobile Chrome and Safari
import React from 'react';
import { useWindowSize } from 'react-use';
// 100vh is broken on mobile (Chrome, Safari):
// https://chanind.github.io/javascript/2019/09/28/avoid-100vh-on-mobile-web.html
export default function use100vh() {
const ref = React.useRef();
const { height } = useWindowSize();
@steveruizok
steveruizok / App.tsx
Created August 18, 2019 19:56
Radial drag constraints in Framer X / Framer Motion.
import { Override, motionValue, useAnimation } from 'framer'
const x = motionValue(0)
const y = motionValue(0)
export function Knob(): Override {
const maxRadius = 32
const overDrag = 0.25
const animation = useAnimation()
@DavidKuennen
DavidKuennen / minimal-analytics-snippet.js
Last active August 28, 2025 15:49
Minimal Analytics Snippet
(function (context, trackingId, options) {
const history = context.history;
const doc = document;
const nav = navigator || {};
const storage = localStorage;
const encode = encodeURIComponent;
const pushState = history.pushState;
const typeException = 'exception';
const generateId = () => Math.random().toString(36);
const getId = () => {
@matthargett
matthargett / ts-vs-flow.md
Created November 19, 2018 21:00
TypeScript versus flowtype

First, let's note the difference in philosophy: TypeScript aims for fast analysis because you can to compile it down to JS before you can run/test it. flowtype is meant to be an async analysis that can run continuously with changes since the last analysis, or in parallel with your eslint and bundler rules. As such, flowtype's type system and analysis is not quite as concerned with speed or memory usage in service of potentially finding more bugs.

On two occasions I have tried to roll out flow in React Native applications, and on those two occasions we ended up backing out after a few weeks. Some detail: flow doesn't have a public roadmap, and what version you use is dictated by the react/react-native dependency and the annotations in react-native itself. flowtype also has some hard-coded aspects to help the analysis for React, so major updates to React itself sometimes also require updating flowtype to match. React Native upgrades then get gated based on your dependent libraries (or flow-typed) being updated