Skip to content

Instantly share code, notes, and snippets.

@karlhorky
karlhorky / README.md
Created April 21, 2024 17:09 — forked from catalinmiron/README.md
Expo app.json Apple Privacy Manifest

About

The privacy details that you may need to add for Apple Privacy Manifest.

This config plugin it's already available from expo >=50.0.17 (Part of this PR by aleqsio)

Tip

Read more about Privacy Manifest File from Apple docs

@karlhorky
karlhorky / express-middleware-disable-gatsby-window-replacestate.ts
Created April 16, 2024 16:32
Express Middleware to Disable Gatsby's window.replaceState()
// Express middleware to disable Gatsby window.replaceState() to
// avoid changing new rewritten URLs back to original URLs
// https://github.com/gatsbyjs/gatsby/blob/c91ed287fd319a345c2f27877e20656826767e92/packages/gatsby/cache-dir/production-app.js#L159-L187
const appJsFilePath = existingGatsbyFiles.find((filePath) =>
/^\/app-[\da-f]+\.js$/.test(filePath),
)!;
const appJsContent = readFileSync(
join(websitePath, 'public', appJsFilePath),
'utf-8',
@karlhorky
karlhorky / Dockerfile
Created April 5, 2024 11:09 — forked from lithdew/Dockerfile
Dockerfile for deploying a Next.js standalone bundle on Fly.io with Bun.
# syntax = docker/dockerfile:1
# Adjust BUN_VERSION as desired
ARG BUN_VERSION=1.1.1
FROM oven/bun:${BUN_VERSION}-slim as base
LABEL fly_launch_runtime="Next.js"
# Next.js app lives here
WORKDIR /app
@karlhorky
karlhorky / guests+api.ts
Last active May 7, 2024 16:54
Expo API Routes version of Express Naïve 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;