Skip to content

Instantly share code, notes, and snippets.

View trxcllnt's full-sized avatar

Paul Taylor trxcllnt

  • NVIDIA, Inc
  • Portland, OR
  • 07:44 (UTC -07:00)
  • X @inlineptx
View GitHub Profile
function initConcatFriction(Rx) {
Rx.Observable.prototype.concatFriction = function (u, xS, yS, vS, aS) {
if (typeof xS !== 'function')
xS = function (m) { return m.x; };
if (typeof yS !== 'function')
yS = function (m) { return m.y; };
if (typeof vS !== 'function')
vS = function (m) { return m.velocity; };
if (typeof aS !== 'function')
@trxcllnt
trxcllnt / rx-sort.coffee
Last active December 17, 2015 02:39
Observable.sort
rx = require 'rx'
_ = require 'underscore'
Observable = rx.Observable
Observable::sort = (sorter) ->
source = @
Observable.createWithDisposable (observer) ->
list = [];
source.map((val) ->
@trxcllnt
trxcllnt / Values.as
Created April 20, 2013 22:26
A dynamic Observable dictionary.
/*
* Copyright (c) 2013 the original author or authors
*
* Permission is hereby granted to use, modify, and distribute this file
* in accordance with the terms of the license agreement accompanying it.
*/
package org.tinytlf.observables
{
import asx.array.flatten;
import asx.fn.args;
/*
Observable.mappend maps a value through a selector and returns
a unique Array of the input values and the result(s).
Use mappend when you'd rather not create anonymous value types
just to track the IObservable stream inputs. Takes advantage of
JS's ability to apply an Array as function arguments, giving the
benefit of more readable JS methods.
Pros:
@trxcllnt
trxcllnt / Main.as
Created April 15, 2013 19:58
concatMany transforms an IEnumerable to an IObservable. concatMany selects each Enumerable value into an Observable, waits for the IObservable to complete, then selects the next Enumerable value.
package
{
import asx.fn.K;
import asx.fn._;
import asx.fn.args;
import asx.fn.getProperty;
import asx.fn.noop;
import asx.fn.partial;
import asx.fn.sequence;
import asx.number.mul;
@trxcllnt
trxcllnt / concatMany.as
Created April 15, 2013 11:21
concatMany transforms an IEnumerable to an IObservable by selecting an Observable for each Enumerable value, waiting until the Observable is complete, then moving on to the next value in the Enumerable.
function concatMany(enumerable:IEnumerable, selector:Function):IObservable {
return Observable.createWithCancelable(function(observer:IObserver):ICancelable {
const iterator:IEnumerator = enumerable.getEnumerator();
const subscriptions:CompositeCancelable = new CompositeCancelable();
var schedule:Function = function():void {
subscriptions.add(Scheduler.scheduleRecursive(Scheduler.defaultScheduler, function(reschedule:Function):void {
schedule = reschedule;
package org.tinytlf.fn
{
import raix.interactive.toEnumerable;
/**
* @author ptaylor
*/
public function pipe(...functions):Function {
return function(...args):* {
return toEnumerable(functions).reduce(args, function(args:Array, func:Function):Array {
@trxcllnt
trxcllnt / combineLatest-tricks.coffee
Created January 25, 2013 20:55
combineLatest, merge, expand
merge = [].concat
expand = (fn, context) -> (args) -> fn.apply context, args.slice 0, fn.length
obs1 = Rx.Observable.returnValue(1)
obs2 = Rx.Observable.returnValue(2)
obs3 = Rx.Observable.returnValue(3)
combined = obs1.combineLatest(obs2, merge).combineLatest(obs3, merge)
combined.subscribe expand (o1, o2, o3) -> o1 + o2 + o3
fs = require 'fs'
path = require 'path'
{exec} = require 'child_process'
# Make sure we have our dependencies
try
colors = require 'colors'
coffee = require 'coffee-script'
browserify = require 'browserify'
catch error
@trxcllnt
trxcllnt / OnlineConcaveMinima.coffee
Created December 1, 2011 22:07
A JS port of the ConcaveMinima algorithm from D. Eppstein (http://www.ics.uci.edu/~eppstein/PADS/SMAWK.py)
class OnlineConcaveMinima
values = []
indices = [0]
finished = 0
matrix = (i, j) -> 0
base = 0
tentative = 0