Skip to content

Instantly share code, notes, and snippets.

View STRML's full-sized avatar

Samuel Reed STRML

View GitHub Profile
@STRML
STRML / ResizeSensor.js
Created April 21, 2018 03:49
A resize sensor component for React that doesn't use iframes, objects, or require ResizeObservers.
// @flow
import * as React from 'react';
type Dimensions = {width: number, height: number, ref: ?HTMLElement};
type Props = {
children?: React.Node,
className?: string,
onResize: (dimensions: Dimensions) => any,
};
@STRML
STRML / gist:2117f574726bdf0b8d58
Created June 24, 2015 19:38
Relying on React as an external

The problem:

When writing a React component, you want to target all environments. It is easy to generate a build that will work on the server and browser with Webpack, and as a bonus you can use loaders (like babel-loader for ES6 code).

When you generate this bundle, you should rely on "react" as an external so it isn't included in the bundle. In all environments this is desired behavior so you don't duplicate "react" and break it. This is necessary both because it would make a much larger bundle than necessary, but also because React behaves badly when multiple copies are loaded.

If you do this, you'll end up with a UMD shim like:

(function webpackUniversalModuleDefinition(root, factory) {
@STRML
STRML / zha-lutron-aurora-smart-area-blueprint.yaml
Last active September 12, 2023 19:42 — forked from blizzrdof77/zha-lutron-aurora-smart-area-blueprint.yaml
HASS Blueprint | ZHA - Lutron Aurora Smart Area with Night-Light Dimmer
blueprint:
name: ZHA - Lutron Aurora Dimmer Expanded v1.5
description: Control lights with a Lutron Aurora Dimmer Pressing in the dimmer button will toggle between turning lights on to full brightness, and turning the lights off. Rotating the dimmer will increase and decrease the light brightness. Adjust the sensitivity if updates from the dimmer are being sent too quickly.
domain: automation
input:
remote:
name: Lutron Aurora Dimmer Switch
description: Lutron Aurora Z3-1BRL
selector:
device:
@STRML
STRML / bat-download.js
Last active March 22, 2024 22:58
A simple script for downloading all images for a listing on BringATrailer.com
async function ensureCarouselVisible() {
const imgWrap = document.elementFromPoint(100, 100);
if (!imgWrap.classList.contains('pswp__item')) {
// carousel isn't active, make it so
document.querySelector('.gallery img').click();
while (!document.elementFromPoint(100, 100).classList.contains('pswp__item')) {
await delay(50);
}
}
}