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
const read = async (filePath: string) => { | |
return new Promise((resolve, reject) => { | |
fs.readFile(filePath, 'utf8', (err: any, data: string) => { | |
if (err) reject(err) | |
resolve(data) | |
}) | |
}) | |
} | |
const write = (filePath: string, fileName: string, fileExtension: string, content: any) => { |
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
const useD3 = (renderChartFn: (el: any) => void, dependencies: any[]) => { | |
const ref = useRef<HTMLElement>(); | |
useEffect(() => { | |
if (!!ref.current) { | |
renderChartFn(d3.select(ref.current)); | |
} | |
return () => {}; | |
}, dependencies); |
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
// Source: https://twitter.com/calebporzio/status/1151876736931549185 | |
<div class="flex"> | |
<aside class="h-screen sticky top-0"> | |
// Fixed Sidebar | |
</aside> | |
<main> | |
// Content | |
</main> |
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 React, { | |
useContext, | |
createContext, | |
ReactNode, | |
useMemo, | |
Children, | |
isValidElement, | |
useState | |
} from 'react'; |
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
const encodeGetParams = p => | |
Object.entries(p).map(kv => kv.map(encodeURIComponent).join("=")).join("&"); | |
const params = { | |
user: "María Rodríguez", | |
awesome: true, | |
awesomeness: 64, | |
"ZOMG+&=*(": "*^%*GMOZ" | |
}; |
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
const formatter = new Intl.NumberFormat('en-US', { | |
style: 'currency', | |
currency: 'USD', | |
minimumFractionDigits: 2, | |
}); |
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
// HTML5 Pattern | |
// http://html5pattern.com/ | |
const alphaNumeric = /[a-zA-Z0-9]+/; | |
const userNameWith20Chars = /^[a-zA-Z][a-zA-Z0-9-_\.]{1,20}$/; | |
const twitterHandle = /^[A-Za-z0-9_]{1,15}$/; | |
const password = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).*$/; // Uppercase, lowercase, and number | |
const password2 = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).*$/; // Password (UpperCase, LowerCase, Number/SpecialChar and min 8 Chars) |
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
// Building-blocks to use for composition | |
const double = x => x + x; | |
const triple = x => 3 * x; | |
const quadruple = x => 4 * x; | |
// Function composition enabling pipe functionality | |
const pipe = (...fns) => input => [...fns].reduce((acc, fn) => fn(acc), input); | |
// Composed functions for multiplication of specific values | |
const multiply6 = pipe(double, triple); |
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
const pause = (duration) => new Promise(res => setTimeout(res, duration)); | |
const retry = (retries, fn) => | |
fn().catch(err => retries > 1 ? retry(retries - 1, fn) : Promise.reject(err)); | |
const backoff = (retries, fn, delay = 500) => | |
fn().catch(err => retries > 1 | |
? pause(delay).then(() => backoff(retries - 1, fn, delay * 2)) | |
: Promise.reject(err)); |
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 increment(input) { return input + 1;} | |
function decrement(input) { return input - 1; } | |
function double(input) { return input * 2; } | |
function halve(input) { return input / 2; } | |
var initial_value = 1; | |
var pipeline = [ | |
increment, | |
increment, |