Skip to content

Instantly share code, notes, and snippets.

View bradennapier's full-sized avatar

Braden Napier bradennapier

View GitHub Profile
@bradennapier
bradennapier / bot-bot.js
Last active March 28, 2019 17:55
Example of a Slack API flow using AWS, SQS, and a nice automated handling of commands
/* @flow */
import type { Bot$Interface } from 'types/bot';
import slack from 'lib/slack';
import * as utils from './utils';
function handleDeferredExecution(result) {
if (bot.state.isWorker) {
@bradennapier
bradennapier / notification.saga.js
Last active February 26, 2019 21:12
Saga Defer Example
import _ from 'lodash';
import {
take,
call,
put,
fork,
spawn,
delay,
cancel
} from 'redux-saga/effects';
const ms = delay => new Promise(resolve => setTimeout(resolve, delay));
async function* iterate() {
let i = 0;
try {
const done = false;
while (!done) {
try {
await ms(1000);
i += 1;

redis-rate-limiter

This document specifies a concept for a multi-level rate limiting procedure that can be used to implement rate limiting of many kinds. It should be considered a work in progress!

This document describes the schema that should be utilized.

Limiting Keys

Each user shall be assigned a multi-level set of limiting that must pass for any request to continue.

import { getDashboardWidgetSchema } from './utils/widgetSchema'
const getWidgetDefaultSchema = widgetName => {
const schema = getDashboardWidgetSchema(widgetName)
if ( ! schema ) {
throw new Error(`[Grid]: Widget Not Known: ${widgetName}`)
}
return schema
}
import { Process } from 'redux-saga-process';
import { call, put, select, fork } from 'redux-saga/effects';
import { createTaskManager } from 'saga-task-manager';
import appConfig from 'utils/config';
import processLoadsWithScope from './config/processLoadsWithScope';
import processReducer from './config/processReducer';
import processSelectors from './config/processSelectors';
// Any quick tests that we want to run `yarn try`
import { performance } from 'perf_hooks';
import createState from './src/index';
const state = createState({
config: { mid: 'my-module' },
// Hooks allow simple hooking into the lifecycle of the state
hooks: {
// Before action is dispatched, may return an action with new properties
before: [action => console.group('DISPATCHING: ', action)],
/**
* SetMap provides an extended Map which mixes in some extra commands. The idea is
* to use this when you need to manage a Map of Sets or Maps. It provides various
* prototype methods that make it easy to build these data structures.
*
* Map<any, Set<any> | Map<any, any> | any>
* @extends {Map}
*/
export default class SetMap extends Map {
add(key, ...values) {
/* @flow */
// TODO : Remove dependency on lodash
import _ from 'lodash';
// const r = objectDifference(
// {
// one: 'two',
// three: 'five',
// five: ['six', { seven: 'eight' }],
// six: ['seven', { seven: 'eight' }],
import { PROXY_SYMBOL } from './src2/context';
const rootDescriptor = { changed: new Map(), path: [] };
const ProxyDescriptors = new WeakMap();
const proxyTraps = {
get(target, prop, receiver) {
if (prop === PROXY_SYMBOL) return target[prop];
if (typeof prop === 'symbol') return Reflect.get(target, prop, receiver);