This file contains 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
// TS Decorators | |
function Component(constructor: Function) { | |
// here we can do something like add/modify/enhance/delete properties from class methods | |
constructor.prototype.uniqueID = Math.random(); | |
constructor.prototype.insertInDOM = () => { | |
console.log(`Inserting component in DOM`); | |
}; | |
} |
This file contains 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
// type `never` is great for exhaustive checking, great for exhaustive switch statements | |
type Bird = { | |
kind: 'bird' | |
legs: number | |
wings: 2 | |
} | |
type Dog = { | |
kind: 'dog' | |
legs: number | |
} |
This file contains 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
// ==UserScript== | |
// @name Email Scraper | |
// @namespace http://tampermonkey.net/ | |
// @version 0.2 | |
// @description Scrape emails across multiple pages and save to CSV | |
// @match https://solicitors.lawsociety.org.uk/* | |
// @grant GM_setValue | |
// @grant GM_getValue | |
// @run-at document-end | |
// @license MIT |
This file contains 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
// Types for the result object with discriminated union | |
type Success<T> = { | |
data: T; | |
error: null; | |
}; | |
type Failure<E> = { | |
data: null; | |
error: E; | |
}; |
This file contains 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
// Types for the result object with discriminated union | |
type Success<T> = { | |
data: T; | |
error: null; | |
}; | |
type Failure<E> = { | |
data: null; | |
error: E; | |
}; |
This file contains 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
// **** Types **** // | |
export type TFunc = (...args: any[]) => any; | |
export type TEmail = `${string}@${string}`; | |
export type TColor = `#${string}`; | |
// **** Variables **** // | |
const EMAIL_RGX = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9-]*\.)+[A-Z]{2,}$/i, |
This file contains 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
function slow(id, cb) { | |
setTimeout(function () { | |
cb(null, id) | |
}, Math.random() * 3000) | |
} | |
let promises = [] | |
for (let i = 0; i < 3; i++) { | |
const prom = new Promise((resolve, reject) => { | |
slow(i, function (err, res) { |
This file contains 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
export default function App() { | |
const [isOpen, setIsOpen] = React.useState(false); | |
const ref = React.useRef(null); | |
React.useEffect(() => { | |
if (isOpen === true) { | |
const handleEvent = (e) => { | |
const element = ref.current; | |
if (element && !element.contains(e.target)) { |
This file contains 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 { | |
createContext, | |
memo, | |
useCallback, | |
useContext, | |
useEffect, | |
useId, | |
useLayoutEffect, | |
useMemo, | |
useReducer, |
This file contains 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
/* | |
Josh Comeau Reset https://www.joshwcomeau.com/css/custom-css-reset/ with my tweaks | |
*/ | |
*, | |
*::before, | |
*::after { | |
box-sizing: border-box; | |
} | |
* { | |
margin: 0; |
NewerOlder