Skip to content

Instantly share code, notes, and snippets.

View emeraldsanto's full-sized avatar

Yanick Bélanger emeraldsanto

View GitHub Profile
@emeraldsanto
emeraldsanto / use-reducer.tsx
Last active May 14, 2021 00:56
Small `useReducer` example
import { useReducer } from 'react';
/**
* There are much better ways to type this
* but this is not the focus of this gist.
*/
interface HTTPState<T> {
status: 'loading' | 'error' | 'success'
error?: string
data?: T
@emeraldsanto
emeraldsanto / segment-proxy-node.ts
Last active March 17, 2021 01:23
Segment proxy (Node)
import express from 'express';
import Segment from 'analytics-node';
const instance = new Segment('YOUR_WRITE_KEY');
const port = 3000;
const app = express();
// Enables JSON parsing middleware
app.use(express.json())
@emeraldsanto
emeraldsanto / segment-proxy-usage-react-native.ts
Last active March 17, 2021 01:22
Segment proxy usage (React Native)
import { instance } from './analytics';
// These events will be sent to your server instead of Segment's
instance.identify('some-user-id', { customProperty: 'custom value' });
instance.track('Custom Event', { userId: 'some-user-id' });
@emeraldsanto
emeraldsanto / segment-proxy-react-native.ts
Last active March 17, 2021 01:23
Segment proxy (React Native)
import Segment from "analytics-react-native";
export const instance = new Segment(
'YOUR_WRITE_KEY',
{
proxy: {
scheme: 'http',
host: 'localhost',
port: 3000,
path: '/analytics/segment'
@emeraldsanto
emeraldsanto / scaling-stylesheet.ts
Created February 24, 2021 16:34
A basic implementation of a scaling stylesheet measurements
import { Dimensions, StyleSheet } from "react-native";
const SCALABLE_PROPERTIES = [
"padding",
"paddingStart",
"paddingEnd",
"paddingTop",
"paddingBottom",
"paddingRight",
"paddingLeft",
@emeraldsanto
emeraldsanto / styles.xml
Created February 23, 2021 20:12
Jumio 3.8.0 styles
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowLightStatusBar">true</item>
<item name="android:statusBarColor">@color/status_bar_color</item>
<item name="android:spinnerItemStyle">@style/SpinnerItem</item>
<item name="android:spinnerDropDownItemStyle">@style/SpinnerDropDownItem</item>
<!-- Text Underline -->
<item name="android:editTextBackground">@android:color/transparent</item>
<!-- TextInput cursor -->
@emeraldsanto
emeraldsanto / PaginatedList.tsx
Created August 18, 2020 01:05
A wrapper over the base FlatList component with better pagination and automatic data-retrieval footers.
import { RefObject } from "react";
import { FlatList, FlatListProps } from "react-native";
import Success from "@assets/icons/success.svg";
import Warning from "@assets/icons/warning.svg";
import { ColorCode } from "@models/constants/ColorCode";
import { Row } from "@primitives/Flex/Row";
import { LocalizedText } from "@primitives/LocalizedText/LocalizedText";
import { useScrollToTop } from "@react-navigation/native";
import React, { FC, Fragment, useImperativeHandle, useRef, useState } from "react";
import { ActivityIndicator, FlatList, StyleSheet } from "react-native";
@emeraldsanto
emeraldsanto / withSuspense.tsx
Last active May 20, 2025 20:51
HOC to wrap a component in a `Suspense`, most likely a React Navigation screen. To be used with `React.lazy`.
/**
* Wraps the provide component in a `Suspense`, with the provided fallback.
* This should be used on components whose parent is not easy to control, such as
* React Navigation screens to be able to lazy load them using `React.lazy`.
* @param WrappedComponent The component to wrap.
* @param fallback The component to render while loading.
*
* @example
* const SomeScreen = withSuspense(React.lazy(() => import("path/to/some/screen")));
*/
@emeraldsanto
emeraldsanto / ErrorBoundary.tsx
Last active March 15, 2023 20:26
Custom error boundary with Firebase Crashlytics reporting and HOC
import React, { Component, ComponentType, ReactNode } from "react";
import crashlytics from "@react-native-firebase/crashlytics";
export interface ErrorBoundaryProps {
fallback: () => ReactNode;
}
/**
* Wraps the provided component in an ErrorBoundary, with the provided fallback.
* This should be used on components whose parent is not easy to control, such as
@emeraldsanto
emeraldsanto / set-environment.ts
Created August 4, 2020 02:07
Script to be run via NPM commands to generate the correct `env.json` file based on the provided environment name and the existing environment files
#!/bin/node
/**
* This scripts will create a `env.json` file at the root of the project
* with the content matching that of the desired environment file, as defined in `/src/env/`
*
* @example
* npx ts-node src/scripts/set-environment.ts production
*/