Skip to content

Instantly share code, notes, and snippets.

View elsangedy's full-sized avatar
🚀

Munir Ahmed Elsangedy elsangedy

🚀
View GitHub Profile
@elsangedy
elsangedy / infiniteScrollMachine.js
Last active September 16, 2019 13:30
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: "infinite-scroll",
initial: "idle",
context: {
page: 1,
size: 2,
total: 0,
keyword: "",
items: []
},
@elsangedy
elsangedy / useSubmit.ts
Last active November 1, 2019 01:52
useSubmit
import { useState, useCallback } from "react";
export function useSubmit(fun: Function): [Function, boolean] {
const [pending, setPending] = useState<boolean>(false);
const submit = useCallback(
(...args) => {
if (pending) return;
const res = fun.apply(this, args);
@elsangedy
elsangedy / hooks-as-plugin.jsx
Created November 27, 2019 18:21
hooks-as-plugin.jsx
import React, { useRef, useMemo, useState, useCallback, useEffect } from "react";
import ReactDOM from "react-dom";
function applyHooks(hooks, initial, ...args) {
return hooks.reduce((prev, next) => {
const nextValue = next(prev, ...args);
if (typeof nextValue === "undefined") {
throw new Error("A hook just returned undefined! This is not allowed.");
}
if (!process.env.NODE_ENV) {
process.env.NODE_ENV = 'development'
}
const clientEnv = require('react-scripts/config/env')().raw
console.log(clientEnv)
const Comp = () => {
const { getInputProps } = useImask({
mask: [
{
mask: '000.000.000-00',
},
{
mask: '00.000.000/0000-00',
}
],
@elsangedy
elsangedy / machine.js
Created November 30, 2020 11:13
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
initial: 'images',
context: {
images: [],
expenses: [],
category: undefined
},
states: {
images: {
on: {
@elsangedy
elsangedy / machine.js
Last active April 15, 2021 14:54
Generated by XState Viz: https://xstate.js.org/viz
// TAP BACKEND
const appMachine = Machine(
{
id: 'tap',
context: {},
initial: 'bootstrap',
on: {
RESTART: 'bootstrap',
},
@elsangedy
elsangedy / machine.js
Last active February 26, 2021 04:40
Generated by XState Viz: https://xstate.js.org/viz
// TAP FRONTEND
const appMachine = Machine(
{
id: 'tap',
initial: 'init',
context: {},
on: {
RESTART: {
target: 'init',
@elsangedy
elsangedy / machine.js
Created March 8, 2021 14:24
Generated by XState Viz: https://xstate.js.org/viz
// INSTRUMENT
const fetchMachine = Machine(
{
id: 'device',
initial: 'connection',
context: {
retries: 0
},
states: {
const S3Client = require('aws-sdk/clients/s3')
const sharp = require('sharp')
const ACCESS_KEY_ID = ''
const SECRET_ACCESS_KEY = ''
const REGION = ''
const BUCKET = ''
const PREFIX = ''
const CHUNK_SIZE = 500
const FILTER = (filesName) => {