Skip to content

Instantly share code, notes, and snippets.

@thulioph
thulioph / load-nvmrc.sh
Created Nov 5, 2021
Script to call nvm use automatically in a directory with a .nvmrc file
View load-nvmrc.sh
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 Mar 13, 2019
Example of a HOC to manage route permissions in React.
View PrivateRoute.jsx
import React from 'react';
import { withRouter, Redirect } from 'react-router-dom';
const PrivateRoute = (WrappedComponent) => {
class PrivateRoute extends React.Component {
state = {
isLogged: false,
}
_checkAuthentication() {
View fragments.js
import gql from 'graphql-tag';
const USER_FRAGMENT = {
account: gql`
fragment AccountDetails on FinancialUserType {
id
username
email
firstName
lastName
@thulioph
thulioph / zombies.json
Created Nov 18, 2018
Zombies data to test my case of use
View zombies.json
[
{
"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 Sep 20, 2018
An example to demonstrate a Modal component made using Recompose
View ModalHOC.js
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 Sep 20, 2018
An example to demonstrate a Modal component using Reactstrap
View Modal.js
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 Sep 20, 2018
An example to demonstrate a Modal component using class.
View ModalClass.js
import React from "react";
import { ModalComponent } from "./Modal";
class ModalContainer extends React.Component {
state = {
showModal: false
};
onHandleModal = () => {
@thulioph
thulioph / mapProps.js
Created Sep 13, 2018
An example to demonstrate the mapProps API of Recompose
View mapProps.js
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 Sep 13, 2018
An example to demonstrate the withHandlers API of Recompose
View withHandlers.js
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 Sep 13, 2018
An example to demonstrate the nest API of Recompose
View nest.js
import React from 'react';
import { nest } from 'recompose';
const Header = ({ children }) => (
<div>
<header>HEY!</header>
{children}
</div>
);