Skip to content

Instantly share code, notes, and snippets.

Matthew Podwysocki mattpodwysocki

Block or report user

Report or block mattpodwysocki

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ContinuationMonad.fs
open System
type Cont<'T> =
abstract Call<'R> : ('T -> 'R) * (exn -> 'R) -> 'R
let protect f x cont econt =
let res = try Choice1Of2 (f x) with err -> Choice2Of2 err
match res with
| Choice1Of2 v -> cont v
| Choice2Of2 v -> econt v
@mattpodwysocki
mattpodwysocki / eventsource.js
Last active Sep 23, 2019
Adding support for server-sent events for RxJS
View eventsource.js
if (!!root.EventSource) {
/**
* This method wraps an EventSource as an observable sequence.
* @param {String} url The url of the server-side script.
* @param {Observer} [openObserver] An optional observer for the 'open' event for the server side event.
* @returns {Observable} An observable sequence which represents the data from a server-side event.
*/
dom.fromEventSource = function (url, openObserver) {
return new AnonymousObservable(function (observer) {
@mattpodwysocki
mattpodwysocki / rx_child_process_hacking.js
Created Aug 16, 2011
RxJS and node.js Child Processes
View rx_child_process_hacking.js
var rx_child_process = require('./rx_child_process');
rx_child_process.exec('dir /w').Subscribe(function(x) {
console.log('stdout: ' + x.stdout);
console.log('stderr: ' + x.stderr);
});
rx_child_process.exec('foo').Subscribe(function(x) {
console.log('stdout: ' + x.stdout);
console.log('stderr: ' + x.stderr);
}, function(e) {
View setImmediate.js
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>setImmediate + jQuery Deferred</title>
<script src="http://code.jquery.com/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
(function() {
function wrapSetImmediate(work, time) {
var def = $.Deferred();
@mattpodwysocki
mattpodwysocki / examples.js
Last active Apr 13, 2019
Implementing Reduce and ReduceRight in RxJS
View examples.js
var leftFold = Rx.Observable.range(1, 10).reduce(function (acc, x) { return acc * x; }, 1);
leftFold.forEach(function (x) { console.log(x); });
=> 3628800
var rightFold = Rx.Observable.range(1, 10).reduceRight(function (acc, x) { return acc * x; }, 1);
rightFold.forEach(function (x) { console.log(x); });
=> 3628800
View examples.md
@mattpodwysocki
mattpodwysocki / fromEventPattern.js
Last active Nov 23, 2018
Exploring FromEventPattern in base RxJS with sample implementations in jQuery, DOM, Dojo and Node.js
View fromEventPattern.js
Observable.fromEventPattern = function (addHandler, removeHandler) {
return new AnonymousObservable(function (observer) {
function innerHandler (e) {
observer.onNext(e);
}
var returnValue = addHandler(innerHandler);
return disposableCreate(function () {
if (removeHandler) {
removeHandler(innerHandler, returnValue);
@mattpodwysocki
mattpodwysocki / Promises-Observables.js
Last active Nov 3, 2018
New support for Promises in RxJS to include conversion to and from Promises, and operator support such as: flatMap/selectMany, mergeObservable/mergeAll, concatObservable/concatAll, switchLatest/switch, and startAsync
View Promises-Observables.js
// Observable to Promise
var promise = Rx.Observable.return(42).toPromise(RSVP.Promise);
promise.then(console.log.bind(console));
// => 42
// Using config instead of argument
Rx.config.Promise = RSVP.Promise;
var promise = Rx.Observable.return(42).toPromise();
promise.then(console.log.bind(console));
// => 42
View Stamp.ps1
function Get-Files($path = $pwd) {
foreach ($item in Get-ChildItem $path) {
if (Test-Path $item.FullName -PathType Container) {
Get-Files $item.FullName
} else {
$item
}
}
}
@mattpodwysocki
mattpodwysocki / eventaggregator.js
Last active Jun 13, 2018
Example of an event aggregator using RxJS
View eventaggregator.js
var Rx = require('rx');
function EventAggregator() {
this._subject = new Rx.Subject(); // Can be ReplaySubject too
}
EventAggregator.prototype.publish = function (type, data) {
this._subject.onNext( { type: type, data: data });
};
You can’t perform that action at this time.