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
| type Node<T> = { | |
| next: Node<T>; | |
| prev: Node<T>; | |
| key: number; | |
| value: T; | |
| }; | |
| class LRUCache { | |
| private capacity: number; | |
| private size: number = 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
| import {useRef, useState, useCallback, useEffect} from 'react'; | |
| function useStateThen(initialValue) { | |
| const p = useRef(null); | |
| const [value, setValue] = useState(initialValue); | |
| const wrappedSetValue = useCallback((...args) => { | |
| return new Promise(resolve => { | |
| p.current = resolve; | |
| setValue(...args); | |
| }); |
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 com.amazonaws.services.lambda.runtime.Context; | |
| import io.javalin.Javalin; | |
| import io.javalin.http.HandlerType; | |
| import org.slf4j.Logger; | |
| import org.slf4j.LoggerFactory; | |
| import java.util.Map; | |
| import java.util.regex.Pattern; | |
| import java.util.stream.Collectors; |
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 withUrlState from './with-url-state'; | |
| function Example({urlState, setUrlState}) { | |
| const {count} = urlState; | |
| return <button onClick={() => setUrlState({count: count + 1})}>{count}</button>; | |
| } | |
| export default withUrlState({count: 0})(Example); |
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, { Component, PropTypes } from 'react' | |
| import { render } from 'react-dom' | |
| import withContext from './with-context' | |
| import thread from './thread' | |
| class Parent extends Component { | |
| static childContextTypes = { | |
| someContext1: PropTypes.object, | |
| someContext2: PropTypes.object | |
| } |
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 thread from './thread' | |
| const addOne = x => x + 1; | |
| const double = x => x * 2; | |
| console.log(thread(10, double, addOne)) | |
| // -> 21 (same as addOne(double(10))) |
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 thread(arg, ...funcs) { | |
| return funcs.reduce((prev, func) => func(prev), arg) | |
| } | |
| export default thread |
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, { Component, PropTypes } from 'react' | |
| import { render } from 'react-dom' | |
| import withContext from './with-context' | |
| class Parent extends Component { | |
| static childContextTypes = { | |
| someContext1: PropTypes.object, | |
| someContext2: PropTypes.object | |
| } | |
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, { Component } from 'react' | |
| function withContext(key, type) { | |
| return WrappedComponent => class ContextComponent extends Component { | |
| static contextTypes = { | |
| ...WrappedComponent.contextTypes, | |
| [key]: type | |
| } | |
| render() { |
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, { Component, PropTypes } from 'react' | |
| import { render } from 'react-dom' | |
| class Parent extends Component { | |
| static childContextTypes = { | |
| someContext1: PropTypes.object, | |
| someContext2: PropTypes.object | |
| } | |
| render() { |
NewerOlder