Skip to content

Instantly share code, notes, and snippets.

View thanpolas's full-sized avatar

Thanos Polychronakis thanpolas

View GitHub Profile
@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: {
@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 / 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 / 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 / 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 / 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 / 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 / singleton-class.js
Created September 16, 2016 09:45
ES6 Singleton Pattern
/**
* @fileOverview Singleton pattern on ES6.
*/
import logger from './logger.midd';
/**
* The class statement.
*
*/
@thanpolas
thanpolas / dabblet.css
Created November 30, 2012 13:44
the mark
/**
* the mark
*/
body {
text-align: center;
margin-top: 20px;
}
.thanpolas {
font-size: 202px;
-webkit-border-radius: 12px;
@thanpolas
thanpolas / hidden-iframe.js
Last active August 8, 2018 03:06
In the absence of CORS support the Hidden Iframe technique is the only way to submit a big amount of data (over 2kb that jsonp can handle).
/**
* @fileOverview Hidden iFrame implementation for browsers without CORS.
*
* Usage:
* var iframe = new Iframe();
* iframe.submit(url, {data: yourData}, function(err) {});
*
* The server will get a POST request on the defined URL with the data
* JSON encoded in the body attribute named "data".
*/