Skip to content

Instantly share code, notes, and snippets.

View trxcllnt's full-sized avatar

Paul Taylor trxcllnt

View GitHub Profile
@trxcllnt
trxcllnt / Observable.js
Last active August 29, 2015 14:00
Observable with Lift and Mutate
var Subscriber = require('./Subscriber'),
noop = require('./support/noop')
;
module.exports = (function Observable() {
function fixDisposable(subscriber, disposable) {
var disposableType;
if(disposable != null) {
if((disposableType = typeof disposable) === 'function') {
@trxcllnt
trxcllnt / zone.js
Last active August 29, 2015 14:01
// Zone.create = Observable.create
// Zone#setCallback = Observable#forEach/Observable#subscribe
// Zone#then = Observable#map
// Zone#catch = Observable#catch
//
// A little stub of some zone examples that map 1-1 with Rx. Instead of a zone global,
// the "zone" object is passed in to the function we created the Zone with.
//
// This allows us to run multiple Zones in parallel, for example, if we want to await
// two run two asynchronous operations (say, a file-read and a network request) at the
@trxcllnt
trxcllnt / optional-params-and-tail-call-optimizer.sjs.js
Last active August 29, 2015 14:04
Sweet.js macros for optional/default params, and a macro to unroll tail-recursive functions into imperative loops.
macro parameters {
rule { ($arguments ...) } => { (params ($arguments ...)) }
}
macro params {
// group matchers
rule { ($x:ident = $y:expr , $rest:params (,) ...) } => { $x , $rest (,) ... }
rule { ($x:ident , $rest:params (,) ...) } => { $x , $rest (,) ... }
rule { ($x:ident = $y:expr) } => { $x }
@trxcllnt
trxcllnt / EnumerableX.js
Last active August 29, 2015 14:11
Unrolling Enumerable.
macro flatMapVars { rule { } => { } }
macro concatVars { rule { } => { } }
macro flatMapCond { rule { } => { true } }
macro concatsCond { rule { } => { true } }
macro concatBlocks { rule { } => { } }
// wrapArgs(x, i, a) .foo(function (y, j, b) { return y + 1; }) ... ;
macro wrapArgs {
function(stxs, context) {
var name_stx = stxs[0];
@trxcllnt
trxcllnt / scheduler-tests.js
Last active August 29, 2015 14:13
Testing Rx's currentThread and immediate scheduler schedule events appropriately even when requested in the future (and they have to block).
/* output:
legend:
current: Scheduled concurrently by the CurrentThread scheduler.
recursive: Scheduled recursively by the Immediate scheduler.
setTimeout: Scheduled asynchronously by the Timeout scheduler.
blocking-current: Scheduled to block concurrently by the CurrentThread scheduler.
blocking-recursive: Scheduled to block recursively by the Immediate scheduler.
setTimeout a 0
setTimeout b 0
@trxcllnt
trxcllnt / tailrec.sjs
Last active August 29, 2015 14:14
Macros to rewrite tail-recursive immediately invoked function expressions (IIFE) and function declarations as tight while loops.
/* output *//*
var result;
var acc = 1, x = 10;
while (true) {
if (x <= 1) {
// non-recursive return invocations aren't rewritten
acc = log(acc);
break;
} else {
acc = acc * x;
@trxcllnt
trxcllnt / Generator.js
Created June 1, 2015 20:31
RxJS 3 CurrentFrame Scheduler
var noop = require("rx/support/noop");
var try_catch = require("rx/support/try-catch");
var flatten_args = require("rx/support/arguments-flatten");
var errorObj = require("rx/support/error-object");
function Generator(destinationOrNext, _throw, _return) {
if(destinationOrNext && typeof destinationOrNext === "object") {
this.result = destinationOrNext.result || { done: false };
this.destination = destinationOrNext;
} else {
@trxcllnt
trxcllnt / rxjs-2016-performance-results.txt
Last active August 29, 2015 14:22
node v0.10.22 / MacBook Pro (Retina, 13-inch, Early 2015) / 2.7 GHz Intel Core i5 / 16 GB 1867 MHz DDR3
old fromArray with immediate scheduler x 129,353 ops/sec ±1.57% (91 runs sampled)
new fromArray with immediate scheduler x 475,989 ops/sec ±1.18% (82 runs sampled)
267.98% faster than Rx
old from (array) with immediate scheduler x 116,648 ops/sec ±2.21% (81 runs sampled)
new from (array) with immediate scheduler x 689,305 ops/sec ±4.35% (88 runs sampled)
490.93% faster than Rx
old from (array) with immediate scheduler x 68,486 ops/sec ±1.60% (88 runs sampled)
new from (array) with immediate scheduler x 983,076 ops/sec ±3.37% (85 runs sampled)
package org.tiny.tlf.interaction.gestures
{
import flash.events.Event;
import flash.events.IEventDispatcher;
import org.tiny.tlf.events.GestureEvent;
public class GestureBase implements IGesture
{
public function GestureBase()
override protected function initializeApplication():void
{
// Try to initialize mixins to the ReflexApplicationLoader
// (a well behaved mixin relies on a MovieClip),
// but if anything goes wrong, don't allow mixins to muck
// up our initialization.
var mixins:Array = info()["mixins"];
if(mixins && mixins.length > 0)
{
while(mixins.length > 0)