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
| 1 -> 2 | |
| 1p0s+0p1s success: 0.348 retain: 0.484 fail: 0.168 efficiency: 0.590 | |
| 0p1s+1p0s success: 0.348 retain: 0.484 fail: 0.168 efficiency: 0.590 | |
| 1p0s+1p0s success: 0.330 retain: 0.670 fail: 0.000 efficiency: 0.665 | |
| 0p1s+0p1s success: 0.330 retain: 0.670 fail: 0.000 efficiency: 0.665 | |
| 2 -> 3 |
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
| // jdn conversions for date arithmetic/comparison | |
| const intDiv = (l,r) => ~~(l/r); // integer division | |
| const jdnFromIso = iso => { | |
| const [y, m, d] = iso.split('-').map(s => parseInt(s, 10)); | |
| return intDiv(1461 * (y + 4800 + intDiv(m - 14, 12)), 4) | |
| + intDiv(367 * (m - 2 - 12 * intDiv(m - 14, 12)), 12) | |
| - intDiv(3 * intDiv(y + 4900 + intDiv(m - 14, 12), 100), 4) | |
| + d - 32075; | |
| }; |
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
| useEffect(() => { | |
| const pFoo = getFoo().then(foo => /* do somthing with our async foo, making sure to return it */); | |
| return () => pFoo.then(foo => /* cleanup here will always run after we have gotten our foo and used it */); | |
| }); | |
| // This is one of the few cases where it makes sense to use raw promises instead of async/await | |
| // The power of promises is that you can compose asynchronous logic asynchronously | |
| // Afaik that's not possible with async/await? |
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
| // f of the form v => v | |
| export const objMap = (obj, f) => | |
| Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, f(v)])); | |
| // f of the form ([k, v]) => [k, v] | |
| export const objMapEntries = (obj, f) => | |
| Object.fromEntries(Object.entries(obj).map(f)); | |
| export const arrDeepMap = (arr, f) => arr.map((x, i, a) => Array.isArray(x) ? arrDeepMap(x, f) : f(x, i, a)); |
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
| // f of the form (k, v) => v | |
| export const objMap = (obj, f) => | |
| Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, f(k, v)])); | |
| // f of the form ([k, v]) => [k, v] | |
| export const objMapEntries = (obj, f) => | |
| Object.fromEntries(Object.entries(obj).map(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
| export default async n => new Promise((res, rej) => window.setTimeout(() => res(), n)) |
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
| export const debounce = (f, delay) => { | |
| let timer = null | |
| return (...args) => { | |
| const execute = () => { | |
| timer = null | |
| f(...args) | |
| } | |
| if (timer !== null) |
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
| export const unique = (arr, eq) => arr.reduce( | |
| (acc, item) => (eq ? acc.find(a => eq(a, item)) !== undefined : acc.includes(item)) | |
| ? acc | |
| : [...acc, item] | |
| , []) |
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 imSet = (objOrArray, path, valueOrFunc) => { | |
| const multipath = Array.isArray(path) && path.length > 1 | |
| const pathItem = Array.isArray(path) ? path[0] : path // unwrap single item array | |
| const isFunc = typeof valueOrFunc === "function" | |
| const value = multipath | |
| ? imSet(objOrArray[pathItem], path.slice(1), valueOrFunc) | |
| : isFunc ? valueOrFunc(objOrArray[pathItem]) : valueOrFunc | |
| if (Array.isArray(objOrArray)) { |
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
| class FooPage { | |
| async loadData () { | |
| const data = await getData() | |
| this.setState({ data }) | |
| } | |
| render () { | |
| return ( | |
| <Page data={this.state.data} loadData={this.loadData}> |
NewerOlder