Skip to content

Instantly share code, notes, and snippets.

View malectro's full-sized avatar

Kyle Warren malectro

View GitHub Profile
@malectro
malectro / forEachPromise.js
Created April 8, 2015 19:45
Executes an array of promises in sequence. Useful when all promises access the same lock and could possibly time out if run in parallel (as in a database migration).
var forEachPromise = function (array, callback) {
var i = 0;
function iterate() {
if (i < array.length) {
callback(arrray[i]).then(function () {
i++;
iterate();
});
}
@malectro
malectro / textEditorModel.json
Last active August 29, 2015 14:19
Proposed text editor data model for Tale
{
"styles": [
{"type": "underline", "start": 12, "end": 19},
{"type": "bold", "start": 27, "end": 31}
],
"annotations": [
{"nodeId": 87, "start": 27, "end": 31}
],
"links": [],
"offsetX": 10,
@malectro
malectro / JSON-safeStringify.js
Last active August 29, 2015 14:20
Escapes the HTML of all strings attached to a JSON encodable object before stringifying it. Does not detect cycles.
var _ = require('underscore');
var escape = require('escape-html');
function recur(item) {
var ret;
if (_.isObject(item) || _.isArray(item)) {
ret = new item.constructor();
_.each(item, function (val, key) {
ret[key] = recur(val);
});
@malectro
malectro / JSON-safeStringify2.js
Created May 6, 2015 22:55
Scratch pad for my safe-stringify method.
var _ = require('underscore');
var escape = require('escape-html');
function ord(string) {
return string;
//return '' + string.charCodeAt();
}
function pad(string, zeros) {
var count = zeros - string.length;
@malectro
malectro / madeby-agenda.md
Last active February 24, 2016 22:50
MadeBy Architecture Agenda

Agenda

The Goal

We'd like to unify our Router on both client and server and do away with the dispatcher.

The Options

Choose a Framework (like Redux)

@malectro
malectro / RefExamples.jsx
Created March 14, 2016 23:46
Example of how `wrappedRef` would relate to `ref` in the case of FluxComponent-wrapped components.
import React, {Component} form 'react';
import MyComponent from 'my-component.jsx'; // wrapped by FluxComponent
class ParentComponent extends Component {
componentDidMount() {
assert(this.fluxComponent.getWrapped() === this.childEl);
}
render() {
return <MyComponent ref={el => this.fluxComponent = el} wrappedRef={el => this.childEl = el} />
}
const key = generator => actionCreator => {
actionCreator.keyGenerator = generator;
return actionCreator;
};
@require_auth
@require_admin
def get(self):
args = self.get_parser().parse_args()
return User.get_by_id(args.id)
export const key = keyFunc => (
wrappedFunc => {
wrappedFunc.KEY = keyFunc;
return wrappedFunc;
};
);
const getUser = (userId) => (dispatch, getState) => {
// create a unique key for this request
const key = `@@getUser:${userId}`;
// if the action creator has already fired off a request, return it
const fetching = getState().fetching[key];
if (fetching) {
return fetching;
}