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
CREATE TABLE `database-name`.`table-name`( | |
... | |
`created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
`modified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | |
) ENGINE = InnoDB; |
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 { fromJSON, toJSON } from ./circular-json'; | |
describe('toJSON', () => { | |
it('handles ordinary objects', () => { | |
const inputs = [ | |
null, | |
{ a: 1, b: { c: 3 }, d: [4, 5, 6], e: undefined }, | |
[1, 2, 3], | |
1, | |
'a', |
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 { useRef, useState } from 'react'; | |
import { Box, Button, HStack } from '@chakra-ui/react'; | |
export default function RefVsState() { | |
const [state, setState] = useState(0); | |
const ref = useRef(0); | |
console.info('----RENDER----'); | |
return ( |
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 addInTimeZone from './addInTimeZone'; | |
import { formatInTimeZone } from 'date-fns-tz'; | |
it('adds days + hours to a date, with timezone awareness', () => { | |
// add a day plus 3 hours to this time, and you'll cross a DST boundary | |
// in both Halifax and LA | |
const start = '2022-11-05T06:12:34.567Z'; | |
const startTime = new Date(start).getTime(); | |
// but in Halifax you cross it adding the day; in LA you cross it adding hours | |
// i.e. in Halifax you add a 25-hr day plus 3 hrs = 28 hrs, and clock time is +3 hrs |
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
// touch triggers both TouchStart and MouseMove events | |
// and not in a bubbling way -- both are thrown no matter how much you preventDefault() | |
// this suppresses the synthetic MouseMove event on touch | |
function onNonTouchMouseMove(mouseMoveHandler: MouseEventHandler<unknown>) { | |
let ignoreMouseMove = false; | |
return { | |
onTouchStart: () => { | |
ignoreMouseMove = true; | |
}, | |
onMouseMove: (event: MouseEvent<unknown>) => { |
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 useRefWithRerender<T>(initialState: T): [MutableRefObject<T>, (value: T) => void] { | |
const ref = useRef(initialState); | |
const [, setState] = useState(true); | |
const setter = useCallback((value: T) => { | |
if (ref.current === value) return; | |
ref.current = value; | |
setState((n) => !n); | |
}, []); |
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 { createSignal, Signal } from "solid-js"; | |
export function createStoredSignal<T>(key: string, defaultValue: T, storage = localStorage): Signal<T> { | |
const initialValue = tryToParse(storage.getItem(key), defaultValue); | |
const [value, setValue] = createSignal<T>(initialValue); | |
const setValueAndStore = ((arg) => { | |
const v = setValue(arg); | |
storage.setItem(key, JSON.stringify(v)); | |
return v; |
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 BrowserParse from 'parse'; | |
import ServerParse from 'parse/node'; | |
import _ from 'lodash'; | |
const isBrowser = !!global.window; | |
const Parse = isBrowser ? BrowserParse : ServerParse; | |
export default Parse; | |
export function initialize(serverURL: string, applicationId: string, javascriptKey: string): void { | |
Parse.serverURL = serverURL; |
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 { useEffect, useRef, EffectCallback, DependencyList } from 'react'; | |
// React.useEffect runs its effect 1) at initialization and then 2) whenever the deps change | |
// Sometimes you don't want (1), just (2). That's what this is for. | |
export function useEffectOnMount(effect: EffectCallback, deps: DependencyList): void { | |
const isMounted = useRef(false); | |
useEffect(() => { | |
if (isMounted.current) return effect(); |
NewerOlder