Skip to content

Instantly share code, notes, and snippets.

View drwpow's full-sized avatar

Drew Powers drwpow

View GitHub Profile
@drwpow
drwpow / README.md
Last active December 10, 2022 03:19
CSS Custom Properties in React with TypeScript

CSS Custom Properties in React with TypeScript

Ever encounter the following error when trying to do the following?

<div style={{ '--height': '32px' }}>
              ~~~~~~~~~~~~~~~~~~
// Type '{ "--height": string; }' is not assignable to type 'Properties<string | number, string & {}>'.
//   Object literal may only specify known properties, and '"--height"' does not exist in type 'Properties<string | number, string & {}>'.
@drwpow
drwpow / README.md
Last active March 4, 2022 16:33
List files in Node that have changed between branch and main

Git diff files in Node

Useful for when you want to run a CI job only on files that have changed. Usage:

import { getChangedFiles } from './git-diff.js';

getChangedFiles('main');             // get list of diffs from "main"
getChangedFiles('[current branch]'); // get list of diffs from previous commit
@drwpow
drwpow / README.md
Last active November 15, 2021 01:04
Count unique HSL colors

Count unique HSL colors

Convert every possible RGB value to HSL to map the overlapping color space.

Setup

  1. Save this locally
  2. Install the color-convert package
  3. Run with node (node map-hsl.js)
@drwpow
drwpow / README.md
Last active November 9, 2021 19:18

👾 Konami Code (browser-only)

Tiny, lightweight, cross-browser compatible. Only 461 bytes minified!

Instructions

Copy & paste into a `

@drwpow
drwpow / bookmarklet.js
Last active October 31, 2021 02:17
Export Medium to Markdown
javascript:(()=>{function a(a){let b=a.cloneNode(!0);return b.querySelectorAll("a,b,br,code,em,i,mark,p,span,strong,strike").forEach(a=>{switch(a.tagName){case"A":{a.replaceWith(document.createTextNode("["),...a.childNodes,document.createTextNode("]"),document.createTextNode("("),document.createTextNode(a.getAttribute("href")),document.createTextNode(")"));break}case"B":case"STRONG":{a.replaceWith(document.createTextNode("**"),...a.childNodes,document.createTextNode("**"));break}case"BR":{a.replaceWith(document.createTextNode("\n"));break}case"EM":case"I":{a.replaceWith(document.createTextNode("_"),...a.childNodes,document.createTextNode("_"));break}case"CODE":{a.replaceWith(document.createTextNode("`"),...a.childNodes,document.createTextNode("`"));break}case"STRIKE":{a.replaceWith(document.createTextNode("~~"),...a.childNodes,document.createTextNode("~~"));break}case"MARK":case"SPAN":{a.replaceWith(...a.childNodes);break}case"P":{a.replaceWith(...a.childNodes,document.createTextNode("\n\n"));break}}}),b.inne
@drwpow
drwpow / quotes.md
Last active February 7, 2023 21:41
quotes.md

Art

The woods would be very silent if no birds sang except those who sang best.

Henry Van Dyke

Love

I do not trust people who don’t love themselves and yet tell me “I love you.” There is an African saying which is: “Be careful when a naked person offers you a shirt.”

@drwpow
drwpow / fetch-abort-retry.js
Last active August 30, 2023 14:59
Fetch retry with timeout
/**
* fetch() with retries
* @param {string} url URL to fetch
* @param {object} options All options required
* @param {number} options.timeout Max timeout, in milliseconds (default: 5000)
* @param {retries} options.retries Max number of retries (default: 2)
*/
async function fetchWithRetry(url, { timeout, retries } = { timeout: 5000, retries: 2 }) {
let data;
let controller;
@drwpow
drwpow / adjectives.json
Last active January 30, 2021 00:45
List of English Words
[
"abdominal",
"abrupt",
"absolute",
"academic",
"acceptable",
"acclaimed",
"accomodating",
"accountable",
"accurate",
@drwpow
drwpow / google-storage-test.js
Last active January 16, 2021 03:22
Google Cloud Storage availability test: generate many random files, upload, then download
const crypto = require("crypto");
const fs = require("fs");
const path = require("path");
const { Storage } = require("@google-cloud/storage");
const mkdirp = require("mkdirp");
// settings
const FILES_TO_GENERATE = 1000;
const KEY_FILE = "/my/google/service/key.json";