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
| def occurrences(text1, text2): | |
| result = 0 | |
| unique_characters = [] | |
| # for every character in text1 | |
| for character in text1: | |
| # check whether or not the character has been encountered before | |
| if character not in unique_characters: | |
| # if not, add that character to the list | |
| unique_characters.append(character) | |
| # for every character in text2 |
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
| // Usage | |
| import React from 'react'; | |
| injectLogger(React.Component); | |
| // You can also make it specific to just a component | |
| class App extends React.Component {} | |
| injectLogger(App); | |
| // Injecting logger will add additional boolean param to setState. | |
| // Set this to true to perform setState logging |
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
| { | |
| "data": { | |
| "authStatus": "AUTHORIZED", | |
| "authMessage": null, | |
| "rescheduleDetail": { | |
| "rescheduleId": "35001186", | |
| "rescheduleType": "RESCHEDULE_FLIGHT_BASIC", | |
| "rescheduleStatus": "ACTIVE", | |
| "notReschedulableReason": null, | |
| "agentRescheduleStatusType": "INFO", |
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 LRUMap extends Map { | |
| constructor(maxSize = 1) { | |
| super(); | |
| this.maxSize = maxSize; | |
| this.insertionOrder = []; | |
| this.set = this.set.bind(this); | |
| } | |
| set(key, 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
| import React from 'react'; | |
| import { text } from '@storybook/addon-knobs'; | |
| import { storiesOf } from '@storybook/react'; | |
| import HelloWorld from './HelloWorld'; | |
| const DECORATOR = renderStory => ( | |
| <React.Fragment>{renderStory()}</React.Fragment> | |
| ); |
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 { useEffect, useState } = React; | |
| export default function IndexPage(props) { | |
| const [currentHash, setCurrentHash] = useState(window.location.hash); | |
| useEffect(() => { | |
| function handleHashChange(e) { | |
| setCurrentHash(window.location.hash); | |
| } | |
| window.addEventListener('hashchange', handleHashChange); |
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
| /** | |
| * Function component with Hooks | |
| * @see: https://reactjs.org/docs/hooks-intro.html | |
| */ | |
| import { useRouter } from "next/router"; | |
| function FunctionComponentPage() { | |
| const router = useRouter(); | |
| return <h1>{`ID: ${router.query.id}`}</h1>; | |
| } |
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
| function createService<F extends (...args: any[]) => Promise<any>>(fn: F) { | |
| type Result = PromiseType<ReturnType<typeof fn>>; | |
| type Entry = Result | Promise<void> | Error; | |
| // const cache = new LRU<string, Entry>({maxSize: 5}); | |
| const cache = new Map(); | |
| return { | |
| call(...args: Parameters<typeof fn>): Result { | |
| const key = JSON.stringify(args); | |
| const hit = cache.get(key); | |
| if (!hit) { |
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 { range, map } from './utils.js'; | |
| let iter = range(0, 1000); // almost-zero memory & computation overhead! | |
| let list = ( | |
| <ul> | |
| {map(iter, n => <li key={n}>{n}</li>) | |
| </ul> | |
| ); |
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
| module.exports = function (babel) { | |
| const { types: t } = babel; | |
| let counter = 0; | |
| const specialProps = { | |
| padding: 1, | |
| borderRadius: 1 | |
| }; | |
| let styles = null; |
OlderNewer