Skip to content

Instantly share code, notes, and snippets.

View juanchoperezj's full-sized avatar
🇻🇪

Juan Simón juanchoperezj

🇻🇪
View GitHub Profile
@juanchoperezj
juanchoperezj / actions.js
Created January 7, 2018 20:12 — forked from jtibbertsma/actions.js
react-native-navigation redux middleware example
import { createAction } from 'redux-actions';
import {
NAVIGATION_PUSH,
NAVIGATION_POP,
NAVIGATION_RESET_TO,
NAVIGATION_POP_TO_ROOT
} from './actions';
export const push = createAction(NAVIGATION_PUSH);
export const pop = createAction(NAVIGATION_POP);
{
"message":{
"token":"eparYXI6eFA:APA91bGLPUJAfemkAIvm3xD6Y9Y02F3MFXg3MuZLH78b50gQJOvm75bHEYb_qVMlvuBKrYxQ5-wZB7qmNnuYScJcpdMbc5ZurM7AUUN_MTpReDCxxjgTn_2cVBc2PNiSSf3EiKL7bYfVvY4MwGSwnGBoSOYB-vi9QA",
"notification":{
"title":"Match update",
"body":"Arsenal goal in added time, score is now 3-0"
},
"android":{
"ttl":"86400s",
"notification":{
import { AsyncStorage, Alert, Platform } from 'react-native';
import firebase from 'react-native-firebase';
const displayNotificationFromCustomData = message => {
if (message.data && message.data.title) {
let notification = new firebase.notifications.Notification();
notification = notification
.setTitle(message.data.title)
.setBody(message.data.body)
.setData(message.data);
@juanchoperezj
juanchoperezj / Postgres Notify Firebase
Created October 3, 2018 12:53
Trigger that notifies the javascript thread of a change occurred and sends push notifications using postgres and firebase
const admin = require('firebase-admin')
const request = require('request')
const config = require('../config')
const {JWT} = require('google-auth-library')
const dbConfig = config.database
const pg = require('pg')
/**
* @type {string}
@juanchoperezj
juanchoperezj / install_dependencies.sh
Last active August 10, 2023 16:58
Dependencies needed to validate environment variables
yarn add react-native-config zod
npm i react-native-config zod
@juanchoperezj
juanchoperezj / ts_node.sh
Last active August 10, 2023 16:58
ts-node dev dependency
yarn add -D ts-node
npm install ts-node --save-dev
@juanchoperezj
juanchoperezj / react_native_config.d.ts
Last active August 10, 2023 16:58
React Native Config Interface Example
import { NativeConfigType } from './env';
declare module 'react-native-config' {
export interface NativeConfig extends NativeConfigType {}
export const Config: NativeConfig;
export default Config;
}
@juanchoperezj
juanchoperezj / env.ts
Created August 8, 2023 22:01
ENV zod object
import z from 'zod';
const NativeConfig = z.object({
API_URL: z.string(),
BASE_URL: z.string(),
});
export type NativeConfigType = z.infer<typeof NativeConfig>;
export default NativeConfig;
@juanchoperezj
juanchoperezj / package.json
Created August 8, 2023 22:02
Package.json scripts example
"scripts": {
"ios:staging": "APP_ENV=staging ts-node scripts/validate-env.ts && react-native run-ios --scheme MyReactNativeApp-Staging",
"ios:prod": "APP_ENV=prod ts-node scripts/validate-env.ts && react-native run-ios --scheme MyReactNativeApp",
"android:dev": "APP_ENV=dev ts-node scripts/validate-env.ts && react-native run-android --variant=devDebug --appIdSuffix=dev",
"android:qa": "APP_ENV=qa ts-node scripts/validate-env.ts && react-native run-android --variant=qaDebug --appIdSuffix=qa",
// ... other scripts
}
@juanchoperezj
juanchoperezj / validate_env.ts
Created August 10, 2023 17:02
Validate env complete implementation reading the env file variables a compare them against the zod object
import fs from 'fs';
import path from 'path';
import Environment from '../src/@types/env';
const APP_ENV = process.env.APP_ENV ?? 'dev';
const isDev = APP_ENV === 'dev';
const envFile = path.join(__dirname, isDev ? '../.env' : `../.env.${APP_ENV}`);
(() => {