Skip to content

Instantly share code, notes, and snippets.

View rafabarbosa's full-sized avatar
:octocat:
coding

Rafael Barbosa rafabarbosa

:octocat:
coding
  • Sergipe, Brazil
View GitHub Profile
@rafabarbosa
rafabarbosa / Form.tsx
Created May 24, 2022 20:24 — forked from pjchender/Form.tsx
Nested Object Fields in React Hook Form
import { DevTool } from '@hookform/devtools';
import { yupResolver } from '@hookform/resolvers/yup';
import { Button, makeStyles, TextField } from '@material-ui/core';
import { Controller, SubmitHandler, useForm } from 'react-hook-form';
import * as yup from 'yup';
const useStyles = makeStyles(theme => ({
root: {
display: 'flex',
flexDirection: 'column',
@rafabarbosa
rafabarbosa / Finance.excel.rate.js
Created January 29, 2021 12:08 — forked from kucukharf/Finance.excel.rate.js
Excel RATE() Javascript Function
/*!
* @fileOverview Finance Excel Rate Formula Javascript Equivalent
* @version 1.0.0
*
* @author Burak Arslan @kucukharf http://www.github.com/kucukharf
* @license
* Copyright (c) 2010-2018 Burak Arslan
* Licensed under Creative Commons (CC) license
* @usage RATE($periods, $payment, $present, $future, $type, $guess)
*/
@rafabarbosa
rafabarbosa / ExcelFormulas.js
Created January 29, 2021 12:07 — forked from pies/ExcelFormulas.js
Few Excel formulas - PMT, PPMT, XIRR - expressed in Javascript
/* Based on
* - EGM Mathematical Finance class by Enrique Garcia M. <egarcia@egm.co>
* - A Guide to the PMT, FV, IPMT and PPMT Functions by Kevin (aka MWVisa1)
*/
var ExcelFormulas = {
PVIF: function(rate, nper) {
return Math.pow(1 + rate, nper);
},
@rafabarbosa
rafabarbosa / _readme.md
Created August 31, 2020 12:20 — forked from andywer/_readme.md
React - Functional error boundaries

React - Functional error boundaries

Thanks to React hooks you have now happily turned all your classes into functional components.

Wait, all your components? Not quite. There is one thing that can still only be implemented using classes: Error boundaries.

There is just no functional equivalent for componentDidCatch and deriveStateFromError yet.

Proposed solution

// Add a 401 response interceptor
window.axios.interceptors.response.use(function (response) {
return response;
}, function (error) {
if (401 === error.response.status) {
swal({
title: "Session Expired",
text: "Your session has expired. Would you like to be redirected to the login page?",
type: "warning",
showCancelButton: true,
@rafabarbosa
rafabarbosa / index.markdown
Created March 4, 2020 20:11
Integrações RD Station - PHP

Integrações RD Station

PHP

Muitos sites em PHP possuem uma página que é um script para enviar o email de contato ou tratar o preenchimento de algum formulário.

Para fazer com que essa página envie os dados para o CRM do RD Station, é só inserir nosso script de integração em seu código e fazer a chamada quando for controlar a submissão dos dados.

Script para integração

@rafabarbosa
rafabarbosa / optimize.php
Created April 18, 2019 18:58 — forked from fians/optimize.php
Optimize Image in PHP using Imagick according Google Pagespeed Recommendation
/**
* Optimize image image
*
* https://developers.google.com/speed/docs/insights/OptimizeImages
* -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace sRGB
*
* @access public
* @param string $filePath Path of the file
* @return string Raw image result from the process
*/
@rafabarbosa
rafabarbosa / EasyDockerEngine.md
Created January 9, 2018 14:44 — forked from VirtuBox/EasyDockerEngine.md
Docker Apps with Nginx as reverse proxy using EasyEngine

easydockerengine

Small list of useful docker containers with nginx as reverse proxy using easyengine. To deploy on Debian/Ubuntu.

1) Install docker

   wget -qO- https://get.docker.com/ | sh

2) Install easyengine

@rafabarbosa
rafabarbosa / es7-async-await.js
Created December 11, 2017 11:56 — forked from msmfsd/es7-async-await.js
Javascript fetch JSON with ES7 Async Await
// Async/Await requirements: Latest Chrome/FF browser or Babel: https://babeljs.io/docs/plugins/transform-async-to-generator/
// Fetch requirements: Latest Chrome/FF browser or Github fetch polyfill: https://github.com/github/fetch
// async function
async function fetchAsync () {
// await response of fetch call
let response = await fetch('https://api.github.com');
// only proceed once promise is resolved
let data = await response.json();
// only proceed once second promise is resolved
@rafabarbosa
rafabarbosa / plugin.php
Created November 7, 2017 12:48 — forked from claudiosanches/plugin.php
WooCommerce - Send "New User Registration" email to admins when new customer is created.
<?php
/**
* Send "New User Registration" email to admins when new customer is created on WooCommerce.
*
* @param int $id New customer ID.
*/
function my_wc_customer_created_notification( $id ) {
wp_new_user_notification( $id, null, 'admin' );
}