Skip to content

Instantly share code, notes, and snippets.

Building cool things at @testimio

Benjamin Gruenbaum benjamingr

Building cool things at @testimio
Block or report user

Report or block benjamingr

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 gist:8887343
Entity._save = Promise.promisify(;
Entity.prototype._create = Promise.method(function(itemData) {
if (!this.Model) throw new Error('No Mongoose.Model defined, use setModel()');
var item = new this.Model(itemData);
return Entity._save.apply(item);
View code from view
<li ng-repeat="Rating in Ratings | restrict: 'ratingHistory'" ng-click="showRating(Rating)" ng-class="Rating.rating" analytics="clicked-on-Rating-History" analytics-props="Rating.analyticsProps" >
<!--- ... --->
<div class="more-info" ng-show="">
<!--- ... --->
<d3overview stock="Rating.stock" show-legend="false" show-duration="false" show-recommendations="true" />
benjamingr / gist:10536349
Created Apr 12, 2014
Bluebird asParallel
View gist:10536349
//end debug
Hijack to accept parallelism limit argument
function queueConcurrent(work, degreeOfParallelism) {
// work is array of functions returning promises
"use strict";
View gist:11301184
View gist:5a9c269cdfda3b484f39
// returns a version of a given promise returning function fn that always uses the same cached value
function once(fn){
var called = false, cache = null;
return function cachedPromise(){
if(called) return cache;
cache = fn.apply(this,arguments);
called = true;
return cache;
benjamingr / gist:0ed038727f38fb77e7ee
Created May 20, 2014
Resolve a dependency recursively based on .needs
View gist:0ed038727f38fb77e7ee
// this will load a script, I assume each dependency contains what it needs inside
// `dependency.needs` and we'll load that.
// stuff is called script here, but it could also be a stylesheet or whatever.
// Since when we return a promise from a `.then` it unwraps and runs the promise we return, we can
// return a promise for the values of our _own_ dependencies, and continue doing so, promises will
// unwrap everything for us.
// This does not do have the same `.addDependency` interface from before, it's just a function to show
View gist:749bfe2b3c0411c7430c
function ResourceBuilder(){
this._dependencies = [];
ResourceBuilder.prototype.addDependency = function(dep){
ResourceBuilder.protototype.get = function(){
var loadPromises =; // alternatively, dependencies could be promises already
return Promise.all(loadPromises).then(function(loadedResourcesArray){
View gist:e0ea06536589581c2feb
// Promise.swift
// Promise
// Created by Benjamin Gruenbaum on 8/12/14.
// Copyright (c) 2014 Tipranks. All rights reserved.
import Foundation
View gist:e41e0d2f3097d27c3f65
class Foo<A,B>{
var bar:[(A,B)] = [(A,B)]() // why is this invalid?
View gist:5b42be523b7f313a79b7
// Promise.swift
// Promise
// Created by Benjamin Gruenbaum on 8/12/14.
// Copyright (c) 2014 Tipranks. All rights reserved.
import Foundation
You can’t perform that action at this time.