Skip to content

Instantly share code, notes, and snippets.

View thanpolas's full-sized avatar

Thanos Polychronakis thanpolas

View GitHub Profile
@thanpolas
thanpolas / list-mantri.js
Created February 18, 2014 13:49
List required files by Mantri
var mantri = require('mantri');
var mantriCompile = require('mantri/lib/mantri-build-compile');
mantriCompile.getDepsFiles({
jsRoot: './js',
src: './js/app.js',
gmockDir: mantri.helpers.getPath('closure-mock'),
}, function(status, results) {
console.log('Status should be true:', status);
@thanpolas
thanpolas / test.js
Created February 13, 2014 13:52
How to test a promise returning async method using Mocha
test('test case', function(done) {
promise.method(function(result) {
assert.equal(result.name, 'mocha');
}).then(done, done);
});
@thanpolas
thanpolas / apitest.js
Created February 7, 2014 17:09
Mocha Cooldown
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 December 26, 2015 16:48
Grunt Config for node server + livereload
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
express: {
options: {
// Override defaults here
},
web: {
options: {
@thanpolas
thanpolas / doodle.js
Created June 11, 2013 16:24
Promises doodle
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 December 18, 2015 02:58
Node Server + Grunt Watch Tasks + Livereload using one command: grunt
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 December 16, 2015 04:19
when.sequence execution penalty
//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 April 11, 2013 22:00
Testing promises with mocha
var assert = require('chai').assert;
var when = require('when');
var def1 = when.defer();
function getProm() {
return def1.promise;
}
@thanpolas
thanpolas / app.js
Created April 4, 2013 14:51
Multiple promise callbacks
// 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 March 21, 2013 13:11
A required Gruntfile config
module.exports = function (grunt) {
multiTask: {
options: {
anObject: {
a: 1
}
},
target: {
options: {
anObject: {