Skip to content

Instantly share code, notes, and snippets.

View MarceloPrado's full-sized avatar

Marcelo Terreiro Prado MarceloPrado

View GitHub Profile
@MarceloPrado
MarceloPrado / Dockerfile
Created August 1, 2023 10:12
Railway dockerfile
# ------------------------------
# First stage: build the app
# ------------------------------
FROM node:16.19-alpine as builder
ARG DATABASE_URL
ARG DATADOG_API_KEY
ARG PORT
ARG SENTRY_DSN
@MarceloPrado
MarceloPrado / Dockerfile
Created August 1, 2023 10:16
Fly.io Dockerfile
# ------------------------------
# First stage: build the app
# This includes all dependencies.
# ------------------------------
FROM node:16.19-alpine as builder
ARG PORT
WORKDIR /app
@MarceloPrado
MarceloPrado / ReactNativeGlobalAlert.tsx
Created August 8, 2023 11:05
This gist describes how to build a global alert system that follows a similar API as RN's Alert.alert(). It can be cleaned up and improved, especially in the GlobalAlertManager side, but it's a good starting point.
import { BottomSheetModalProvider } from "@gorhom/bottom-sheet";
/**
* This gist describes how to build a global alert system that follows a similar
* API as RN's Alert.alert().
*
* This can be cleaned up and improved, especially in the GlobalAlertManager
* side, but it's a good starting point.
*/
@MarceloPrado
MarceloPrado / useToggleStorybook.ts
Created October 18, 2023 12:32
Dynamically toggle between storybook and app
import { config } from "@/app/config";
import { createLogger } from "@/app/observability";
import { useEffect } from "react";
const { appEnv } = config;
const logger = createLogger("developer/storybook");
export const useToggleStorybook = () => {
const [isStorybookEnabled, setIsStorybookEnabled] = useState(false)
@MarceloPrado
MarceloPrado / atomWithMmkvStorage.ts
Last active March 20, 2025 08:41
A simple Jotai atom with storage using react-native-mmkv backend
// `storage` is just a MMKV instance from `react-native-mmkv`
import { storage } from "@/app/storage";
import { atomWithStorage } from "jotai/utils";
const defaultOpts = { getOnInit: true };
export const atomWithMmkvBooleanStorage = (
key: string,
initialValue: boolean
) =>
@MarceloPrado
MarceloPrado / DestructiveActionGuard.tsx
Last active April 22, 2024 17:35
An easy way of seeking user confirmation before proceeding with a destructive action. Demo: https://twitter.com/marceloterreiro/status/1779657639745798411
import type { ReactElement } from "react";
import { cloneElement, memo, useCallback } from "react";
import { AlertV2 } from "@/components/AlertV2/alertV2Helpers";
export interface DestructiveActionGuardProps {
children: ReactElement<{ onPress: () => void }>;
confirmationTitle?: string;
confirmationDescription?: string;
}