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
""" | |
Assume we have a graph modeled as a dictionary like so: | |
graph = { | |
'a': ['b', 'c'], | |
'b': ['d'], | |
'c': ['e'], | |
'd': ['f'], | |
'e': [], | |
'f': [] |
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
""" | |
Assume we have a graph modeled as a dictionary like so: | |
graph = { | |
'a': ['b', 'c'], | |
'b': ['d'], | |
'c': ['e'], | |
'd': ['f'], | |
'e': [], | |
'f': [] | |
} |
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
""" | |
Assume we have a graph modeled as a dictionary like so: | |
graph = { | |
'a': ['b', 'c'], | |
'b': ['d'], | |
'c': ['e'], | |
'd': ['f'], | |
'e': [], | |
'f': [] | |
} |
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
function maxInMap<K>(map: Map<K, number>) { | |
return [...map.entries()].reduce((acc, el) => | |
el[1] > acc[1] ? el : acc | |
)[0]; | |
} |
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
const re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/; | |
const match = re.exec('2021-04-24'); | |
const { year, month, day } = match.groups; | |
console.log({ year, month, day }); | |
// { year: '2021', month: '04', day: '24' } |
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
#!/usr/bin/env bash | |
function npm-do { (PATH=$(npm bin):$PATH; eval $@;) } | |
for file in src/*.re src/*.rei; do | |
[ -f "$file" ] || break | |
FILENAME=${file#src/} | |
BASENAME=${FILENAME%%.*} | |
cd src |
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
const sharp = require('sharp'); | |
const fs = require('fs'); | |
const path = require('path'); | |
// Set your sizes array based on the needs of your application. | |
const sizes = [ | |
{ width: 480, suffix: 'sm' }, | |
{ width: 800, suffix: 'md' }, | |
{ width: 1080, suffix: 'lg' }, | |
{ width: 1280, suffix: 'xl' }, |
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
/** | |
* Modified from Sophie's StackOverflow answer here: | |
* https://stackoverflow.com/questions/23618744/rendering-comma-separated-list-of-links | |
*/ | |
function intersperse<T>(arr: T[], sep: any) { | |
if (arr.length === 0) { | |
return []; | |
} |
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 React from 'react'; | |
/* eslint-disable no-console */ | |
export const useTraceUpdate = <P>(props: P) => { | |
const prev = React.useRef(props); | |
React.useEffect(() => { | |
const changedProps = Object.entries(props).reduce((ps, [k, v]) => { | |
if (prev.current[k] !== v) { | |
ps[k] = [prev.current[k], v]; | |
} |