This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<button id="search">Search</button> | |
<div id="results"></div> | |
<script src="IO.js"></script> | |
<script src="IO.Browser.js"></script> | |
<script> | |
var fake_search = function (kind) { | |
return function (query) { | |
return IO.do([ | |
function (_) { | |
return IO.delay(Math.floor(Math.random() * 100)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
// Measuring the rate at which we can get callbacks. | |
// This technique is known, I believe, to yield the | |
// fastest call-me-as-soon-as-you-can time. | |
var start_ms = performance.now(), end_ms; | |
var img = document.createElement('img'); | |
var count = 0, N = 10000; | |
function callback() { | |
count++; | |
if (count === N) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
// Code from http://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-os-x | |
#include <mach/mach_time.h> | |
#define ORWL_NANO (+1.0E-9) | |
#define ORWL_GIGA UINT64_C(1000000000) | |
static double orwl_timebase = 0.0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Requirements: | |
// 1) npm install ffi | |
// 2) npm install ref | |
// 3) dynamically loadable libblas must be available aleady. | |
var ffi = require('ffi'); | |
var ref = require('ref'); | |
var doublePtr = ref.refType(ref.types.double); | |
var blas = new ffi.Library('libblas', { | |
'cblas_dgemm': ['void', [ | |
'int', 'int', 'int', 'int', 'int', 'int', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
// Channel is a simple object that can be used for | |
// CSP-style concurrency in Javascript. In JS code, | |
// the act of taking a value from a channel looks | |
// like a blocking call and therefore is not appropriate | |
// for single-process/single-thread environments like | |
// NodeJS. To address that, Channel produces promises | |
// for values. | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A thread module for working with ES6 generator functions | |
// that model threads of execution. This module hopes for | |
// composeable behaviour. | |
// fork(g, resume, [context]) | |
// | |
// Will start the given generator function to run asynchronously. | |
// When the thread completes, either by an error or by returning | |
// a value, the given (optional) resume callback is called. | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var thread = require('./thread'); // Refers to https://gist.github.com/srikumarks/8662298 | |
// call upload like this - | |
// thread.fork(upload(stream, idOrPath, tag), optionalResume) | |
function upload(stream, idOrPath, tag) { | |
return function* (resume) { | |
var blob = blobManager.create(account); | |
var tx = db.begin(); | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define('node_types', ['steller'], function (S) { | |
return { | |
sine: function (freq) { | |
var osc = this.audioContext.createOscillator(); | |
osc.frequency.value = freq; | |
osc.start(0); | |
return S.SoundModel(this, [], [osc]); | |
}, | |
gain: function (multiplier) { | |
var gain = this.audioContext.createGain(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For completeness, I include the steller API object and the current audio context as arguments. | |
function theremin(steller, sh) { | |
var osc = null; | |
var gain = sh.audioContext.createGain(); | |
var sm = steller.SoundModel({}, [], [gain]); | |
sm.start = sh.fire(function (clock) { | |
if (osc) { osc.stop(clock.t1); } | |
osc = AC.createOscillator(); | |
osc.frequency.value = sm.frequency.value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// (Syntax) -> String | |
function resolveCtx(originalName, ctx, stop_spine, stop_branch) { | |
if (ctx instanceof Mark) { | |
return resolveCtx(originalName, ctx.context, stop_spine, stop_branch); | |
} | |
if (ctx instanceof Def) { | |
if (stop_spine.indexOf(ctx.defctx) !== -1) { | |
return resolveCtx(originalName, ctx.context, stop_spine, stop_branch); | |
} | |
return resolveCtx(originalName, renames(ctx.defctx, ctx.context, originalName), stop_spine, unionEl(stop_branch, ctx.defctx)); |