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 / readme.md
Created July 24, 2024 16:46
Test .dockerignore
@rphlmr
rphlmr / index.ts
Last active July 30, 2024 03:11
Link XState and Remix fetcher
import type { ActionFunctionArgs, LoaderFunctionArgs } from '@remix-run/node';
import {
ClientActionFunctionArgs,
ClientLoaderFunctionArgs,
useFetcher,
useLoaderData,
} from '@remix-run/react';
import { enqueueActions, fromPromise, setup } from 'xstate';
import { useActor } from '@xstate/react';
import { useEffect, useRef } from 'react';
#
# 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 September 19, 2024 13:48
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 August 31, 2024 22:06
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 },
() =>