Skip to content

Instantly share code, notes, and snippets.

View ShizukuIchi's full-sized avatar
💗

sh1zuku ShizukuIchi

💗
View GitHub Profile
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);
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"noFallthroughCasesInSwitch": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"esModuleInterop": true,
"noUnusedLocals": true,
"noImplicitAny": true,
"declarationDir": "dist/types",
{
"presets": ["@babel/env", "@babel/typescript"],
"plugins": [
"@babel/proposal-class-properties",
"@babel/proposal-optional-chaining",
"@babel/plugin-proposal-numeric-separator"
]
}
module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:promise/recommended',
'plugin:unicorn/recommended',
'prettier/@typescript-eslint',
'plugin:prettier/recommended',
],
rules: {
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'),
},
// 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 },
// ];
class ExampleWithEffects extends React.Component {
constructor(props) {
super(props);
this.state = {
count: 0
};
this.timer = null;
}
minus = () => {
this.setState(prevState => ({
@ShizukuIchi
ShizukuIchi / useVisibility.js
Last active February 4, 2019 17:33
React hook observes intersection of a node.
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)
})
}
@ShizukuIchi
ShizukuIchi / yt-video-float.js
Last active January 28, 2019 03:37
Float YouTube video by viewport intersection.
// 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 = `
@ShizukuIchi
ShizukuIchi / useResettableTimeout.js
Last active July 5, 2020 01:13
React hook generates a resettable setTimeout and only reset when reset is invoked.
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)