Skip to content

Instantly share code, notes, and snippets.

@ngbrown
ngbrown / Remix.xml
Last active April 9, 2024 20:50
WebStorm Live Template for Remix
<templateSet group="Remix">
<template name="useFetcher" value="const $fetcher$ = useFetcher();" description="const fetcher = useFetcher()" toReformat="true" toShortenFQNames="true" useStaticImport="true">
<variable name="fetcher" expression="" defaultValue="&quot;fetcher&quot;" alwaysStopAt="true" />
<context>
<option name="JS_CLASS_MEMBER_STATEMENT" value="false" />
<option name="JS_STATEMENT" value="true" />
<option name="TS_CLASS_MEMBER_STATEMENT" value="false" />
<option name="TS_STATEMENT" value="true" />
</context>
</template>
@ngbrown
ngbrown / SemaphoreSlimExtensions.cs
Created May 21, 2024 15:48
SemaphoreSlimExtensions
public static class SemaphoreSlimExtensions
{
/// <summary>
/// Blocks the current thread until it can enter the <see cref="SemaphoreSlim"/>. Returns an <see cref="IDisposable"/> to be used in <c>using</c>.
/// </summary>
/// <param name="semaphore">A <see cref="SemaphoreSlim"/> to lock.</param>
/// <returns>An <see cref="IDisposable"/> that will release the <see cref="SemaphoreSlim"/> when disposed.</returns>
public static IDisposable Lock(this SemaphoreSlim semaphore)
{
semaphore.Wait();
@ngbrown
ngbrown / nav.tsx
Last active August 6, 2024 07:09
Nav for Remix (and React Router) - Use to drive which component has the active link in a menu
import React from "react";
import type { LinkProps } from "@remix-run/react";
import { stripBasename } from "@remix-run/router";
import {
UNSAFE_DataRouterStateContext as DataRouterStateContext,
UNSAFE_NavigationContext as NavigationContext,
useLocation,
useResolvedPath,
@ngbrown
ngbrown / entry.server.tsx
Last active August 30, 2024 07:25
Populate Links in Remix for Cloudflare 103 hints
/**
* By default, Remix will handle generating the HTTP Response for you.
* You are free to delete this file if you'd like to, but if you ever want it revealed again, you can run `npx remix reveal` ✨
* For more information, see https://remix.run/file-conventions/entry.server
*/
import type { AppLoadContext, EntryContext } from "@remix-run/cloudflare";
import { RemixServer } from "@remix-run/react";
import { isbot } from "isbot";
import { renderToReadableStream } from "react-dom/server";
@ngbrown
ngbrown / Count-Lines.ps1
Created October 10, 2025 16:11
Counts the lines of code in the specified directory using cloc. Uses PowerShell and Docker.
<#
.SYNOPSIS
Counts the lines of code in the specified directory using cloc.
.DESCRIPTION
This script utilizes the cloc (Count Lines of Code) tool to analyze and count the lines of code in a given directory. It requires Docker Desktop to be running, as cloc is executed within a Docker container.
To improve performance, the script first compresses the files into a zip archive. This allows the Docker container to analyze the code quickly, avoiding the slow performance that would result from mounting all files as a volume.