Skip to content

Instantly share code, notes, and snippets.

@corysimmons
corysimmons / useHotkey.ts
Last active January 28, 2023 14:08
A simple hook for adding hotkeys to your React app. Piggybacks on keyboardJS for a nicer interface.
import keyboardJS from 'keyboardjs'
import { useEffect } from 'react'
export default function useHotkey(key: string | string[], callback: () => void) {
useEffect(() => {
keyboardJS.bind(key, callback)
return () => keyboardJS.unbind(key, callback)
}, [key, callback])
}
// monster image to pic.png
const fs = require('fs')
// trimmed the `data:image/png;base64,` off the front of it
const x = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAQoAAAFmCAMAAACiIyTaAAABv1BMVEUAAAB5S0dJSkpISkpLTU3pSzzoTD3oSzzoTD3kSjvoTD1GRUbeSDpFREVCQULpSzzoTD3c3d3gSTrg4uDm5uZFRETbRznoTD3oTD1JR0iXlYXaRzncRzhBQUDnSjtNS0zUzsdnZmVLSEpMSEoyNjPm5eSZmYfm6ekzNTOloI42ODbm6Oiioo/h4eEzODbm5+eop5SiopCiopDl396hloaDg3ToTD3m5uZMS03///9RTlAAAADy8vIgICA2NzY4OzYPM0fa29qgoI7/zMnj4+PW19VGRkbqPi7v7/D6+vr09fXyTj4rKSvhSTo/Pj/oSDnlMyLsNCI0MTP0///tTT7ZRjizOi+6PDDmLRyenZ7oKRfExMT/TzvobGEVFBWGhYUAGjLW8/ToXVADLUZ8e33/2tfRRTdWVFTFQDT1u7aSkZIADib+5eFwcHHW+/z70tDwkIesPTPW6+teXV2xsbG7u7vY4+Lre3DMzM2qp6jilIxsPT7lg3kdO07m/f4AJjuwsJzftK/fpZ7woJjoVUZBWGj1zMdTaXfcvrrzq6Tby8f+8u8wSlYZNDaQRUKfr7d9j5lpf4vx5ePMsLF/o64s+PNlAAAANnRSTlMAC1IoljoZWm2yloPRGWiJfdjEEk037Esq7Pn24EKjpiX+z7rJNNWB5pGxZ1m2mZY/gXOlr43C+dBMAAAmkklEQVR42uzay86bMBAF4MnCV1kCeQFIRn6M8xZe+v1fpVECdtPSy5822Bi+JcujmfEApl3IIRhBFyIJ3Em6UMTDSKfHsOB0dhILQ2fX4+4aF0tVXC3yJJB4OrcJV1msIhJN52avslh
.auto-grid {
grid-template-columns: repeat( auto-fit, minmax(250px, 1fr) );
}
@corysimmons
corysimmons / props-in-styled-components.js
Created June 15, 2020 15:01
Cleaner props in styled-components from Sara Vieira's Twitter thread https://twitter.com/Saeris/status/1262441528078688256
import styled, { css } from 'styled-components'
const Styles = styled.div(({ someProp }) => css`
font-size: ${someProp ? '10px' : '20px'};
`)
import { useState, useLayoutEffect } from 'react'
const specialKeys = [
`Shift`,
`CapsLock`,
`Meta`,
`Control`,
`Alt`,
`Tab`,
`Backspace`,

FakeUP doesn't track or use any information about you for anything.

@corysimmons
corysimmons / vscode_shortcuts.md
Created November 1, 2019 14:53 — forked from bradtraversy/vscode_shortcuts.md
Helpful shortcuts for VSCode

VSCode Shortcuts

List of helpful shortcuts for faster coding

Official List of all commands

Open/View

@corysimmons
corysimmons / Modal.css.js
Last active June 8, 2019 15:00
Scrollable react-modal's within Next.js
import { css } from '@emotion/core'
import styled from '@emotion/styled'
import ReactModal from 'react-modal'
ReactModal.setAppElement('#__next')
ReactModal.defaultStyles = {}
export const globalStyles = css`
.ReactModal__Html--open,
.ReactModal__Body--open {
@corysimmons
corysimmons / eslint-sort-imports.json
Last active June 8, 2019 14:45
With ESLint, eslint-plugin-autofix, and eslint-plugin-import you can replace VSCode's buggy `organizeImports` setting with ESLint and organize imports for an entire project in one CLI `$ yarn lint --fix`
{
"scripts": {
"lint": "eslint '{,!(node_modules)/**/}*.js'"
},
"eslintConfig": {
"plugins": [
"autofix",
"import"
],
"rules": {
const ContentVideo = ({ videoId, on }) => {
const player = useRef();
useEffect(() => {
player.current = new YTPlayer('#' + videoId);
player.current.load(videoId);
}, []);
useEffect(() => {
if (!on) {