import { useNow } from './useNow'
function MyApp() {
const now = useNow({ interval: 1000 })
return (
<div>The current date is {now}</div>
)
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 get from 'lodash.get' | |
interface SearchMap { | |
[key: string]: number | |
} | |
/** | |
* Performantly get the original index of an item. | |
* Use-case: Get index of item in array A in array B | |
* e.g., Check if user (inside users array) is inside the invitations array |
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
interface SearchMap { | |
[key: string]: boolean | |
} | |
/** | |
* Make it easy to search for an item inside an array | |
* | |
* @input | |
* [{ id: 5 }, { id: 6 }, { id: 7 }, { id: 32 }] | |
* @output |
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
/** | |
* Converts seconds to readable time (e.g., 03:45:24, 45:34, 34) | |
*/ | |
export default function toReadableTime(seconds: number): string { | |
const hh = Math.floor(seconds / 3600) | |
const mm = Math.floor((seconds % 3600 / 60)) | |
const ss = Math.floor(seconds % 60) | |
if (hh >= 1) { | |
return [hh, mm, ss].map(t => String(t).padStart(2, '0')).join(':') |
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
<?php | |
namespace App\Support; | |
use Str; | |
class Helper { | |
/** | |
* e.g., X4345-ZXCA4-S3XYB-3AST1 | |
*/ |
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
/** | |
* Supercharges GatewayDest so that it allows default children, because this does not work: | |
* <GatewayDest><div>Default content if nobody has passed anything to me yet.</GatewayDest> | |
* @see https://github.com/cloudflare/react-gateway/pull/39 | |
* | |
* @usage <GatewayDestWithFallback name={constants.gateway.backUrl} fallback={<UiNavigation.Action />} /> | |
*/ | |
import * as React from 'react' | |
import { GatewayDest } from 'react-gateway' |
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 { parse, subDays } from 'date-fns'; | |
import getEntryTodayDateString from './getEntryTodayDateString' | |
import getEntryDateString from './getEntryDateString' | |
/** | |
* Get the streak between today and the last date. | |
* Assumes that there is an entry for today. | |
*/ | |
export default function getStreak(tracker: AppDataTracker): 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
<?php | |
namespace App\Support; | |
class Helper { | |
/** | |
* Converts an array of objects into an object, keys based on its key | |
* [{ "entry_date": "" }, { "entry_date": "" }] -> { "2019-08-20": {}, ... } | |
*/ | |
static public function toPropertyKeys($array, $property) { |
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 NUMERIC_0 = 48 | |
const NUMERIC_9 = 57 | |
/** | |
* Check if the pressed key (evt.keyCode) is a numeric key | |
*/ | |
export default function isNumericKeyCode(key: number): boolean { | |
return key >= NUMERIC_0 && key <= NUMERIC_9 | |
} |
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 * as React from 'react' | |
import { Route } from 'react-router-dom' | |
import { RouteProps } from 'react-router' | |
class RouterRoute extends React.Component<RouteProps> { | |
render() { | |
const { component, children, ...rest } = this.props | |
const Component = this.props.component | |
return ( |