This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<script> | |
function round(n) { | |
return Math.round(n * 100)/100 | |
} | |
// parameters for 35mm microfilm rolls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |