Skip to content

Instantly share code, notes, and snippets.

View OlivierJM's full-sized avatar

Olivier JM OlivierJM

View GitHub Profile
import { useEffect, useState } from 'react';
/**
* Debounce a value to avoid constant calls to the server
* @param value it can be a string or a number
* @param delay the amount in milliseconds that will be delayed
* @returns The give value debounced
*/
export default function useDebounceValue<T>(value: T, delay: number): T {
const [debouncedValue, setDebouncedValue] = useState<T>(value);
function removeDuplicates(arr, prop){
return arr.filter((obj, index, self) => {
return index === self.findIndex((t) => {
return t[prop] === obj[prop]
})
})
}
function onInputChange(file) {
// convert image file to base64 string
const reader = new FileReader();
reader.addEventListener(
'load',
() => {
setInputImg(reader.result);
},
false
const createImage = url => {
return new Promise((resolve, reject) => {
const image = new Image();
image.addEventListener('load', () => resolve(image));
image.addEventListener('error', error => reject(error));
image.setAttribute('crossOrigin', 'anonymous');
image.src = url;
});
};
import React, { useState } from 'react'
import Cropper from 'react-easy-crop'
import { getCroppedImg } from '../../../utils/helpers'
export default function ImageCropper({ getBlob, inputImg, fileName }){
const [crop, setCrop] = useState({ x: 0, y: 0 })
const [zoom, setZoom] = useState(1)
const onCropComplete = async (_, croppedAreaPixels) => {
const croppedImage = await getCroppedImg(
inputImg,
@OlivierJM
OlivierJM / moment-js-timezones.txt
Created September 22, 2021 09:19 — forked from diogocapela/moment-js-timezones.txt
List of All Moment.js Timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Asmera
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
function countingValleys(steps, path) {
for (let index = 0; index < steps; index++) {
const currentStep = path[index];
const nextStep = path[index + 1];
let downHill = 0;
let upHill = 0;
if (currentStep + nextStep !== "UD") {
if (currentStep === nextStep) {
// we are either going downhill or uphill
// now check if currentStep is D which means downhil, if U then upHill
import * as actions from "../actions/";
import * as types from "../utils/types";
import { moviesMock } from "../utils/moviemock";
describe("actions", () => {
it("should create an action to fetch popular movies", () => {
const fetchMovieAction = {
type: types.FETCH_POPULAR_MOVIES,
movies: moviesMock
};
import { createContext, useContext, useState } from "react";
// Consumer
// useContext
const AppContext = createContext();
const ThemeContext = createContext();
export default function App() {
const [language, setLanguage] = useState("en-US");
const [color, setColor] = useState("blue");
import { useState } from 'react'
import { Button } from '@chakra-ui/react'
const initialState = {
age: 0,
name: '',
address: '',
phoneNumber: '',
location: '',
}