Skip to content

Instantly share code, notes, and snippets.

View yuripramos's full-sized avatar
currently not coding side-projects

Yuri Pereira Ramos yuripramos

currently not coding side-projects
View GitHub Profile
@yuripramos
yuripramos / createCtx.ts
Created December 21, 2021 18:57
createCtx typescript
import * as React from "react";
/**
* A helper to create a Context and Provider with no upfront default value, and
* without having to check for undefined all the time.
*/
function createCtx<A extends {} | null>() {
const ctx = React.createContext<A | undefined>(undefined);
function useCtx() {
const c = React.useContext(ctx);
@yuripramos
yuripramos / intersection.js
Created December 2, 2021 11:41
Intersection
const tokens = ['USDC', 'USDT', 'ETH'];
const contracts = [{contract:"#CAS#", tokens: ["BTC"]},{contract: "FSA@#", tokens:["ETH","USF"]},{contract: "8%SD8", tokens:["ETH" ]}]
const intersection = contracts.filter(contract => tokens.some(token => {
return contract.tokens.includes(token)
}))
@yuripramos
yuripramos / webpack.config.js
Created August 29, 2020 15:32
enable source map
{
devtool: 'source-map'
}
// just add the sideEffects key inside your package.json file
{
"sideEffects": [
"./src/polyfill.js"
],
}
import { divide, subtract } from "./mathUtils";
divide(1, 2);
@yuripramos
yuripramos / analyze.json
Created August 20, 2020 12:08
analyze JSON
//in that case all the build files were served by build/static adapt to your needs
"scripts": {
"analyze": "webpack-bundle-analyzer 'build/static/js/*.js'",
...
}
@yuripramos
yuripramos / hash.js
Created August 18, 2020 12:17
hash example 1
const path = require('path');
module.exports = {
entry: {
vendor: './vendor.js',
main: './index.js'
},
output: {
path: path.join(__dirname, 'build'),
filename: '[name].[hash].js'
export const fetchSmallDevicesData = async (
resolution,
filters,
pages
) => {
const { data } = await axios.get(
`${URL}?${buildSmartDevicesParameters(
resolutions,
filters,
pages
@yuripramos
yuripramos / useFetch.js
Last active July 11, 2020 15:49
useFetch custom hook
import { useState, useEffect } from 'react';
export function useFetch(
doFetch,
dependencies
) {
const [loading, setLoading] = useState(false);
const [data, setData] = useState();
useEffect(() => {
const state = useContext(MessagesContext);
const [textValue, setTextValue] = useState("");
const [isEmojiEnabled, setIsEmojiEnabled] = useState(false);
const toggleEmoji = () => setIsEmojiEnabled(!isEmojiEnabled);
const myStateRef = useRef(textValue);
const setMyState = (data: any) => {
myStateRef.current = data;