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
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
app = "my-app"
primary_region = "cdg"
kill_signal = "SIGINT"
kill_timeout = "5s"
swap_size_mb = 256
@rphlmr
rphlmr / helpers.ts
Last active May 3, 2024 22:28
Drizzle ORM, deep sub queries
/* -------------------------------------------------------------------------- */
/* More here; */
/* -------------------------------------------------------------------------- */
//gist.github.com/rphlmr/0d1722a794ed5a16da0fdf6652902b15
https: export function distinctOn<Column extends AnyColumn>(column: Column) {
return sql<Column["_"]["data"]>`distinct on (${column}) ${column}`;
}
export function jsonBuildObject<T extends SelectedFields>(shape: T) {
@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
@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 / protect-routes.ts
Last active March 22, 2024 20:45
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 {