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 { useState } from "react"; | |
export function useLocalStorage<T>(key: string, initialValue: T): [T, (s: T) => void] { | |
// State to store our value | |
// Pass initial state function to useState so logic is only executed once | |
const [storedValue, setStoredValue] = useState<T>(() => { | |
try { | |
// Get from local storage by key | |
const item = window.localStorage.getItem(key); | |
// Parse stored json or if none return initialValue |
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
from pylivetrader.api import * | |
import logbook | |
log = logbook.Logger('track-ticker') | |
def enter_play(context, data): | |
s = context.ticker |
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 startCountingForHideAndSeek() { | |
// State for managing cleanup and cancelling | |
let finished = false; | |
let cancel = () => finished = true; | |
const promise = new Promise((resolve, reject) => { | |
// | |
// Custom Promise Logic | |
// | |
// NOTE: This countdown not finish in exactly 10 seconds, don't build timers this way! |
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
// Promis-ifying `setTimeout`, handy to have | |
function timeout(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
// Example promise-creator. This one happens to load scripts synchronously in a browser, | |
// but you can work with any kind of promise here, even in node. | |
function getScript(src) { | |
return new Promise((resolve, reject) => { | |
const element = document.createElement('script'); |
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
#!/bin/bash | |
expo build:web | |
web_build_return_code="$?" | |
echo "yourwebsitehere.com" > web-build/CNAME | |
exit "${web_build_return_code}" |
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
Cypress.Commands.add('mockGeolocation', (latitude, longitude) => { | |
cy.window().then(($window) => { | |
cy.stub($window.navigator.geolocation, 'getCurrentPosition', (callback) => { | |
return callback({ coords: { latitude, longitude } }); | |
}); | |
}); | |
}); |
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
// From https://github.com/cypress-io/cypress/issues/702#issuecomment-435873135 | |
beforeEach(() => { | |
if (window.navigator && navigator.serviceWorker) { | |
navigator.serviceWorker.getRegistrations() | |
.then((registrations) => { | |
registrations.forEach((registration) => { | |
registration.unregister(); | |
}); | |
}); | |
} |
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 { renderHook, act } from '@testing-library/react-hooks' | |
import { useFakeTimers, SinonFakeTimers } from 'sinon'; | |
import { useTime } from '.'; | |
describe('useTime (sinon clocks)', () => { | |
let clock: SinonFakeTimers; | |
beforeEach(() => { clock = useFakeTimers(); }); | |
afterEach(() => { clock.restore(); }); |
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 React, { FunctionComponent, ReactNode } from 'react'; | |
import { useResumeURL, ConfigurationContext } from '.'; | |
import { renderHook } from '@testing-library/react-hooks'; | |
describe('useResumeURL (context)', () => { | |
const makeWrapper = (value: any): FunctionComponent => ({ children }: { children?: ReactNode }) => ( | |
<ConfigurationContext.Provider value={value}> | |
{children} | |
</ConfigurationContext.Provider> | |
); |
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 React from 'react'; | |
import { useResumeURL } from '.'; | |
export const ConfigSection = () => { | |
const url = useResumeURL(); | |
return <div> | |
<a href={url} target="_blank" rel="noopener noreferrer">Open my resume</a> | |
</div>; | |
} |
NewerOlder