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 / clear-db.ts
Last active August 24, 2025 11:07
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 / 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;
}
}
// 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 / 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";
@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 },
() =>
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 / 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)
@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 / app-install-manager.tsx
Created October 21, 2023 16:13
PWA App install button handling native prompt or a fallback.
/**
* App Install Manager
*
* Author: @rphlmr
*/
/**
* You will be surprised by the code below.
*
* `beforeinstallprompt` is an event really hard to work with 😵‍💫
@rphlmr
rphlmr / readme.md
Last active December 31, 2023 17:12
Use Supabase RLS with Drizzle

Supabase RLS Policy functions and Postgres transaction configuration association

source

Supabase's RLS Policy functions PgTransaction config to set Description
auth.uid() set_config('request.jwt.claim.sub', <current_user_uid>, true) <current_user_uid> comes from your own way to get the current user uid
auth.email() set_config('request.jwt.claim.email', <current_user_email>, true) <current_user_email> The current user email
auth.role() set_config('request.jwt.claim.role', <current_user_role>, true) <current_user_role> The current user role
auth.jwt() set_config('request.jwt.claim', <current_user_jwt>, true) <current_user_jwt> The current user jwt token. 🚨 I'm note sure about the config name, found nothing in Supabase repo