Skip to content

Instantly share code, notes, and snippets.

View themgoncalves's full-sized avatar
⚜️
Software and cathedrals are much the same – first we build them, then we pray.

Marcos Gonçalves themgoncalves

⚜️
Software and cathedrals are much the same – first we build them, then we pray.
View GitHub Profile
@themgoncalves
themgoncalves / loremIpsum.jsx
Created November 1, 2018 16:20
React SSR components implementation demo
import React from 'react';
export default function LoremIpsum() {
return (
<div>
Bacon ipsum dolor amet pork belly minim pork loin reprehenderit incididunt aliquip hamburger chuck culpa mollit officia nisi pig duis.
Buffalo laboris duis ullamco flank.
Consectetur in excepteur elit ut aute adipisicing et tongue veniam labore dolore exercitation.
Swine consectetur boudin landjaeger, t-bone pork belly laborum.
@themgoncalves
themgoncalves / title.jsx
Last active November 1, 2018 16:23
React SSR components implementation demo
import React from 'react';
export default function Title() {
return (
<React.Fragment>
<h1>React Server Side Render & Code Splitting</h1>
<h2>identifying and loading required assets</h2>
</React.Fragment>
);
}
@themgoncalves
themgoncalves / client.jsx
Created November 1, 2018 16:25
React SSR Client set-up
import React from 'react';
import ReactDOM from 'react-dom';
import Loadable from 'react-loadable';
import App from './components/App';
window.onload = () => {
Loadable.preloadReady().then(() => {
ReactDOM.hydrate(<App />, document.getElementById('app'));
});
};
@themgoncalves
themgoncalves / server.jsx
Last active November 7, 2018 16:27
React SSR Server set-up
import express from 'express';
import path from 'path';
import React from 'react';
import { renderToString } from 'react-dom/server';
import Loadable from 'react-loadable';
import { getBundles } from 'react-loadable-ssr-addon';
import App from './components/App';
const manifest = require('./dist/react-loadable-ssr-addon.json');
const server = express();
@themgoncalves
themgoncalves / reverse.js
Created November 3, 2018 14:35
Reverse a sentence in a most perfomatic way
/*
* Reverse sentence
* @function
* @description Benchmark test <http://jsben.ch/8jGJ6>
* @param {String} sentence - Sentence to be reversed
* @return {String} reversed sentence
*/
const reverse = (sentence) => sentence.split(' ').reverse().join(' ');
// ------------------------------------------------------
@themgoncalves
themgoncalves / spiralMatrix.js
Created November 3, 2018 15:00
Spiral Matrix - Outputs 2 dimensional matrix in spiral sequence
/*
* Spiral Matrix
* @function toSpiral
* @description Outputs 2 dimensional matrix in spiral sequence
* @example
* const matrix = [[1, 2, 3],[4, 5, 6],[7, 8, 9]]
* @param {Array} matrix - 2 dimensional matrix
* @return {Array} given matrix in spiral order
*/
function toSpiral(matrix) {
@themgoncalves
themgoncalves / .babelrc
Last active November 7, 2018 15:22
Babel server configuration
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"@babel/plugin-proposal-class-properties",
"dynamic-import-node",
"react-loadable/babel"
]
@themgoncalves
themgoncalves / homebrew.md
Created February 12, 2019 20:18 — forked from indiesquidge/homebrew.md
How to and Best of Homebrew

Homebrew

How To

Homebrew is a package management system for OS X. You can read more about it here, or simply run

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

to install it.

@themgoncalves
themgoncalves / typescript-merge-refs.ts
Last active August 17, 2020 12:42
Working with multiple references on React - Typescript
import React from 'react';
type Mutable<T> = {
-readonly [k in keyof T]: T[k];
};
const mergeRefs = <T>(...refs: React.Ref<T>[]) => (value: T): void => {
for (let i = 0; i < refs.length; i += 1) {
const ref = refs[i];
@themgoncalves
themgoncalves / typescript-merge-refs-demo.tsx
Last active August 17, 2020 12:57
Working with multiple references on React - Demo
import React from 'react';
import mergeRefs from './typescript-merge-refs.ts';
export interface InputElement extends ICSSCustom, Partial<HTMLInputElement> {
readonly?: boolean;
disabled?: boolean;
onChange: (value: string) => void;
}