Skip to content

Instantly share code, notes, and snippets.

View rphlmr's full-sized avatar
Making things with Remix Run

Raphaël Moreau rphlmr

Making things with Remix Run
View GitHub Profile
@rphlmr
rphlmr / protect-routes.ts
Last active November 26, 2024 00:24
Protected routes middleware with HonoJS with Remix-Hono
import { getSession, session } from "remix-hono/session";
import { pathToRegexp } from "path-to-regexp";
/**
* Add protected routes middleware
*
*/
app.use(
protect({
@rphlmr
rphlmr / typecheck.sh
Created August 30, 2023 20:56
Keep skipLibCheck to false and still typecheck your project's .d.ts files
#!/bin/bash
RED="\e[31m"
ENDCOLOR="\e[0m"
echo "⏳ Checking for type errors..."
# Run tsc and capture the output
TYPE_ERRORS=$(tsc --project ./tsconfig.json 2>&1)
import { createId } from "@paralleldrive/cuid2";
/**
* @param message The message intended for the user.
*
* Other params are for logging purposes and help us debug.
* @param cause The error that caused the rejection.
* @param context Additional data to help us debug.
* @param name A name to help us debug and filter logs.
*
@rphlmr
rphlmr / page.tsx
Created August 21, 2023 08:19
Next13 paginate stream
import { faker } from "@faker-js/faker";
import { Suspense, cache } from "react";
import Link from "next/link";
export const dynamic = "force-dynamic";
export const revalidate = 0;
const salesFromDB = Array.from(
{ length: 21 },
() =>
@rphlmr
rphlmr / entry.server.tsx
Last active August 15, 2023 22:31
How I have implemented CSP nonce, based on https://github.com/remix-run/remix/issues/5162
/**
* 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 crypto from "node:crypto";
import { PassThrough } from "node:stream";
import type { EntryContext } from "@remix-run/node";
// Remember to install mini-svg-data-uri
// Follow me on twitter for memes @jordienr
import { type Config } from "tailwindcss";
const {
default: flattenColorPalette,
} = require("tailwindcss/lib/util/flattenColorPalette");
const svgToDataUri = require("mini-svg-data-uri");
export default {
@rphlmr
rphlmr / style.css
Created July 18, 2023 16:56 — forked from Demandrel/style.css
Style.css for driver.js
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
html {
font-family: 'Rubik', system-ui, sans-serif;
}
}
@rphlmr
rphlmr / clear-db.ts
Last active January 21, 2026 12:24
Drizzle snippets
// Credits to Louistiti from Drizzle Discord: https://discord.com/channels/1043890932593987624/1130802621750448160/1143083373535973406
import { sql } from "drizzle-orm";
const clearDb = async (): Promise<void> => {
const query = sql<string>`SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
AND table_type = 'BASE TABLE';
`;
@rphlmr
rphlmr / route.tsx
Last active July 24, 2024 13:02
Remix Supabase Upload
// if you don't plan to upload only images :
/*
async function convertToFile(data: AsyncIterable<Uint8Array>) {
const chunks = [];
for await (const chunk of data) {
chunks.push(chunk);
}
return chunks;
}
@rphlmr
rphlmr / zod-helper.ts
Created October 16, 2022 20:38
Zod implements a TypeScript model
// Thanks https://github.com/colinhacks/zod/issues/372#issuecomment-830094773
type Implements<Model> = {
[key in keyof Model]-?: undefined extends Model[key]
? null extends Model[key]
? z.ZodNullableType<z.ZodOptionalType<z.ZodType<Model[key]>>>
: z.ZodOptionalType<z.ZodType<Model[key]>>
: null extends Model[key]
? z.ZodNullableType<z.ZodType<Model[key]>>
: z.ZodType<Model[key]>;