Skip to content

Instantly share code, notes, and snippets.

View amerllica's full-sized avatar
⚛️
Front-end Developer

Amer Lotfi Orimi amerllica

⚛️
Front-end Developer
View GitHub Profile
@amerllica
amerllica / debounce.js
Last active June 3, 2019 10:28
JavaScript Debounce Function
const searchInput = document.getElementById('search-input');
const searchText = document.getElementById('search-text');
const debounce = (func, wait = 100) => {
let timeout;
return (...args) => {
clearTimeout(timeout);
timeout = setTimeout(() => {
func.apply(this, args);
}, wait);
@amerllica
amerllica / EuclidTree.js
Last active June 3, 2019 10:44
The tree of Euclid
const euclidTree = (width = 100, height = 100) => {
const body = document.body;
const canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
body.appendChild(canvas);
const ctx = canvas.getContext("2d");
const branch = (size, angle) => {
size < 10 ? ctx.strokeRect(0, 0, size, size) : ctx.fillRect(0, 0, size, size);
if (size < 2) return;
@amerllica
amerllica / shuffler.js
Created June 23, 2019 13:36
Simple array shuffler (Using reduce function)
const shuffler = array => array.reduce((accumulator, currentValue) => {
const randomIndex = Math.ceil(Math.random() * 10);
accumulator.splice(randomIndex, 0 ,currentValue);
return accumulator;
}, []);
@amerllica
amerllica / server.ts
Created April 17, 2020 01:39
reactjs server auth
const jwt = require("jsonwebtoken");
const secret = process.env.JWT_SECRET;
export const authCheck = (req, res, next) => {
if (req.headers.authorization) {
const token = req.headers.authorization;
jwt.verify(token, secret, (err, decoded) => {
if (err) {
res.send(401);
} else {
next();
@amerllica
amerllica / .zshrc
Created September 14, 2020 14:17
android path zshell
export ANDROID_HOME=/Users/amerllica/Library/Android/sdk
export JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk-14.0.1.jdk/Contents/Home
export PATH=$JAVA_HOME:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/emulator:$PATH
@amerllica
amerllica / useStateCallback.ts
Last active June 21, 2021 11:25
ReactJS hook for passing state and a setter function with ability of getting callback for each setter call.
import { useRef, useCallback, useEffect, useState } from 'react';
import type { Dispatch, SetStateAction } from 'react';
type StateFunctionType<S> = Dispatch<SetStateAction<S | undefined>>;
type SetStateCallbackGeneric<S> = (
x: S | StateFunctionType<S>,
cb?: Function
) => void;
const useStateCallback = <T>(
@amerllica
amerllica / useHorizontalScroll.ts
Last active June 28, 2021 12:01
Google horizontal scroll for desktop (ReactJS)
import { useEffect } from 'react';
import type { MutableRefObject } from 'react';
const useHorizontalScroll = (
scrollWrapperRef?: MutableRefObject<HTMLElement | undefined>,
scrollSpeed = 1
): void => {
useEffect(() => {
const horizWrapper = scrollWrapperRef?.current;
if (horizWrapper?.style) {
@amerllica
amerllica / deviceDetector.ts
Created March 8, 2022 14:05
Device Detector
export type NameVersion = {
name: string;
version: number;
};
export type DeviceDetector = {
os: NameVersion;
browser: NameVersion;
};
@amerllica
amerllica / currencies_country_flags.json
Created April 14, 2022 17:03 — forked from demirdev/currencies_country_flags.json
Currency list with Country Flag
[
{
"name": "US Dollar",
"symbol": "$",
"symbolNative": "$",
"decimalDigits": 2,
"rounding": 0,
"code": "USD",
"namePlural": "US dollars",
"countryEmoji": "🇺🇸"