Skip to content

Instantly share code, notes, and snippets.

View MarceloPrado's full-sized avatar

Marcelo Terreiro Prado MarceloPrado

View GitHub Profile
@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;
}
@MarceloPrado
MarceloPrado / atomWithMmkvStorage.ts
Last active April 15, 2024 13:04
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 / 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 / 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 / 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 / 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
name: Deploy
on:
push:
branches:
- master
jobs:
test:
name: Tests
runs-on: ubuntu-latest
{
"idExterno": "fSkHv28beT26PktAL",
"ambienteEmissao": "Homologacao",
"enviarPorEmail": false,
"servico": {
"descricao": "17 - CONTORNO TOTAL - R$ 47.00 \nSALAO-PARCEIRO: 41.529.660/0001-41 - COTA PARTE: R$ 28.20 \nPROFISSIONAL-PARCEIRO: 21.465.006/0001-04 - COTA-PARTE R$ 18.80 \n\n",
"codigoInternoServicoMunicipal": 25010,
"issRetidoFonte": false
},
"valorTotal": 47,
Error at PagarMe request { Error: failed [500] {"errors":[{"type":"action_forbidden","parameter_name":null,"message":"Um erro interno aconteceu."}],"url":"/transactions/98301253/refund","method":"post"}
at Object.exports.makeErrorByStatus (packages/http.js:176:10)
at Request._callback (packages/http.js:140:24)
at Request.self.callback (/var/app/current/programs/server/npm/node_modules/meteor/http/node_modules/request/request.js:185:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request.<anonymous> (/var/app/current/programs/server/npm/node_modules/meteor/http/node_modules/request/request.js:1161:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at IncomingMessage.<anonymous> (/var/app/current/programs/server/npm/node_modules/meteor/http/node_modules/request/request.js:1083:12)
@MarceloPrado
MarceloPrado / rota-boleto.js
Last active January 15, 2019 13:56
postback test
const boletoTransactionSchema = {
body: Joi.object()
.keys({
model: Joi.string().valid('transaction'),
model_id: Joi.string().required(),
payload: Joi.string().required()
})
.unknown(true) // permite outros campos além dos definidos acima
}