Skip to content

Instantly share code, notes, and snippets.

View adi518's full-sized avatar
🌴
On vacation

Adi adi518

🌴
On vacation
View GitHub Profile
@abuduba
abuduba / hotkeys.js
Last active October 12, 2022 03:39
Hotkey library
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],
function addComments(arg, name) {
// 当参数前的注释不存在的情况, 加入 webpackChunkName 注释
if (!arg.leadingComments) {
arg.leadingComments = [
{
type: 'CommentBlock',
value: ` webpackChunkName: '${name}' `,
},
]
}
@jalbam
jalbam / performance.now-polyfill.js
Last active November 27, 2022 06:27
window.performance.now polyfill
'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
@danielt69
danielt69 / matrixDigitalRain.js
Last active April 2, 2020 11:01
Matrix rain animation using HTML5 canvas and javascript
// 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';
@joshuacerbito
joshuacerbito / useScroll.js
Last active January 8, 2024 13:44
Custom React hook for listening to scroll events
/**
* useScroll React custom hook
* Usage:
* const { scrollX, scrollY, scrollDirection } = useScroll();
*/
import { useState, useEffect } from "react";
export function useScroll() {
const [lastScrollTop, setLastScrollTop] = useState(0);
@sarthology
sarthology / regexCheatsheet.js
Created January 10, 2019 07:54
A regex cheatsheet 👩🏻‍💻 (by Catherine)
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"
@MikaelCarpenter
MikaelCarpenter / react-select-data-attributes.jsx
Created December 14, 2018 19:09
Solution for adding data attributes to a react-select component by passing in "custom components" where you've manipulated the innerProps prop
import React, { Component } from 'react';
import ReactSelect, { components } from 'react-select';
const TextOption = props => (
components.Option && (
<components.Option { ...props }>
...
</components.Option>
)
);
@iliran11
iliran11 / gist:807bb4b434853680213818d598e7c5ac
Created October 20, 2018 14:50
Check which prop has changed that caused re-render
componentDidUpdate(prevProps) {
for (const index in prevProps) {
if (prevProps[index] !== this.props[index]) {
console.log(index, this.props[index], '-->', prevProps[index]);
}
}
}
@imgsrc
imgsrc / colorConverter.ts
Created August 12, 2018 16:35
converter hex to rgb / rgb to hex
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]
@kvedantmahajan
kvedantmahajan / linked_list_OLOO_style.js
Last active December 4, 2018 16:14
Implementation of Linked list in Javascript using OLOO ( Object linked with another object ) style of coding i.e. no "new" keyword and sugar coated classes
/**
* Initialize your data structure here.
*/
var MyLinkedList = {
head: null,
length: 0,
Node: function (val){
return {