Skip to content

Instantly share code, notes, and snippets.

View jgcmarins's full-sized avatar

João Marins jgcmarins

View GitHub Profile
@jgcmarins
jgcmarins / MyPrivatePage.ts
Created July 11, 2022 22:37
Next.js SSR authentication and routing between public and private pages with getServerSideProps and cookies
import type { NextPage } from 'next';
import { getServerSidePropsPrivate } from '../../../middlewares/getServerSidePropsPrivate';
const MyPrivatePage: NextPage = ({ me }) => {
// use me data
/* code goes here */
};
export const getServerSideProps = getServerSidePropsPrivate;
@jgcmarins
jgcmarins / MEMOIZE.md
Created March 26, 2021 13:57 — forked from mrousavy/MEMOIZE.md
Memoize!!! 💾 - a react (native) performance guide
In computing, memoization or memoisation
is an optimization technique used primarily
to speed up computer programs by storing
the results of expensive function calls and  
returning the cached result when the same
inputs occur again.                                         
                                                     — wikipedia
@jgcmarins
jgcmarins / ReactNativeFormikExample.tsx
Last active April 5, 2021 00:49
React Native + Formik hooks example
import React from 'react'
import { FormikProvider, useFormik } from 'formik'
import * as yup from 'yup'
import TextInputFormik from './TextInputFormik'
const ReactNativeFormikExample: React.FC<unknown> = (props) => {
const formik = useFormik({
initialValues: {
name: '',
@jgcmarins
jgcmarins / index.js
Created March 20, 2021 00:16
Curebase Technical Interview - Coding Problem (https://www.curebase.com/)
const readlineSync = require('readline-sync');
function isValid1(answer) {
return answer === 'y'
}
function isValid2(answer) {
return Number(answer) >= 18 && Number(answer) <= 75
}
@jgcmarins
jgcmarins / babel.config.js
Created March 3, 2021 19:57
Angora JavaScript build setup with Webpack and Babel (https://www.npmjs.com/package/@angoralabs/angora-js)
module.exports = {
presets: [
'@babel/preset-react',
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
@jgcmarins
jgcmarins / esbuild-relay.js
Created February 19, 2021 19:49 — forked from sciyoshi/esbuild-relay.js
Esbuild plugin for compiling relay queries
import { promises } from "fs";
import crypto from "crypto";
import path from "path";
import { print, parse } from "graphql";
const plugin = {
name: "relay",
setup: build => {
build.onLoad({ filter: /\.tsx$/, namespace: "" }, async args => {
let contents = await promises.readFile(args.path, "utf8");
@jgcmarins
jgcmarins / devTraining.md
Created January 8, 2021 13:27 — forked from sibelius/devTraining.md
How to train your dev team

you should review every pull request of your team

  • each pull request will make understand what everyone in your team is working on
  • it will ensure you keep consistency of file location, and code patterns
  • it will catch bugs/regression early on
  • it will teach the best way to solve the problem

you should ensure consistency of the code base

you should pair programming with all devs of your team

@jgcmarins
jgcmarins / responseTime.ts
Created December 7, 2020 20:27
Koa middleware to measure response time and set X-Response-Time header
export async function responseTime(ctx, next) {
const start = new Date();
await next();
const ms = new Date() - start;
ctx.set('X-Response-Time', ms + 'ms');
}
@jgcmarins
jgcmarins / webpack.config.js
Created November 20, 2020 17:35 — forked from jkinkead/webpack.config.js
Webpack configuration for Google Cloud Functions
const webpack = require('webpack')
const path = require('path')
const nodeExternals = require('webpack-node-externals')
const StartServerPlugin = require('start-server-webpack-plugin')
module.exports = {
entry: [
'webpack/hot/poll?1000',
'./local/server'
],
watch: true,