Skip to content

Instantly share code, notes, and snippets.

View fernandocamargo's full-sized avatar
💀
I am the beast I worship

Fernando Camargo Del Buono fernandocamargo

💀
I am the beast I worship
View GitHub Profile
import axios from 'axios';
export default axios.create({
baseURL: 'https://api.expertlead.de/v.1.0/',
timeout: 1000,
headers: {
'token': '<YOUR_TOKEN>'
}
});
export default (authenticate, deny) => {
// from https://developers.facebook.com/docs/reference/javascript/FB.login/v6.0
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
// actual integration
import React, { useState } from 'react';
import { saveUser } from 'services/user';
const Users = () => {
const [loading, setLoading] = useState(false);
const [user, setUser] = useState(null);
const [error, setError] = useState(null);
const save = useCallback(() => {
setError(null);
const getBaseURL = () => {
switch(process.env.NODE_ENV) {
case 'staging':
return '//staging-api.nelsoncorp.com/
case 'production':
return '//api.nelsoncorp.com/
default:
return '//localhost:9000/
}
}
const getTotal = (stack, [score, max]) => ({
score: stack.score + score,
max: stack.max + max
});
const getPercentage = ({ score, max }) => score * 100 / max;
const study = ({ score, max }, hours = 1) => ({
until: expected => {
const goal = { score: score + 1, max: max + 1 };
@fernandocamargo
fernandocamargo / item.js
Created January 10, 2020 00:10
Recursive prop-types (menu-like)
import { func, node, oneOf, oneOfType, shape, string } from 'prop-types';
import items from './items';
export const item = {
id: string.isRequired,
children: node.isRequired,
url: oneOfType([string, func]),
target: oneOf(['_blank']),
};
const sample = [
[
[
[
[
[
{
foo: [{ rate: 2.18 }],
},
],
const convert = seconds =>
[
{ label: "year(s)", amount: 31104000 },
{ label: "month(s)", amount: 2592000 },
{ label: "week(s)", amount: 604800 },
{ label: "day(s)", amount: 86400 },
{ label: "hour(s)", amount: 3600 },
{ label: "minute(s)", amount: 60 },
{ label: "second(s)", amount: 1 }
]
import last from "lodash/last";
import React, { Fragment } from "react";
import { usePersisted, useVolatile, useLog } from "nodh";
// your service (async operation)
const fetchGithubRepos = () =>
window
.fetch("https://api.github.com/search/repositories?q=react")
.then(response => response.json());
import React from "react";
import { Provider as Curse } from "nodh";
import YourApp from "./app";
// it works 👍
export default (
<Curse>
<YourApp />
</Curse>