Skip to content

Instantly share code, notes, and snippets.

View maxgfr's full-sized avatar
🎯
Focusing

Maxime Golfier maxgfr

🎯
Focusing
View GitHub Profile
@maxgfr
maxgfr / bypass.js
Created November 10, 2024 10:00
Bypass copy and paste restriction on a webpage by using Console
// Désactive toutes les restrictions de copier-coller
document.addEventListener('copy', function(e) {
e.stopPropagation();
}, true);
document.addEventListener('paste', function(e) {
e.stopPropagation();
}, true);
document.addEventListener('cut', function(e) {
@maxgfr
maxgfr / emitter.ts
Last active April 10, 2024 13:37
Example of an emitter using observer pattern
export enum EventType {
SEND_RESULT_EVENT = "sendResultEvent",
SEND_RANDOM_ITEM = "sendRandomItem",
}
export type CallbackEventType = {
[EventType.SEND_RESULT_EVENT]: (isEligible: boolean) => void;
[EventType.SEND_RANDOM_ITEM]: (valueA: string, valueB: number) => void;
};
@maxgfr
maxgfr / migration.md
Last active March 13, 2024 10:39
From azure storage to s3

Migrate files from azure storage to s3 using cli

Dowload files from azure

mkdir toto && cd toto
az storage blob download-batch --account-name account_name --account-key account_key --source bucket_name --destination . --pattern "*" 

Upload to S3

@maxgfr
maxgfr / .zshrc
Last active June 9, 2024 16:31
My .zshrc config
export ZSH="/Users/max/.oh-my-zsh"
ZSH_THEME="robbyrussell"
plugins=(git
zsh-autosuggestions
zsh-syntax-highlighting
)
source $ZSH/oh-my-zsh.sh
@maxgfr
maxgfr / useful.ts
Created February 12, 2024 11:06
Useful types in typescript
export type CamelCase<S extends string> =
S extends `${infer P1}_${infer P2}${infer P3}`
? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}`
: Lowercase<S>;
export type KeysToCamelCase<T> = {
[K in keyof T as CamelCase<string & K>]: T[K] extends {}
? KeysToCamelCase<T[K]>
: T[K];
};
@maxgfr
maxgfr / getValue.ts
Last active November 21, 2023 13:58
getValue with type inference in typescript
const getValue = <TObj, Tkey extends keyof TObj> (obj: TObj, key: Tkey) => obj[key]
const result = getValue({a: "hello", b: 2, c: true}, "a")
console.log(result) // defined as string
const result2 = getValue({a: "hello", b: 2, c: true}, "b")
console.log(result2) // defined as number
import React, { forwardRef } from "react";
// Declare a type that works with
// generic components
type FixedForwardRef = <T, P = {}>(
render: (props: P, ref: React.Ref<T>) => React.ReactNode
) => (props: P & React.RefAttributes<T>) => React.ReactNode;
// Cast the old forwardRef to the new one
export const fixedForwardRef =
@maxgfr
maxgfr / singleton_factory_1.ts
Last active June 30, 2023 14:23
Example of Singleton which generate one object or the other
type Vehicule = "Voiture" | "Camion";
class Voiture {
public taille = "2m"
constructor() {
console.log("Je suis une voiture");
}
}
class Camion {
@maxgfr
maxgfr / MultiSingletonHelper.ts
Created June 30, 2023 10:46
A Singleton with multiple instance which returns the good instance
class MultiSingletonHelper {
private static readonly instances: MultiSingletonHelper[] = [];
private readonly param1: string;
private readonly param2?: string;
private constructor(param1: string, param2?: string) {
this.param1 = param1;
this.param2 = param2;
@maxgfr
maxgfr / .eslintrc.js
Last active June 21, 2023 15:09
React Typescript Storybook Prettier TestingLibrary Cypress eslint config
module.exports = {
root: true,
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:react/jsx-runtime',
'plugin:storybook/recommended',
'plugin:import/recommended',
'plugin:jsx-a11y/recommended',