Skip to content

Instantly share code, notes, and snippets.

View unscriptable's full-sized avatar
🏔️

John Hann unscriptable

🏔️
View GitHub Profile
@unscriptable
unscriptable / curry.js
Last active August 29, 2015 14:04
One way to create a curry function. Currying: http://en.wikipedia.org/wiki/Currying
module.exports = curry;
function curry (f) {
var arity = f.length;
var params = [];
var end = createEnd(f, arity);
return createCurried(params, arity, end);
}
function createEnd (f, arity) {
┏( ˆ◡ˆ)┛ ┗(ˆ◡ˆ )┓ 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 / 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
@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 / 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 / maybe.js
Last active August 29, 2015 14:20
Maybe monad in javascript
export class Maybe {
constructor (f) {
this._run = f;
}
/**
* Transform the result of a maybe operation.
*/
map (f) {
$.each(itemList, function (which) {
// if dev passed an array
if ($.isArray(itemList))
// use the 2nd arg as item name (1st arg is array index)
which = arguments[1];
// check if we've already initialized this item
var already = doneMap[which];
if (!already)
cujo.js equivalent (in-browser):
file: myApp.view.LoginPanel.html
<div class="myapp-view-loginpanel">
<span data-attach="greeting">${display.greeting}</span>
<a data-attach="action" href="{$config.loginUrl}">{$display.loginAction}</a>
</div>
logout version extends login version (inheritance defined in myApp.view.LogoutPanel.js:
@unscriptable
unscriptable / PhantomVisit.hs
Last active September 22, 2015 21:04
Implement Visit using phantom types and smart constructors
module PhantomVisit (
Visit,
CallAhead,
Remote,
WalkIn,
Rsv,
callAhead,
remote,
walkIn,
rsv
attributeMap: {
seconds: {
data: "seconds",
type: "no-dom"
},
displaySeconds: {
source: "seconds",
deriver: "_displaySeconds",
type: "no-dom"
}