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
class PriorityQueue { | |
constructor(compare = (a, z) => a - z) { | |
this.data = []; | |
this.compare = compare; | |
} | |
get length() { | |
return this.data.length; | |
} | |
push(item) { | |
this.data.push(item); |
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
{ | |
"compilerOptions": { | |
"allowSyntheticDefaultImports": true, | |
"noFallthroughCasesInSwitch": true, | |
"noUnusedParameters": true, | |
"noImplicitReturns": true, | |
"esModuleInterop": true, | |
"noUnusedLocals": true, | |
"noImplicitAny": true, | |
"declarationDir": "dist/types", |
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
Show hidden characters
{ | |
"presets": ["@babel/env", "@babel/typescript"], | |
"plugins": [ | |
"@babel/proposal-class-properties", | |
"@babel/proposal-optional-chaining", | |
"@babel/plugin-proposal-numeric-separator" | |
] | |
} |
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
module.exports = { | |
parser: '@typescript-eslint/parser', | |
extends: [ | |
'plugin:@typescript-eslint/recommended', | |
'plugin:promise/recommended', | |
'plugin:unicorn/recommended', | |
'prettier/@typescript-eslint', | |
'plugin:prettier/recommended', | |
], | |
rules: { |
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
const path = require('path'); | |
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); | |
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
module.exports = { | |
entry: path.resolve(__dirname, 'src/index.ts'), | |
output: { | |
filename: 'bundle.js', | |
path: path.resolve(__dirname, 'dist'), | |
}, |
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
// specify a root element to insert video node | |
// such as a div | |
// videos in playlist will turn into a single video | |
// const playlist = [ | |
// { src: 'bunny.mp4', start: 5, end: 20 }, | |
// { src: 'bunny.mp4', start: 15, end: 18 }, | |
// { src: 'bunny.mp4', start: 22, end: 30 }, | |
// ]; |
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
class ExampleWithEffects extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
count: 0 | |
}; | |
this.timer = null; | |
} | |
minus = () => { | |
this.setState(prevState => ({ |
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, useEffect } from 'react'; | |
require('intersection-observer'); | |
function useVisibility(ref , ratio = 0.1) { | |
const [visible, setVisible] = useState(false); | |
const callback = entries => { | |
entries.forEach(entry => { | |
setVisible(entry.intersectionRatio >= ratio) | |
}) | |
} |
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
// Base on https://gist.github.com/realdennis/b254ce2ac0efd54e602a6b1bb64c643a#file-float-youtube-video-using-monkey-js | |
// Intersection API version | |
// Last edit: 01/28/2019 | |
(() => { | |
const float_video = () => { | |
if (window._floatIsOpen === true) return; | |
window._floatIsOpen = true; | |
const style = document.createElement('style'); | |
style.innerHTML = ` |
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, useEffect } from 'react' | |
const useResettableTimeout = (ms = 0, fn = () => {}, args = []) => { | |
const [timeout, setTimeoutVal] = useState(); | |
function start() { | |
setTimeoutVal(setTimeout(fn.bind(null, args), ms)); | |
return clear; | |
} | |
function clear() { | |
clearTimeout(timeout) |
NewerOlder