Skip to content

Instantly share code, notes, and snippets.

View adi518's full-sized avatar
🎯
Focusing

Adi adi518

🎯
Focusing
View GitHub Profile
@silicakes
silicakes / extractAllNamedImports.sh
Last active January 21, 2020 15:03
Extracts and returns all named imports from JS import statements i.e the things inside {} when doing: import { foo, bar } from 'some-lib'
# Relies on ripgrep: https://github.com/BurntSushi/ripgrep
#
# Params:
# <library-name> a string with or without quotes
#
# Usage:
# $ ./extracAllNamedImports <library-name>
# Output
# $ ./getNamedImportsByLibrary.sh date-fns
@shilman
shilman / storybook-docs-typescript-walkthrough.md
Last active January 29, 2025 02:47
Storybook Docs Typescript Walkthrough

Storybook Docs w/ CRA & TypeScript

This is a quick-and-dirty walkthrough to set up a fresh project with Storybook Docs, Create React App, and TypeScript. If you're looking for a tutorial, please see Design Systems for Developers, which goes into much more depth but does not use Typescript.

The purpose of this walkthrough is a streamlined Typescript / Docs setup that works out of the box, since there are countless permutations and variables which can influence docs features, such as source code display, docgen, and props tables.

Step 1: Initialize CRA w/ TS

npx create-react-app cra-ts --template typescript
@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]);
}
}
}