TypeScript, React & Node snippets.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { parseArgs } from "https://deno.land/[email protected]/cli/parse_args.ts"; | |
import { join } from "https://deno.land/[email protected]/path/mod.ts"; | |
const { debug } = parseArgs(Deno.args, { boolean: ["debug"], default: { "debug": false } }); | |
const interfaceRegex = /interface\s+(\w+)(\s+extends\s+([\w, ]+))?\s*{([^}]*)}/g; | |
let convertedFiles = 0 | |
function isIncludedDir(filePath: string) { | |
return ["configs", "packages", "scripts"].find((dir) => filePath.startsWith(Deno.realPathSync(dir))) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | |
/** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable max-len */ | |
import Document, { | |
DocumentContext, | |
DocumentInitialProps, | |
Head, | |
Html, | |
Main, | |
NextScript, | |
} from 'next/document'; | |
import React from 'react'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
These snippet are used in the following articles:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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% |
NewerOlder