Skip to content

Instantly share code, notes, and snippets.

View crrmacarse's full-sized avatar
✍️
@ bitbucket

Macarse, Christian Ryan R. crrmacarse

✍️
@ bitbucket
View GitHub Profile
import nodemailer from 'nodemailer'
import Env from '@ioc:Adonis/Core/Env'
export const emailConfig = {
rootUrl: Env.getOrFail('PUBLIC_URL') as string,
service: Env.getOrFail('SMPT_SERVICE') as string,
user: Env.getOrFail('SMPT_USER') as string,
pass: Env.getOrFail('SMPT_PASSWORD') as string,
}
import * as AWS from 'aws-sdk'
import Env from '@ioc:Adonis/Core/Env'
import { v4 as uuid } from 'uuid'
import { ManagedUpload } from 'aws-sdk/clients/s3'
const AWS_BUCKET_NAME = Env.getOrFail('AWS_BUCKET_NAME') as string
const AWS_REGION = Env.getOrFail('AWS_REGION') as string
const AWS_SECRET_ACCESS_KEY = Env.getOrFail('AWS_SECRET_ACCESS_KEY') as string
const AWS_ACCESS_KEY_ID = Env.getOrFail('AWS_ACCESS_KEY_ID') as string
@crrmacarse
crrmacarse / ck-editor-react.tsx
Last active October 16, 2020 02:44
How add ts-ignore in jsx
<FormControl
{...otherProps}
variant="outlined"
fullWidth
>
<Field name={name}>
{({ input, meta: { touched, error, submitError } }) => (
<Fragment>
<FormLabel>{label}</FormLabel>
{/*
@crrmacarse
crrmacarse / useEffect.ts
Last active May 19, 2020 15:31
Limit trigger of useEffect ala componentDidUpdate behaviour
const isInitialMount = useRef(true);
const [search, setSearch] = useState<string>();
// https://stackoverflow.com/questions/55075604/react-hooks-useeffect-only-on-update
useEffect(() => {
let debounceFunc: NodeJS.Timeout;
if (isInitialMount.current) {
isInitialMount.current = false;
} else {
import React, { useState, useEffect } from 'react';
import { Backdrop, CircularProgress, Typography, Box } from '@material-ui/core';
import { makeStyles, createStyles, Theme } from '@material-ui/core/styles';
const useStyles = makeStyles((theme: Theme) => createStyles({
backdrop: {
zIndex: theme.zIndex.drawer + 1,
background: '#0000001f',
},
title: {
@crrmacarse
crrmacarse / index.tsx
Created May 15, 2020 02:25
Preloading
import 'providers/message';
import 'core-js/stable';
import 'regenerator-runtime/runtime';
import 'raf/polyfill';
import 'scss/index.scss';
import 'providers/sentry';
import React from 'react';
import { hydrate } from 'react-dom';
import { Provider as ReduxProvider } from 'react-redux';
import Providers from 'providers';
$font-system: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
$font-family: "Poppins", $font-system;
@crrmacarse
crrmacarse / session.ts
Created May 1, 2020 03:58
Session handling with SPA
/* eslint-disable no-empty, no-param-reassign */
import api from 'utils/api';
const LS_SESSION = 'hasSession';
export const startSession = () => window.localStorage.setItem(LS_SESSION, 'true');
export const resetSession = () => window.localStorage.removeItem(LS_SESSION);
export const hasSession = (): boolean => {
const val = Boolean(window.localStorage.getItem(LS_SESSION));
@crrmacarse
crrmacarse / api.ts
Last active May 2, 2020 04:30
Axios config + CSRF Token
/** Retrieve token cookie generated by backend */
const [cookieCsrfToken] = document.cookie.split('; ').filter((v) => /^xsrf-token=/.test(v));
const csrfToken = cookieCsrfToken.replace('xsrf-token=', '');
const DEFAULT_API_BASE_URL = `${process.env.API_BASE_URL}/api`;
const API_BASE_URL = process.env.NODE_ENV === 'development' && process.env.API_BASE_URL
? DEFAULT_API_BASE_URL
: '/api';
/**
@crrmacarse
crrmacarse / ga.ts
Last active May 13, 2020 03:23
Google Analytics Config
import ReactGA, { EventArgs, TimingArgs } from 'react-ga';
const GA_CODE = process.env.GA_TRACKING_CODE;
/** returns an initialized ReactGA instance */
const initGA = () => ReactGA.initialize(GA_CODE);
/**
* Send page view
* @param page optional. Defaults to current browser URL