Skip to content

Instantly share code, notes, and snippets.

View jomifepe's full-sized avatar
:shipit:

José Pereira jomifepe

:shipit:
View GitHub Profile
@jomifepe
jomifepe / useLocaleUpdates.ts
Last active June 8, 2022 10:17
useLocaleUpdates
import { useEffect, useState } from 'react';
import cookie from 'cookie';
import { useRouter } from 'next/router';
import { useTranslation } from 'react-i18next';
import usePrevious from './usePrevious';
import { LocaleDirection } from 'models/types';
import { getLocaleFromUrl, setLocaleCookie, updateLocale } from 'utils/locales';
import { COOKIE_LOCALE_KEY } from 'constants/cookies';
import { DEFAULT_LOCALE, LOCALES } from 'constants/locales';
/**
@jomifepe
jomifepe / _document.tsx
Last active June 7, 2022 14:02
document
/* eslint-disable max-len */
import Document, {
DocumentContext,
DocumentInitialProps,
Head,
Html,
Main,
NextScript,
} from 'next/document';
import React from 'react';
@jomifepe
jomifepe / 0-typescript-react-node-snippets.md
Last active September 28, 2023 23:51
TypeScript, React & Node Snippets

TypeScript, React & Node snippets.

@jomifepe
jomifepe / youtube-blocklist
Last active January 24, 2022 23:12
Youtube Blocklist
2mdn.net
2975c.v.fwmrm.net
ad-g.doubleclick.net
ad.doubleclick.net
ad.mo.doubleclick.net
ad.youtube.com
ads.doubleclick.net
ads.youtube.com
adservice.google.com
analytic-google.com
@jomifepe
jomifepe / getHtmlColorsAsEnum.js
Last active June 12, 2021 15:24
Simple script to get all HTML colors from w3schools as a TypeScript enum (https://www.w3schools.com/colors/colors_names.asp)
// Paste it on the console, while in: https://www.w3schools.com/colors/colors_names.asp
const colors = [...document.querySelectorAll('.colornamespan')].map((el) => el.textContent.toLowerCase())
const enumString = 'export enum HtmlColor {\n' + colors.map((color) => `\t${color} = '${color}'`).join(',\n') + ',\n}';
console.log(enumString);
@jomifepe
jomifepe / getHtmlColorsAsUnion.js
Last active June 12, 2021 15:23
Simple script to get all HTML colors from w3schools as a TypeScript union (https://www.w3schools.com/colors/colors_names.asp)
// Paste it on the console, while in: https://www.w3schools.com/colors/colors_names.asp
const colors = [...document.querySelectorAll('.colornamespan')].map((el) => el.textContent.toLowerCase())
const union = [...colors].reduce((acc, name) => `${acc}| '${name}'\n`, '');
console.log(union);
@jomifepe
jomifepe / getPrefixedStringsAsUnion.js
Last active June 12, 2021 15:23
Simple function that looks for unique words prefixed by something and prints them sorted as a TypeScript union
/**
* Simple function that looks for unique words prefixed by something and prints them sorted as a TypeScript union
* Usage: getPrefixedNamesAsUnion(`.icon-alert{color: white}.icon-arrow{color: red}`, '.icon-');
* Output: 'alert' | 'arrow'
*/
getPrefixedStringsAsUnion = (str, prefix) => {
const escapedPrefix = prefix.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const matches = [...str.matchAll(RegExp(`(?<=${escapedPrefix})[a-zA-Z0-9-_]+`, 'g'))].map((s) => s[0]);
const sortedUniqueStrings = [...new Set(matches)].sort((a, b) => a.localeCompare(b));
@jomifepe
jomifepe / mountUnmountDriveByLabel.bat
Last active June 12, 2021 15:25
Allows you to mount and unmount drives in Windows by its label
@echo off
setlocal ENABLEDELAYEDEXPANSION
set label=VOLUME_LABEL_HERE
set letter=VOLUME_LETTER_HERE
set dpvns="%TEMP%\dpvn.txt"
set dprls="%TEMP%\dprl.txt"
echo list volume>%dpvns%