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
// @source https://github.com/srph/chunk-pattern/blob/master/index.js | |
// Slices the array into chunks based on the pattern. | |
// Useful for intentionally splitting an array into rows and columns on a specific pattern. | |
// e.g., display 4 on top, 2 on bottom. | |
// @use chunkPattern([1, 2, 3, 4, 5], [2, 3]) => [[1, 2], [3, 4, 5]] | |
// @use chunkPattern([1, 2, 3, 4, 5], [4, 1]) => [[1, 2, 3, 4], [5]] | |
const chunkPattern = <T>(array: readonly T[], pattern: number[]): Array<T[]> => { | |
const result: Array<T[]> = [[]] | |
let patternIndex: number = 0 | |
let patternCount: number = pattern[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
// API | |
{ | |
items: [] | |
} | |
// Query | |
{ | |
items: { | |
[id]: { | |
id: 1, |
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
@@ -0,0 +1,44 @@ | |
import { delay } from '../time' | |
type PollValueCallback<T> = () => Promise<T> | |
type PollConditionCallback<T> = (t: T) => boolean | |
interface PollOptions { | |
ms?: number | |
max?: number |
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 { Pubkey } from '@cosmjs/amino' | |
import { Uint64 } from '@cosmjs/math' | |
import { decodePubkey } from '@cosmjs/proto-signing' | |
import { assert } from '@cosmjs/utils' | |
import { stride } from '@stride/proto' | |
import { BaseAccount, ModuleAccount } from 'cosmjs-types/cosmos/auth/v1beta1/auth' | |
import { | |
BaseVestingAccount, | |
ContinuousVestingAccount, | |
DelayedVestingAccount, |
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 { intervalToDuration, isAfter, eachDayOfInterval, addMonths } from 'date-fns' | |
const remaining = intervalToDuration({ | |
start: now, | |
end: target | |
}) | |
const days = | |
remaining.months && remaining.days | |
? remaining.days + |
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 getServerSideProps = withPageAuthRequired({ | |
async getServerSideProps(ctx) { | |
const whitelisted = ['[email protected]'] | |
const session = getSession(ctx.req, ctx.res) | |
if (!whitelisted.includes(session.user.email)) { | |
return { | |
redirect: { | |
destination: '/logout', |
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, useRef } from 'react' | |
// useEffect that runs on mount and works with Suspense / Fast Refresh | |
const useMount = (fn: () => void) => { | |
const isMountedRef = useRef(false) | |
useEffect(() => { | |
if (isMountedRef.current) return | |
isMountedRef.current = true | |
fn() |
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 { delay } from './time' | |
export async function poll<T = any>(callback: () => Promise<T>, condition: (t: T) => boolean, ms: number): Promise<T> { | |
let first = true | |
while (true) { | |
const data = first ? await callback() : await delay(ms).then(callback) | |
if (condition(data) === true) { | |
return data |
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, { useState, useEffect } from 'react' | |
interface MemoizeProps<T, Y extends unknown> { | |
value: () => T | |
dependencies: Y[] | |
} | |
const Memoize = ({ value, dependencies }) => { | |
const [state, setState] = useState(value) | |
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 { pathname } = useRouter() | |
const active: Record<string, boolean> = useMemo(() => { | |
return [ | |
{ key: 'home', url: '/' }, | |
{ key: 'about', url: '/about' }, | |
{ key: 'contact', url: '/contact' } | |
].reduce((object, link) => { | |
object[link.key] = pathname === link.url | |
return object |