Skip to content

Instantly share code, notes, and snippets.

View unscriptable's full-sized avatar
🏔️

John Hann unscriptable

🏔️
View GitHub Profile
@unscriptable
unscriptable / Group.js
Last active August 29, 2015 14:13
Simple (and probably naive) JavaScript Lens implementation
module.exports = Group;
Group.compete = compete;
function Group (equals, compare) {
this.equals = equals;
this.compare = compare;
}
Group.prototype = {
@unscriptable
unscriptable / compete.js
Created January 13, 2015 16:44
Multiplexed streams compete
module.exports = compete;
/**
* Filter function to determine which of all multiplexed streams
* is currently winning.
* TODO: change this so that multiple streams can be winners, but
* don't use an array of winners. Perhaps inject another function?
*/
function compete (identify, compare) {
var winner, wid;
@unscriptable
unscriptable / filterGroup.js
Last active August 29, 2015 14:12
One solution for dealing with the parallel nature of neurons when using *networks of streams* instead of *neural networks*. (This probably doesn't help with *massively parallel* situations.)
var most = require('most');
module.exports = filterGroup;
/**
* Filters each of a group (array) of streams via a predicate that
* compares each value passing through the group to the most recent
* value of every other stream in the group.
* @param {function (a, b): boolean} predicate compares the most
* recent value of a stream (a) to the current value passing through
┏( ˆ◡ˆ)┛ ┗(ˆ◡ˆ )┓ Welcome to the RaveJS debug party! ┏( ˆ◡ˆ)┛ ┗(ˆ◡ˆ )┓
If you see some 404s for JSON files, that's ok! They'll go away when you build your app.
If the 404s are spoiling your debug party, the README.md shows how to evict them.
rave.js:4692 Rave REPL enabled! (experimental)
Available commands:
-> rave.dump() - returns rave's context to be viewed or manipulated.
-> rave.version() - shows rave's version.
-> rave.checkVersions() - checks if extensions are compatible.
@unscriptable
unscriptable / neuron.js
Last active July 20, 2016 14:25
Just playing with neurons
/**
* Just playing with neurons. Neurons must be connected to each other with
* a synapse, which provides the "strength" of the signal of the upstream
* neuron.
* A few months back, I had the idea that neurons were just like functions.
* The inputs are the signals from other neurons that have been modified
* via synapses. The output (action potential) is simply the return value.
*
* A few weeks ago, I realized that functions weren't the right model *at all*.
* Neural networks are more like streams. This implementation relies on

Debugger APIs

NOTE: This document describes APIs that provide support to external debugging tools. Do not use these APIs in application code.

The following APIs allow debugging tools to receive information about promise errors. For example, when.js uses them in its builtin unhandled rejection reporting feature, as well as in when/monitor/console to display long async stack traces.

A debugger could use them to do any number of things, such as display a list of "currently unhandled promise rejections", or send error reports to an error aggregation service.

Example

Migrating from curl.js

Rave Starters make it super easy to start a new front-end web application with rave. However, adapting an existing app over to rave takes a bit more effort. This document will step you through the process of adapting your current curl+cram project to RaveJS.

Survey your current app

Before you start deleting, modifying, or moving files, assemble a list of all of your front-end app's third-party dependencies. The first place to look for dependencies is in your app's bootstrap code. For curl-based projects, look in the paths and packages sections of your curl.js configuration.

You should record the version numbers of your third-party dependencies, if possible. If you use bower or npm and installed using the --save option, the version numbers are in your package.json or bower.json files.

@unscriptable
unscriptable / ambiguous-race.js
Last active September 25, 2019 13:20 — forked from briancavalier/ambiguous-race.js
Promise.race is a lie
// This is the function we will use to call Promise.race().
// logWinner is simply a function that races two promises
// and logs the "winner" of the race as a side effect.
function logWinner (p1, p2) {
Promise.race([p1, p2]).then(console.log.bind(console));
}
// Here are 2 promises, p1 and p2. p2 always resolves
// first, since p1 resolves in 20 ms, and p2 resolves
// in 10 ms. By any reasonable definition of "race",
@unscriptable
unscriptable / 1.js
Created September 24, 2014 18:49
script factory redux
/** @license MIT License (c) copyright 2014 original authors */
/** @author Brian Cavalier */
/** @author John Hann */
module.exports = scriptFactory;
function scriptFactory (scriptEval) {
return function (loader, load) {
return function () {
scriptEval(load.source);
@unscriptable
unscriptable / 0-final-captureDefines.js
Last active February 11, 2024 22:29
rave's captureDefines module as function closures and as Constructor-proto
module.exports = captureDefines;
function captureDefines (amdEval) {
var result;
define.amd = { jQuery: {} };
return function (load) {
result = { named: [], isAnon: false, anon: void 0, called: false };
return capture(amdEval, define, load, result);