Skip to content

Instantly share code, notes, and snippets.

View thulioph's full-sized avatar
🔥

Thulio Philipe thulioph

🔥
View GitHub Profile
@thulioph
thulioph / load-nvmrc.sh
Created November 5, 2021 14:35
Script to call nvm use automatically in a directory with a .nvmrc file
load-nvmrc() {
local node_version="$(nvm version)"
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
if [ "$nvmrc_node_version" = "N/A" ]; then
nvm install
elif [ "$nvmrc_node_version" != "$node_version" ]; then
@thulioph
thulioph / PrivateRoute.jsx
Last active March 13, 2019 23:18
Example of a HOC to manage route permissions in React.
import React from 'react';
import { withRouter, Redirect } from 'react-router-dom';
const PrivateRoute = (WrappedComponent) => {
class PrivateRoute extends React.Component {
state = {
isLogged: false,
}
_checkAuthentication() {
import gql from 'graphql-tag';
const USER_FRAGMENT = {
account: gql`
fragment AccountDetails on FinancialUserType {
id
username
email
firstName
lastName
@thulioph
thulioph / zombies.json
Created November 18, 2018 03:40
Zombies data to test my case of use
[
{
"title": "Classic zombies",
"picture": "https://via.placeholder.com/150x80/000000/FFFFFF/?text=Imagem+01",
"description":
"Slow, quiet and clumsy, the reason for these dead to reanimate is unknown. After a zombie apocalypse, all dead humans turn into zombies. Being bitten by a zombie results in illness and death. Can only be killed by massive brain trauma."
},
{
"title": "Voodoo Zombies",
"picture": "https://via.placeholder.com/150x80/000000/FFFFFF/?text=Imagem+02",
@thulioph
thulioph / ModalHOC.js
Last active September 20, 2018 03:28
An example to demonstrate a Modal component made using Recompose
import React from "react";
import { compose, withState, withHandlers } from "recompose";
import { ModalComponent } from "./Modal";
const hoc = compose(
withState("showModal", "updateModal", false),
withHandlers({
onHandleModal: ({ updateModal, showModal }) => () => updateModal(!showModal),
onBtnSuccess: () => () => console.warn("Success"),
@thulioph
thulioph / Modal.js
Last active September 20, 2018 03:49
An example to demonstrate a Modal component using Reactstrap
import React from "react";
import PropTypes from "prop-types";
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from "reactstrap";
export const ModalComponent = ({
showModal,
onHandleModal,
onBtnSuccess,
onBtnCancel,
mainBtnLabel,
@thulioph
thulioph / ModalClass.js
Last active September 20, 2018 03:50
An example to demonstrate a Modal component using class.
import React from "react";
import { ModalComponent } from "./Modal";
class ModalContainer extends React.Component {
state = {
showModal: false
};
onHandleModal = () => {
@thulioph
thulioph / mapProps.js
Created September 13, 2018 04:29
An example to demonstrate the mapProps API of Recompose
import React from 'react';
import { compose, withState, mapProps } from 'recompose';
const MyComponent = ({ myCounter, setCounter }) => (
<div>
<h1>{myCounter}</h1>
<button onClick={() => setCounter(myCounter + 1)}>Add</button>
<button onClick={() => setCounter(myCounter - 1)}>Remove</button>
</div>
);
@thulioph
thulioph / withHandlers.js
Created September 13, 2018 04:06
An example to demonstrate the withHandlers API of Recompose
import React from 'react';
import { compose, withState, withHandlers } from 'recompose';
const MyComponent = ({ counter, increment, decrement, reset }) => (
<div>
<h2>{counter}</h2>
<button onClick={increment}>Add</button>
<button onClick={decrement}>Remove</button>
<button onClick={reset}>Reset</button>
</div>
@thulioph
thulioph / nest.js
Last active September 13, 2018 03:54
An example to demonstrate the nest API of Recompose
import React from 'react';
import { nest } from 'recompose';
const Header = ({ children }) => (
<div>
<header>HEY!</header>
{children}
</div>
);