Skip to content

Instantly share code, notes, and snippets.

const create = sessionUser => data => Promise.try(() => transaction(model, async (modelTransaction) => {
const { CAN_CREATE_ORGANIZATIONS } = getPermissions(sessionUser.permissions);
const { userId } = sessionUser;
const { avatar, ...orgData } = data;
if (!CAN_CREATE_ORGANIZATIONS) {
throw Unauthorized({ message: 'Sie haben nicht das Recht Organisationen zu erstellen' });
}
const insert = params => modelTransaction.query()
let estate;
let signed;
let watches;
function getImagesAndServePages() {
estate = require('fs').readdirSync('./public/imgs/estate');
signed = require('fs').readdirSync('./public/imgs/signed');
watches = require('fs').readdirSync('./public/imgs/watches');
const get = (array, currentKey, direction) => {
const k = currentKey ? currentKey : array[0];
const delta = direction == 'inc' ? 1 : -1
const index = array.indexOf(k);
const nextIndex = (index + delta + array.length) % array.length;
console.log(array[nextIndex]);
};
import React, { useState } from 'react';
import styled from '@emotion/styled';
import { Col, Row } from './Flex';
const splitBasis = (percent) => {
const SCALE = 10000;
const p = Math.floor(percent * SCALE);
const shared = { flexShrink: 1 };
return {
a: { flexGrow: String(p), ...shared },
export async function json_to_sheet(...args) {
const XLSX = await import('xlsx')
return XLSX.utils.json_to_sheet(...args);
}
@brigand
brigand / .js
Last active June 2, 2021 03:16
function on(eventTarget, eventType, handler) {
// Distinct but identical event handler
const handler2 = (event) => handler(event);
eventTarget.addEventListener(eventType, hander2);
const unsub = () => {
eventTarget.removeEventListener(eventType, hander2);
};
return unsub;
@brigand
brigand / promiseMap.js
Created February 17, 2021 04:18
A slow async/await version of promiseMap
async function promiseMap(array, mapper, concurrency) {
const promises = [];
const results = Array.from({ length: array.length });
const drainOne = async () => {
const [pj, { index, resolved, rejected }] = await Promise.race(promises.map((p, pi) => p.then((v) => [pi, v])));
promises.splice(pj, 1);
if (resolved) {
results[index] = resolved[0];
@brigand
brigand / .js
Last active September 1, 2020 21:22
domOn, domOnce
function domOn(subject, eventName, handler, options = false) {
// This function is useless except in the case domOn(x, 'e', f); domOn(x, 'e', f); is run
// where cleanup can remove the distinct 'inner' function from each call, instead of both 'f' listeners.
function inner(event) {
return handler.call(this, event);
}
subject.addEventListener(eventName, inner, options);
const cleanup = () => subject.removeEventListener(eventName, inner, options);
@brigand
brigand / .js
Created December 17, 2019 23:35
Concept for flexible pattern matching in ES6
import match, { matches, Instance, TypeOf, PropEq, Eq, Check, Index } from '@brigand/unnamed-match-thing';
// Simple matching.
// Note that this is an object literal, so all of these need to
// return something with a toString, and match needs to convert that
// back to the pattern. This implies we need to store Eq('production') in
// module level storage and somehow avoid leaking memory for every pattern ever used.
// Something every toString called here allocates the pattern, and when match() is called
// it can claim all patterns before it (since the toString calls run before match()), removing
// them from the global storage, and then execute the patterns.
@brigand
brigand / README.md
Last active November 14, 2019 17:48
A gist npm package for using @types/stripe-v3

To install, add this gist as a dependency, and @types/stripe-v3 as a dev dependency.

yarn add --dev @types/stripe-v3
yarn add https://gist.github.com/955eafd92692f4ba54d50d447cef6327.git

Or with npm