Skip to content

Instantly share code, notes, and snippets.

@karlhorky
karlhorky / guests+api.ts
Last active February 23, 2024 11:34
Expo API Routes version of Express Naive Guest List API https://github.com/upleveled/express-guest-list-api-memory-data-store
// guests+api.ts
import { ExpoRequest, ExpoResponse } from 'expo-router/server';
import { guestList, Guest } from './index+api.ts';
export const guestList: Guest[] = [];
export function GET(request: ExpoRequest): ExpoResponse {
return ExpoResponse.json(guestList);
}
@karlhorky
karlhorky / Tailwindcssunreset.scss
Created February 14, 2024 01:19 — forked from swyxio/Tailwindcssunreset.scss
Tailwind CSS Un-Reset - un-reset Tailwind's Preflight CSS Reset so that autogenerated HTML looks consistent with the rest of your Tailwind site. - https://www.swyx.io/writing/tailwind-unreset
.unreset {
a {
@apply text-blue-700 underline;
}
p {
@apply my-4;
}
blockquote,
figure {
@karlhorky
karlhorky / auth-guard-components.tsx
Last active January 21, 2024 13:45
Guard components with auth permissions
// From the comment from @SukkaW here:
// https://github.com/vercel/next.js/pull/60616#issuecomment-1902608289
// Here is what I am doing currently, to authenticate and authorize
// RSC pages and components (like a button or a tooltip)
function GuardedComponent() {
const user = useUser();
// guard() will throw a `NoPermissionError` when the user doesn't have the permission
guard(user, permissionList);
@karlhorky
karlhorky / .eslintrc.cjs
Created November 3, 2023 09:14
Avoid await within arrays passed to Promise.all() https://twitter.com/alvarlagerlof/status/1720182566135779582
// https://twitter.com/karlhorky/status/1720368118193651903
/** @type {import('@typescript-eslint/utils').TSESLint.Linter.Config} */
const config = {
'no-restricted-syntax': [
'warn',
{
selector:
'CallExpression[callee .object.name=Promise][callee .property.name=all] > ArrayExpression > AwaitExpression',
message: 'Avoid await within array passed to Promise.all() to avoid waterfalls',
@karlhorky
karlhorky / set-methods.js
Created August 25, 2023 16:39
Set Methods demo
const hosts = new Set(["Wes", "Scott", "Snickers"]);
const team = new Set(["Wes", "Scott", "Kaitlin", "Ben"]);
const fans = new Set(["Paige", "Nick", 1]);
// Difference between two sets
console.log(team.difference(hosts)); // Set { 'Kaitlin', 'Ben' }
// Overlap between two sets
console.log(team.intersection(hosts)); // Set { 'Wes', 'Scott' }
const CH_BRACE_L = 0x7b as const;
const CH_BRACE_R = 0x7d as const;
const CH_SQUARE_L = 0x5b as const;
const CH_SQUARE_R = 0x5d as const;
const CH_QUOTE_D = 0x22 as const;
const CH_ESCAPE = 0x5c as const;
const CH_COMMA = 0x2c as const;
const CH_COLON = 0x3a as const;
const CH_DOT = 0x2e as const;
const CH_MINUS = 0x2d as const;
@karlhorky
karlhorky / R2_storage.ts
Created May 1, 2023 05:54 — forked from AndrewIngram/R2_storage.ts
Read/write from Cloudflare R2 in a Vercel edge function w/default
import { AwsClient } from "aws4fetch";
import { deflate } from "pako";
const R2_ACCOUNT_ID = "SOMETHING"
const R2_ACCESS_KEY_ID = "SOMETHING"
const R2_SECRET_ACCESS_KEY ="SOMETHING"
const R2_BUCKET = "SOMETHING"
const R2_URL = `https://${R2_BUCKET}.${R2_ACCOUNT_ID}.r2.cloudflarestorage.com`;
@karlhorky
karlhorky / alpine-linux-deploy.log
Created April 6, 2023 07:51
Alpine Linux deploy logs: corepack prepare pnpm@latest --activate
2023-04-03T07:53:27.8474256Z Requested labels: ubuntu-latest
2023-04-03T07:53:27.8474294Z Job defined at: upleveled/next-js-example-winter-2023-vienna-austria/.github/workflows/test-playwright-and-deploy-to-fly-io.yml@refs/heads/main
2023-04-03T07:53:27.8474316Z Waiting for a runner to pick up this job...
2023-04-03T07:53:28.1009892Z Job is waiting for a hosted runner to come online.
2023-04-03T07:53:30.6303409Z Job is about to start running on the hosted runner: GitHub Actions 2 (hosted)
2023-04-03T07:53:32.8886204Z Current runner version: '2.303.0'
2023-04-03T07:53:32.8913724Z ##[group]Operating System
2023-04-03T07:53:32.8914198Z Ubuntu
2023-04-03T07:53:32.8914499Z 22.04.2
2023-04-03T07:53:32.8914804Z LTS
@karlhorky
karlhorky / _app.js
Created November 3, 2022 14:34 — forked from claus/_app.js
Restore scroll position after navigating via browser back/forward buttons in Next.js
import useScrollRestoration from "utils/hooks/useScrollRestoration";
const App = ({ Component, pageProps, router }) => {
useScrollRestoration(router);
return <Component {...pageProps} />;
};
export default App;