Skip to content

Instantly share code, notes, and snippets.

HOSTNAME=einar.local
PORT=5555
HOST=http://$HOSTNAME:$PORT
type Props<
T extends React.FunctionComponent,
P extends keyof Parameters<T>[0]
> = Pick<Parameters<T>[0], P>
@einarlove
einarlove / Typescript Props utility function.ts
Last active April 28, 2021 08:26
Pick the props you want from another react function
type Props<
T extends React.FunctionComponent,
P extends keyof Parameters<T>[0]
> = Pick<Parameters<T>[0], P>
@einarlove
einarlove / Root.js
Created March 4, 2019 08:51
convert <Transition> to useTranstion (there is some bugs here)
import React from 'react'
import { useTransition, config, animated } from 'react-spring'
import Layout from './Layout'
import SiteHeader from './SiteHeader'
import SiteFooter from './SiteFooter'
const isBrowser = typeof window !== 'undefined'
const Root = ({ children, ...props }) => {
const headerRef = React.useRef()
@einarlove
einarlove / Untitled-1
Created December 17, 2018 14:53
Access token
import React from 'react'
let globalZIndex = 1000
const useOverlay = ({ onClickOutside, ref }) => {
// Used for detecting touch to not fire onClickOutside twice
const isTouchRef = React.useRef(false)
// Create a z-index that is overlaying all other layers with 1
const zIndex = React.useMemo(() => globalZIndex += 1, [])
@einarlove
einarlove / cloudSettings
Last active May 4, 2018 08:22
Subliminal : Visual Studio Code Settings Sync Gist
{"lastUpload":"2018-05-04T08:22:20.231Z","extensionVersion":"v2.9.2"}
@einarlove
einarlove / tmp.js
Last active March 14, 2017 10:29
React firebase deep subscriptions sketches
const createQuery = query => ({
[REACT_FIREBASE_QUERY_SYMBOL]: true,
query,
})
export default connect(props => ({
pathSubscription: 'path/to/data',
deepSubscription: {
a: {
aa: 'path/to/data/a/aa',
@einarlove
einarlove / lightenDarkenColor.js
Created February 15, 2017 12:29
Takes a hex color and luminosity adjustment and outputs new color
/* eslint-disable no-bitwise */
export default (inputColor, amt) => {
let usePound = false
let color = inputColor
if (color[0] === '#') {
color = color.slice(1)
usePound = true
}
import path from 'path'
import fs from 'fs'
export default root => {
const stories = []
const loopFiles = context => {
fs.readdirSync(context).forEach(name => {
const filepath = path.join(context, name)
if (fs.lstatSync(filepath).isDirectory()) {
@einarlove
einarlove / gist:62d97aefdd2fc0be9ab322bd21f29fc2
Created December 13, 2016 11:46
Hide chrome extensions and socket files in Network panel in Google Chrome
-scheme:chrome-extension -sockjs-node