Skip to content

Instantly share code, notes, and snippets.

@jasonphillips
jasonphillips / gist:503ca8cd89dcbb4b551d
Last active August 29, 2015 14:16
Web Document Editor Spec: WIP

Web Document Editor Spec (WIP)

Context and Overview

Across a number of our projects in recent years, we have discerned a growing need for an online editor that can span the gulf between less structured or narrative documents and structured or templated forms. Note that these opposed terms are meant to be intelligible to the non-programmer, and interpreted in that light; "document" here does not refer to document-based non-relational storage or any other technical implementation.

Documents, in user perspective

A document refers to a linear body of formatted text, ie. the object one would author in any word-processing application (Word, Google Docs,...). Its contents are at least implicitly and historically organized around the metaphor of a paper document, with the structure of information built around formatting requirements of sections, paragaphs, headers, and so forth. A document is a singular and complete entity, in "one file" so to speak.

@jasonphillips
jasonphillips / getPage.js
Last active August 31, 2015 22:01
Algorithm for finding shortest page for fetching results, given low and high index
/*
* Find smallest page and per_page limit to retrieve a range of results, given low and high
* For non-offset pased paging APIs (where one must send 'per_page' and 'page', rather than offset and limit)
*
* params:
* (integer) low: lowest index to fetch (zero-based)
* (integer) high: highest index to fetch (zero-based)
*
* return value:
* [(integer) per_page, (integer) page]
@jasonphillips
jasonphillips / Post.js
Last active December 14, 2015 03:15
Declarative, Isomorphic Falcor data in React.js
// Main Post component, which initiates data fetching
import React from "react";
import { resolve, context } from "react-resolver";
import PostBody from "./PostBody.js";
import PostMeta from "./PostMeta.js";
/**
* Falcor routes constructed below:
@jasonphillips
jasonphillips / config.js
Last active June 24, 2018 13:10
Jupyter NodeJS: HTML Output (and React Demonstration)
module.exports = {
extensions: {
// clojurescript: require('./ext/clojurescript'),
clojure: require('./build/ext/clojure'),
clojurescript: require('./build/ext/clojurescript'),
coffee: require('./build/ext/coffee'),
babel: require('./build/ext/babel'),
html: require('./build/ext/html')
}
}
@jasonphillips
jasonphillips / responsiveTable.js
Last active January 5, 2018 10:21
React table elements with automatic pivoting to list-style view for mobile
import React from 'react';
/* context helpers from:
* https://gist.github.com/ryanflorence/1e1290571337ebcea1c5a748e8f5b37d
*/
import provideContext from './provideContext';
import withContext from './withContext';
const contextShape = React.PropTypes.shape({
@jasonphillips
jasonphillips / cardboard.glsl
Last active April 6, 2020 06:52
Lens distortion for Dolphin emulator (for VR viewers) as custom shader
/*
[configuration]
[OptionRangeInteger]
GUIName = Distortion amount
OptionName = DISTORTION_FACTOR
MinValue = 1
MaxValue = 10
StepAmount = 1
DefaultValue = 4
@jasonphillips
jasonphillips / JackRabbit.js
Last active April 18, 2017 15:37
RabbitMQ Router (Express-like) for Topic Exchanges
const amqp = require('amqplib');
class JackRabbit {
constructor(url, opts) {
this.channel = this.makeConnection(url, opts);
this.errorCB = (error) => console.log(error);
this.exchanges = {};
this.queued = {};
this.channel.catch((error) => this.errorCB(error));
@jasonphillips
jasonphillips / pick.js
Last active May 11, 2017 16:08
Pick "One"-Liner
const pick = (obj, props) => Array.prototype.reduce.call(
props,
(built, prop) => (
Object.prototype.hasOwnProperty.call(obj, prop)
? Object.assign({}, built, {[prop]: obj[prop]})
: built
), {}
)
@jasonphillips
jasonphillips / .babelrc
Last active October 30, 2017 19:01
babel error with Set() and spread syntax, when using "loose":true
{
"presets": [["env", {
"loose": true
}
]]
}
@jasonphillips
jasonphillips / omit.js
Created November 9, 2017 17:24
omit "One"-liner
const omit = (obj, omitProps) => Object.keys(obj)
.filter(key => omitProps.indexOf(key)===-1)
.reduce((returnObj, key) => ({ ...returnObj, [key]: obj[key] }), {})