Skip to content

Instantly share code, notes, and snippets.

View AugustoCalaca's full-sized avatar

Augusto Calaca AugustoCalaca

View GitHub Profile
@AugustoCalaca
AugustoCalaca / initEnvironment.tsx
Created June 29, 2020 03:16 — forked from sibelius/initEnvironment.tsx
initEnvironment to be used for SSR
export const initEnvironment = (records = {}) => {
const network = Network.create(cacheHandler);
const source = new RecordSource(records);
const store = new Store(source, {
// This property tells Relay to not immediately clear its cache when the user
// navigates around the app. Relay will hold onto the specified number of
// query results, allowing the user to return to recently visited pages
// and reusing cached data if its available/fresh.
gcReleaseBufferSize: 10,
@AugustoCalaca
AugustoCalaca / withData.tsx
Created July 13, 2020 03:07
inject query and variables to relay fectQuery on next ssr
import React from 'react';
import { NextPage } from 'next';
import { DocumentContext } from 'next/document';
import { RelayEnvironmentProvider, fetchQuery } from 'react-relay/hooks';
import { GraphQLTaggedNode, Variables } from 'relay-runtime';
import { initEnvironment } from './createEnvironment';
type OptionsWithData = {
query: GraphQLTaggedNode;
@AugustoCalaca
AugustoCalaca / _document.tsx
Created July 21, 2020 17:41
Styled Components and Material UI working on server side with nextjs
import React from 'react';
import { ServerStyleSheet } from 'styled-components';
import { ServerStyleSheets } from '@material-ui/core/styles';
import Document, { Html, Head, Main, NextScript } from 'next/document';
class MyDocument extends Document {
static async getInitialProps(context) {
const styledComponentsSheet = new ServerStyleSheet();
const materialSheets = new ServerStyleSheets();
const originalRenderPage = context.renderPage;
@AugustoCalaca
AugustoCalaca / webpack.server.js
Created July 29, 2020 13:38 — forked from sibelius/webpack.server.js
Webpack config for server
const path = require('path');
const webpack = require('webpack');
const WebpackNodeExternals = require('webpack-node-externals');
const ReloadServerPlugin = require('reload-server-webpack-plugin');
const cwd = process.cwd();
module.exports = {
@AugustoCalaca
AugustoCalaca / AutocompleteRelay.tsx
Created July 29, 2020 13:40 — forked from sibelius/AutocompleteRelay.tsx
@material-ui Autocomplete lab with react-window + infinite-loader for GraphQL/Relay connections
import React, { useRef, useState } from 'react';
import { Typography } from '@material-ui/core';
import TextField from '@material-ui/core/TextField';
import CircularProgress from '@material-ui/core/CircularProgress';
import Autocomplete, {
AutocompleteChangeDetails,
AutocompleteChangeReason,
AutocompleteProps
} from '@material-ui/lab/Autocomplete';
@AugustoCalaca
AugustoCalaca / liveStreaming.txt
Last active August 21, 2020 14:36
Serviços de live streaming
https://www.sitehosting.com.br/streaming-de-video-ao-vivo/
https://www.mediastream.com.br/
https://colorwhistle.com/live-stream-video-on-website/
https://habr.com/ru/post/453374/
https://www.twilio.com/voice/conference
https://whereby.com/
@AugustoCalaca
AugustoCalaca / Fragments.md
Created September 11, 2020 13:52
Resume about relay fragments

About Fragment

  • Fragment is the building block of the relay
  • Fragment is a selection of fields on a GraphQL Type
  • Fragment allow you to colocate data
  • Relay composes fragments from multiple components into optimized and efficient batches to reduce round-trips to the server
  • Its hard to over-fetch and under-fetch
  • Components can only access data they've asked for - data mask - each one must declare its own data requirements without relying on others
  • Components only re-render when the exact data they're using is updated, preventing unnecessary re-renders
  • In short, colocating data make your components modular, easier to refactor, more performant and less error-prone
@AugustoCalaca
AugustoCalaca / FormWithTinymce.tsx
Last active September 22, 2020 12:22
Example of how to use tinymce as controlled component by formik with text field material-ui
import React from 'react';
import { useFormik } from 'formik';
import * as Yup from 'yup';
import Button from '@material-ui/core/Button';
import TextField from '@material-ui/core/TextField';
import EditorField from './EditorField';
type InitialValuesFormikType = {
editor: string;
@AugustoCalaca
AugustoCalaca / base64ToPDF.js
Created January 8, 2021 12:29
how to convert a base64 to pdf url
const base64ToPDF = (base64) => {
const byteString = window.atob(base64);
const arrayBuffer = new ArrayBuffer(byteString.length);
const int8Array = new Uint8Array(arrayBuffer);
for (let i = 0; i < byteString.length; i += 1) {
int8Array[i] = byteString.charCodeAt(i);
}
const blob = new Blob([int8Array], { type: 'application/pdf' });
const pdfURL = URL.createObjectURL(blob);
@AugustoCalaca
AugustoCalaca / babel.config.js
Created January 12, 2021 21:31 — forked from jgcmarins/babel.config.js
Webpack configs for Node.js backends to run both locally and on AWS Lambda
module.exports = {
presets: [
'@babel/preset-react',
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},