Skip to content

Instantly share code, notes, and snippets.


Samuel Reed STRML

View GitHub Profile
STRML / bat-download.js
Created Jul 13, 2020
A simple script for downloading all images for a listing on
View bat-download.js
async function ensureCarouselVisible() {
const imgWrap = document.elementFromPoint(100, 100);
if (!imgWrap.classList.contains('pswp__item')) {
// carousel isn't active, make it so
while (!document.elementFromPoint(100, 100).classList.contains('pswp__item')) {
await delay(50);
STRML / ResizeSensor.js
Created Apr 21, 2018
A resize sensor component for React that doesn't use iframes, objects, or require ResizeObservers.
View ResizeSensor.js
// @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,
View WebpackStableChunkHash.js
// @flow
const crypto = require('crypto');
module.exports = WebpackStableChunkHash;
function WebpackStableChunkHash() {}
WebpackStableChunkHash.prototype.apply = function(compiler) {
// For a while, webpack has had issues with [chunkhash] being unstable and not reflecting the actual
STRML / gist:2117f574726bdf0b8d58
Created Jun 24, 2015
Relying on React as an external
View gist:2117f574726bdf0b8d58

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 / overrideSlack.lua
Created Jul 10, 2015
Lua snippet for Hammerspoon to bind ctrl-tab and ctrl-shift-tab back to switching channels.
View overrideSlack.lua
-- Fix Slack's channel switching.
-- This rebinds ctrl-tab and ctrl-shift-tab back to switching channels,
-- which is what they did before the Teams update.
-- Slack only provides alt+up/down for switching channels, (and the cmd-t switcher,
-- which is buggy) and have 3 (!) shortcuts for switching teams, most of which are
-- the usual tab switching shortcuts in every other app.
local ctrlTab ={"ctrl"}, "tab", function()
STRML / gist:3154212
Created Jul 21, 2012
Variable declaration hoisting
View gist:3154212
(function foo(){bar = 10; var bar = 20;}());
alert(bar) // ReferenceError: bar is not defined
(function foo(){bar = 10;}());
alert(bar) // 10
Created Jun 30, 2012
A few useful files for running a nodejs server. I keep update-project.js in /root so when I ssh in I can just run it. my-project.conf runs the project as the user 'www-data', and so makes sure the project folder is readable/writable.
chown -R www-data:root $T
find $T -type d ! -perm 770 -print -exec chmod 770 {} \;
find $T -type f ! -perm 660 ! -name "*.sh" -print -exec chmod 660 {} \;
find $T -type f ! -perm 770 -name "*.sh" -print -exec chmod 770 {} \;
STRML / dumpExtLoader.js
Created May 10, 2012
Simple PhantomJS file that dumps the contents of Ext.Loader
View dumpExtLoader.js
var page = require('webpage').create(),
t, address;
if (phantom.args.length === 0) {
console.log('Usage: dumpExtLoader.js <some URL>');
} else {
page.onConsoleMessage = function (msg) {
STRML / phantomjs-jsb.js
Created May 10, 2012
Working phantomjs-jsb.js for use with ExtJS4 & (experimentally) Sencha Touch 2
View phantomjs-jsb.js
// This belongs in %SDK%/compat/scripts/
(function() {
var defaultJsb3Object = {
"projectName": "Project Name",
"licenseText": "Copyright(c) 2012 Company Name",
"builds": [
"name": "All Classes",
"target": "all-classes.js",
STRML / index.js
Created Jul 30, 2015
requirebin sketch
View index.js
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var React = require('react');
var App = React.createClass({
render: function() {
return (
React.createElement("div", {className: "example"},
React.createElement("h1", null, "Example Component"),
React.createElement("ul", null, React.createElement("li", null, "One item"), React.createElement("li", null, "Another item"))