Skip to content

Instantly share code, notes, and snippets.

View tomasreichmann's full-sized avatar

Tomáš Reichmann tomasreichmann

View GitHub Profile
// retries async check() untill it resolves or time runs out
const retry = async (check = async () => true, timeout = 1000, interval = 100, started = Date.now()) => {
const startTime = Date.now();
return check().catch(
(error) => {
return new Promise((resolve, reject) => {
const resolveTime = Date.now();
if (Date.now() + interval > started + timeout) {
reject(error);
}
({ babel: false})
const set = require('lodash/set');
const get = require('lodash/get');
const unset = require('lodash/unset');
// Mocks ===
const mockPromise = (response = 123, delay = 1000, willFail = false) => {
return new Promise((resolve, reject) => {
({ babel: false })
const range = require('lodash/range');
const attributeItems = {
year: [
'2018', '2017'
],
quarter: [
'Q1', 'Q2', 'Q3', 'Q4'
export const getTreeLeaves = (tree: any, getChildren = (node: any) => node && node.children) => {
const leaves = [];
const nodes = Array.isArray(tree) ? [...tree] : [tree];
let node;
let children;
while (
// tslint:disable-next-line:no-conditional-assignment ban-comma-operator
node = nodes.shift(), children = getChildren(node),
((children && children.length) || (leaves.push(node) && nodes.length))
) {
export const indexOfTreeNode = (
node: any,
tree: any,
matchNode = (nodeA: any, nodeB: any) => (nodeA === nodeB),
getChildren = (node: any) => node && node.children || [],
indexes: number[] = []
): number[] => {
const nodes = Array.isArray(tree) ? [...tree] : [tree];
for (let nodeIndex = 0; nodeIndex < nodes.length; nodeIndex++) {
const currentNode = nodes[nodeIndex];
@tomasreichmann
tomasreichmann / fate-character-sheet.markdown
Last active January 4, 2017 16:15
Fate - Character sheet