Skip to content

Instantly share code, notes, and snippets.

View andrewluetgers's full-sized avatar

Github Notification andrewluetgers

View GitHub Profile
<div css={styles}>
<div class="panel flex-container">
<div class="header">fixed</div>
<div class="content flex-container non-scrollable">
<div class="flex-container non-scrollable">
expands..
<div class="list scrollable">
scrolls...
@andrewluetgers
andrewluetgers / RuleBuilder.stories.jsx
Last active December 18, 2021 19:48
A pile of code that captures the core of a system to mock out apis that can be used in msw or in express. A standard crud api generator is implemented for the client that uses reactQuery.
import {mswMocks as ruleMocks, getRulesBody} from '../../../api/rules/rulesMocks'
import {mswMocks as rulesetMocks, getRulesetsBody} from '../../../api/rulesets/rulesetsMocks'
import {mswMocks as channelMocks} from '../../../api/channels/channelMocks'
import RuleBuilder from './RuleBuilder'
// -------------------------------------- setup ----------------------------------------
let items = getRulesetsBody,
item = items[0],
{name, uuid} = item || {},
@andrewluetgers
andrewluetgers / PresentInteraction.jsx
Last active January 23, 2024 19:17
Presentation mode for Storybook play functions
import {useEffect} from 'react'
import {fireEvent, within} from '@storybook/testing-library'
import userEvent from '@testing-library/user-event'
export const presentInteraction = storyFn => {
return (
<div>
<PresentInteraction/>
{storyFn()}
@andrewluetgers
andrewluetgers / useThisState.js
Created October 16, 2020 18:40
Works like useState but for Class Components using this.setState
function useThisState(key, component, initialState) {
let set = (val) => component.setState({[key]: val}),
initial = !(key in component.state)
if (initial) {
set(initialState)
}
let retVal = initial ? initialState : component.state[key]
import {every, filter} from 'lodash'
export const numericComparisons = {
lte: (a, b) => a <= b,
lt: (a, b) => a < b,
gt: (a, b) => a > b,
gte: (a, b) => a >= b,
eq: (a, b) => a === b,
neq: (a, b) => a !== b
@andrewluetgers
andrewluetgers / auc.js
Created April 2, 2019 14:51
integration, auc, interpolation fns
// get n linear steps between point{x, y} a and b
function interPoints(a, b, n) {
let int = (t) => ({
x: a.x * (1 - t) + b.x * t,
y: a.y * (1 - t) + b.y * t
}),
step = 1/(n+1),
ret = [];
for (let i=0; i<n; i++) {
@andrewluetgers
andrewluetgers / selectParent.js
Last active February 28, 2019 16:08
Select a parent node that matches a query selector.
export default function selectParent(el, selector) {
let parent = null,
p = el.parentNode,
pp = p.parentNode,
sel = pp ? pp.querySelector(selector) : null,
done = !pp || sel === p;
console.log(selector, el)
return done ? sel : selectParent(p, selector);
}
@andrewluetgers
andrewluetgers / SpoolMath.html
Created February 12, 2019 17:15
Reel to reel demo
<html>
<body>
<script>
function round(n) {
return Math.round(n * 100)/100
}
// parameters for 35mm microfilm rolls
@andrewluetgers
andrewluetgers / activate.js
Created December 14, 2017 16:39
memoized debounce
// debounce function if arguments do not change
// https://github.com/lodash/lodash/issues/2403#issuecomment-290760787
function activate(func, wait=0, options={}) {
var mem = _.memoize(function() {
return _.debounce(func, wait, options)
}, options.resolver);
return function(){mem.apply(this, arguments).apply(this, arguments)}
}