Skip to content

Instantly share code, notes, and snippets.

Avatar

Thanos Polychronakis thanpolas

View GitHub Profile
@thanpolas
thanpolas / test.js
Created Feb 13, 2014
How to test a promise returning async method using Mocha
View test.js
test('test case', function(done) {
promise.method(function(result) {
assert.equal(result.name, 'mocha');
}).then(done, done);
});
View apitest.js
var apitest = module.exports = {};
/**
* Have a Cooldown period between tests.
*
* @param {number} seconds cooldown in seconds.
* @return {Function} use is beforeEach().
*/
apitest.cooldown = function(seconds) {
return function(done) {
@thanpolas
thanpolas / Gruntfie.js
Last active Dec 26, 2015
Grunt Config for node server + livereload
View Gruntfie.js
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
express: {
options: {
// Override defaults here
},
web: {
options: {
@thanpolas
thanpolas / doodle.js
Created Jun 11, 2013
Promises doodle
View doodle.js
function retProm() {
var def = when.defer();
return def.resolve();
}
console.log('one');
retProm().then(function(){console.log('two'));
console.log('three');
@thanpolas
thanpolas / Gruntfile.js
Last active Dec 18, 2015
Node Server + Grunt Watch Tasks + Livereload using one command: grunt
View Gruntfile.js
module.exports = function (grunt) {
grunt.initConfig({
watch: {
options: {
livereload: true
},
// triggering livereload when the .css file is updated
// (compared to triggering when sass completes)
// allows livereload to not do a full page refresh
styles: {
@thanpolas
thanpolas / perf.js
Last active Dec 16, 2015
when.sequence execution penalty
View perf.js
//var PerfTime = require('perf-time');
//var _ = require('underscore');
var Perf = module.exports = function() {
this.startTime = null;
// this.t = new PerfTime();
this.t = {
get: function() {
return Date.now();
}
@thanpolas
thanpolas / test.js
Created Apr 11, 2013
Testing promises with mocha
View test.js
var assert = require('chai').assert;
var when = require('when');
var def1 = when.defer();
function getProm() {
return def1.promise;
}
@thanpolas
thanpolas / app.js
Created Apr 4, 2013
Multiple promise callbacks
View app.js
// calling multiple callbacks for a promise
var promise = fnReturnsPromise();
promise.then(fn1);
promise.then(fn2);
// that is not the same ?
fnReturnsPromise().then(fn1).then(fn2);
@thanpolas
thanpolas / Gruntfile.js
Created Mar 21, 2013
A required Gruntfile config
View Gruntfile.js
module.exports = function (grunt) {
multiTask: {
options: {
anObject: {
a: 1
}
},
target: {
options: {
anObject: {
@thanpolas
thanpolas / promises.js
Created Mar 14, 2013
promises "resolve" !== "fullfill"
View promises.js
var def1 = when.defer();
var def2 = when.defer();
def1.promise.then(function( arg1 ) {
arg1 === def2.promise;
});