Skip to content

Instantly share code, notes, and snippets.

@andrewluetgers
andrewluetgers / App.js
Last active March 10, 2021 17:39
Image loading with react-konva
import React, { Component } from 'react';
import DevTools from 'mobx-react-devtools';
import Konva from 'konva';
import {Stage, Layer, Rect, Line, Image} from 'react-konva';
import Img from './Img/Img.js';
import './App.css';
import pg from '../assets/scribo-doc-dia-00008061.json'
console.log(pg);
function mapper(data, setType) {
let keys = Object.keys(data),
ret = data.concat ? [] : {};
console.log("keys", keys);
while (keys.length) {
let key = keys.shift(),
obj = data[key];
@andrewluetgers
andrewluetgers / LambdaDDBChangeFeedTrigger.js
Last active March 2, 2017 17:30
DynamoDB Simple Change-Feed Lambda Trigger
/**
* @license
* Lodash (Custom Build) lodash.com/license | Underscore.js 1.8.3 underscorejs.org/LICENSE
* Build: `lodash include="isObject,isEqual"`
*/
;(function(){function t(t,e){for(var r=-1,n=null==t?0:t.length,o=0,a=[];++r<n;){var i=t[r];e(i,r,t)&&(a[o++]=i)}return a}function e(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(e(t[r],r,t))return true;return false}function r(t){return function(e){return t(e)}}function n(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r}function o(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r}function a(){}function i(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){
var n=t[e];this.set(n[0],n[1])}}function c(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function s(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function u(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new s;++e<r;)this.add(t[e])}function f(t){this.size=(th
// work in progress
// problem: you push a change to the database now your whole app needs to also update to that change
// one solution is to fetch the data back from the server just after it has changed
// this assumes acid updates, elastic search is not acid, nor are many nosql databases
// this is an impossible solution without acid
// the alternative is to retain an in memory copy of the data and update it optimistically
// if there is an error from the server roll back the in memory change
// if there is no error the update is already in memory, barring any server side transformations not accounted for
// to make this work you need to keep each object in memory over time,
@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)}
}
@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 / 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 / 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++) {
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 / 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]