Skip to content

Instantly share code, notes, and snippets.

@jasonsnell
jasonsnell / countdupes.py
Last active February 8, 2025 22:02
Count Duplicates in List
import subprocess
import re
import sys
from Levenshtein import ratio
from collections import defaultdict, Counter
# Configuration: Adjust as needed
INCLUDE_PARENTHESES = False # Set to True to include parentheticals, False to exclude them
OUTPUT_TO_CLIPBOARD = True # Set to True to copy output to clipboard, False to print to console
@chaance
chaance / root.tsx
Created March 11, 2023 00:32
Remove trailing slashes to URL via redirect in Remix
import { redirect, type LoaderArgs } from "@remix-run/node";
export async function removeTrailingSlashes(request: Request) {
let url = new URL(request.url);
if (url.pathname.endsWith("/") && url.pathname !== "/") {
throw redirect(url.pathname.slice(0, -1) + url.search);
}
}
export async function loader({ request }: LoaderArgs) {
@searls
searls / rails_bisect_step
Created February 1, 2023 20:34
Used in conjunction with [this script](https://gist.github.com/searls/5c6b77213dbc7202ca39f4e70d975eee) to make it easier to git bisect rails apps whose database changes during the affected sha range
#!/usr/bin/env bash
# Usage:
#
# First, be sure you're running `git bisect start --no-checkout`, so you can
# checkout the bisect head yourself and do some pre-flight stuff like rewind
# migrations
#
# $ git bisect good
# Bisecting: 22 revisions left to test after this (roughly 5 steps)
@kiliman
kiliman / env.server.ts
Last active March 10, 2023 19:34
Use zod to parse/validate environment variables
import { z } from 'zod';
import { getParams } from './params';
const envSchema = z.object({
NODE_ENV: z.string(),
DATABASE_URL: z.string().url(),
SESSION_SECRET: z.string(),
AUTH_SECRET: z.string(),
ENABLE_REGISTRATION: z.boolean().default(false),
SMTP_HOST: z.string(),
@jacob-ebey
jacob-ebey / client-navigation.js
Created January 11, 2023 00:53
Navigation and View Transition API example
import { html } from "html-tagged";
export default function ClientNavigation() {
return html`
<script type="module">
if (typeof navigation !== "undefined") {
let lastAbortController;
navigation.addEventListener("navigate", (event) => {
if (!event.canIntercept) return;
@samselikoff
samselikoff / range.code-snippets
Last active July 30, 2024 01:37
VSCode snippet for creating a loop of n numbers in JSX! https://twitter.com/samselikoff/status/1611406980639244301
{
"Range of numbers": {
"scope": "javascriptreact,typescriptreact",
"prefix": "range",
"body": [
"{[...Array($1).keys()].map((i) => (",
" <$2 key={i}>",
" $3",
" </$2>",
"))}",
// TODO: make `pages` optional and measure the div when unspecified, this will
// allow more normal document flow and make it easier to do both mobile and
// desktop.
import {
createContext,
useCallback,
useContext,
useEffect,
useMemo,
useRef,
@knowler
knowler / fontsource-with-remix.md
Last active February 21, 2024 17:03
Fontsource with Remix (pre-1.7.3)

Fontsource with Remix

Fontsource is designed to work with projects that bundle their CSS. You import their stylesheet and the bundler will place the fonts in your build directory and the CSS file will have the correct URL for the @font-face src.

Remix doesn’t bundle CSS and so while you can import their CSS file and add it to your links, the URL to font will be incorrect. It is still possible to use Fontsource with Remix. We just need to create our own @font-face declaration with the correct URL to the font (ideally, one that benefits from Remix’s asset fingerprinting). There’s a bit of manual set up, but once that’s done, you can serve the font on your site and benefit from updates for the font.

  1. Install your font:
    npm install --save @fontsource/montserrat
@jacob-ebey
jacob-ebey / api.chat.ts
Created May 8, 2022 22:20
Simple Remix SSE Chat Application on new fetch polyfill
import type { LoaderFunction } from "@remix-run/node";
import type { ChatMessageEvent } from "~/events.server";
import { chatEvents } from "~/events.server";
export let loader: LoaderFunction = ({ request }) => {
if (!request.signal) {
throw new Error("No request signal provided by the platform");
}
@denisgolius
denisgolius / generate-ssh-key.sh
Created October 4, 2018 06:55 — forked from grenade/01-generate-ed25519-ssh-key.sh
Correct file permissions for ssh keys and config.
ssh-keygen -t rsa -b 4096 -N '' -C "[email protected]" -f ~/.ssh/id_rsa
ssh-keygen -t rsa -b 4096 -N '' -C "[email protected]" -f ~/.ssh/github_rsa
ssh-keygen -t rsa -b 4096 -N '' -C "[email protected]" -f ~/.ssh/mozilla_rsa