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 isEqual = (a, b) => { | |
const aKeys = Object.keys(a); | |
if (aKeys.length !== Object.keys(b).length) { | |
return false; | |
} | |
return aKeys.every( | |
(k) => Object.prototype.hasOwnProperty.call(b, k) | |
&& a[k] === b[k], |
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 addComments(arg, name) { | |
// 当参数前的注释不存在的情况, 加入 webpackChunkName 注释 | |
if (!arg.leadingComments) { | |
arg.leadingComments = [ | |
{ | |
type: 'CommentBlock', | |
value: ` webpackChunkName: '${name}' `, | |
}, | |
] | |
} |
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
'use strict'; | |
// @license http://opensource.org/licenses/MIT | |
// copyright Paul Irish 2015 | |
// Added code by Aaron Levine from: https://gist.github.com/Aldlevine/3f716f447322edbb3671 | |
// Some modifications by Joan Alba Maldonado. | |
// as Safari 6 doesn't have support for NavigationTiming, we use a Date.now() timestamp for relative values | |
// if you want values similar to what you'd get with real perf.now, place this towards the head of the page | |
// but in reality, you're just getting the delta between now() calls, so it's not terribly important where it's placed | |
// Gist: https://gist.github.com/jalbam/cc805ac3cfe14004ecdf323159ecf40e |
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
// https://codepen.io/P3R0/pen/MwgoKv | |
var matrix = (function(){ | |
var init = function() { | |
document.body.style.background = 'black'; | |
var mdr = document.createElement('canvas'); | |
mdr.id = "mdr"; | |
mdr.style.display = 'block'; | |
mdr.style.position = 'fixed'; | |
mdr.style.top = '0'; | |
mdr.style.left = '0'; |
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
/** | |
* useScroll React custom hook | |
* Usage: | |
* const { scrollX, scrollY, scrollDirection } = useScroll(); | |
*/ | |
import { useState, useEffect } from "react"; | |
export function useScroll() { | |
const [lastScrollTop, setLastScrollTop] = useState(0); |
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
let regex; | |
/* matching a specific string */ | |
regex = /hello/; // looks for the string between the forward slashes (case-sensitive)... matches "hello", "hello123", "123hello123", "123hello"; doesn't match for "hell0", "Hello" | |
regex = /hello/i; // looks for the string between the forward slashes (case-insensitive)... matches "hello", "HelLo", "123HelLO" | |
regex = /hello/g; // looks for multiple occurrences of string between the forward slashes... | |
/* wildcards */ | |
regex = /h.llo/; // the "." matches any one character other than a new line character... matches "hello", "hallo" but not "h\nllo" | |
regex = /h.*llo/; // the "*" matches any character(s) zero or more times... matches "hello", "heeeeeello", "hllo", "hwarwareallo" |
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, { Component } from 'react'; | |
import ReactSelect, { components } from 'react-select'; | |
const TextOption = props => ( | |
components.Option && ( | |
<components.Option { ...props }> | |
... | |
</components.Option> | |
) | |
); |
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
componentDidUpdate(prevProps) { | |
for (const index in prevProps) { | |
if (prevProps[index] !== this.props[index]) { | |
console.log(index, this.props[index], '-->', prevProps[index]); | |
} | |
} | |
} |
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
type Color = { r: number, g: number, b: number }; | |
function hexToRgb(hex: string): Color { | |
if (hex.length === 3) { | |
let [hr, hg, hb] = hex.split(''); // ['F', '0', '0'] | |
return hexToRgb(`${hr}${hr}${hg}${hg}${hb}${hb}`); | |
} | |
let [r, g, b] = [0, 2, 4] | |
.map(offset => hex.substring(offset, offset + 2)) // ['FF', '00', '00'] | |
.map(hex => parseInt(hex, 16)); // [255, 0, 0] |
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
/** | |
* Initialize your data structure here. | |
*/ | |
var MyLinkedList = { | |
head: null, | |
length: 0, | |
Node: function (val){ | |
return { |