Skip to content

Instantly share code, notes, and snippets.

View Willmo36's full-sized avatar

Max Willmott Willmo36

  • SkipTheDishes
  • Saskatoon
View GitHub Profile
function Account(){
//private
var _isReseller = false;
//public
var account = {
isReseller:function(){
return _isReseller;
},
setReseller:function(isR){
@Willmo36
Willmo36 / rx.observable.to$q.js
Created May 26, 2015 16:00
RxJS to$q for angular 1.2.XXX
rx.Observable.prototype.to$q = function(onFulfiled, onRejected) {
var source = this;
var deferred = $q.defer();
var value, hasValue = true;
source.subscribe(function(v) {
value = v;
hasValue = true;
}, deferred.reject, function () {
hasValue && deferred.resolve(value);
@Willmo36
Willmo36 / rx-angular.safeSubscribe.js
Created May 29, 2015 09:26
Angular Rx safeSubscribe
rx.Observable.prototype.safeSubscribe = function(scope, fn, err, cmp) {
var disposable = this.safeApply(scope, fn).subscribe(angular.noop, err, cmp);
scope.$on("$destroy", function() {
disposable.dispose();
});
return disposable;
};
@Willmo36
Willmo36 / toFriendlyDateTime.js
Created June 5, 2015 11:10
Friendly datetime method for JavaScript dates
Date.prototype.toFriendlyDateTime = function() {
var friendlyTime = this.toLocaleTimeString();
friendlyTime = friendlyTime.substring(friendlyTime.lastIndexOf(":"), 0);
return friendlyTime + " " + this.toLocaleDateString();
}
@Willmo36
Willmo36 / react-id.js
Created July 28, 2015 13:55
Get the React ID of a component instance. Useful for tracing multiple instances of components
this.getDOMNode().attributes['data-reactid'].value
@Willmo36
Willmo36 / spyOnBaseClass.js
Created July 31, 2015 08:36
Jasmine spyOn - es6 base class
spyOn(your_instance.__proto__, 'base_method');
@Willmo36
Willmo36 / countdown.most.js
Created October 15, 2015 14:55
count down with most.js
import most from 'most';
const load$ = most.fromEvent('DOMContentLoaded', document);
const tick$ = load$.flatMap(() => {
return most.iterate((f) => f + 1, 0).take(5).flatMap(v => most.of(v).delay(v * 1000));
});
load$.observe(() => console.log('timer start'));
tick$.observe(x => console.log('timer tick', x));
@Willmo36
Willmo36 / countdown.rx.js
Created November 9, 2015 11:00
countdown with rx
const now = moment();
const end = now.clone().add(2, 'minutes');
const diff = (end - now) / 1000;
const tick$ = Rx.Observable.timer(0,1000)
.scan((acc) => {
return acc - 1;
}, diff)
.take(diff);
@Willmo36
Willmo36 / esnextbin.md
Created February 5, 2016 16:41
esnextbin sketch
@Willmo36
Willmo36 / esnextbin.md
Last active March 4, 2016 10:07
esnextbin sketch