Skip to content

Instantly share code, notes, and snippets.

View fadi-george's full-sized avatar

Fadi George fadi-george

View GitHub Profile
@fadi-george
fadi-george / day24.ts
Created December 24, 2023 09:01
Advent of Typescript 2023
type Santa = "🎅";
type Alley = " ";
type MazeMatrix = MazeItem[][];
type MazeItem = "🎄" | "🎅" | " ";
type Directions = "up" | "down" | "left" | "right";
type FindSantaCol<
T extends MazeItem[],
A extends any[] = [],
AL extends number = A["length"],
class StorageHelper {
private storage: Storage;
private tempStorage: Record<string, string> = {};
public isStorageAvailable: boolean;
constructor(storage: "sessionStorage" | "localStorage") {
this.storage = window[storage];
this.isStorageAvailable = this.checkIfStorageAvailable();
}
@fadi-george
fadi-george / codeshift-remove-alias.js
Created February 10, 2022 01:29 — forked from jaroslav-kubicek/codeshift-remove-alias.js
Codeshift script to remove import alias
const path = require("path");
function replacePathAlias(currentFilePath, importPath, pathMap) {
// if windows env, convert backslashes to "/" first
console.log(currentFilePath)
currentFilePath = path.posix.join(...currentFilePath.split(path.sep));
const regex = createRegex(pathMap);
return importPath.replace(regex, replacer);
@fadi-george
fadi-george / renderWithProviders
Created September 9, 2020 03:24
Test util helper for rendering components with various context/providers (e.g. Redux)
import { Provider } from 'react-redux';
import { Router } from 'react-router-dom';
import { SWRConfig } from 'swr';
import { MuiThemeProvider } from '@material-ui/core';
import { SnackbarProvider } from 'notistack';
import { MuiPickersUtilsProvider } from '@material-ui/pickers';
export const Providers = ({
children,
history,
// js
const modifyClassList = (
method: string,
ids: Array<string>,
classStyle: Array<string>,
) => {
let el: any;
ids.forEach((id: string) => {
el = document.querySelector(id);
if (el) {
@fadi-george
fadi-george / Material UI Dialog & Actions
Created July 1, 2020 06:25
Generic Dialog to handle most situation
import React from 'react';
// types
import type { ButtonProps, DialogProps } from '@material-ui/core';
// mui
import {
Box,
Button,
Dialog as MUIDialog,
interface SWRProps {
api: keyInterface;
children?: Function | null;
options?: any;
showRetry?: boolean;
}
export const Fetcher: React.FC<SWRProps> = ({
api,
children,