Skip to content

Instantly share code, notes, and snippets.

View epappas's full-sized avatar
👨‍💻
I'm Building Something Interesting :)

Evangelos Pappas epappas

👨‍💻
I'm Building Something Interesting :)
View GitHub Profile
@epappas
epappas / test-stub.js
Created May 12, 2014 11:15
mocha test stub
var should = require('should');
var assert = require('assert');
var superagent = require('superagent');
describe('app', function() {
var agent = superagent.agent();
before(loginUser(agent));
describe('GET', function() {
@epappas
epappas / sharp-vs-imagemagic.js
Created May 28, 2014 15:43
a benchmark to test how faster sharp is
var im = require('imagemagick');
var sharp = require('sharp');
var path = require('path');
var LOOPS = 1000;
var cscreen = '';
var $scope = this;
var timings = {
start: { test1: { sharp: 0, imagemagic: 0 } },
'use strict';
var fs = require('fs');
var path = require('path');
var async = setImmediate ? setImmediate : process.nextTick ? process.nextTick : setTimeout;
module.exports = function(dir, mode, cb) {
var wqueue = [];
dir = path.resolve(dir);
@epappas
epappas / jiffy.json.erl
Created June 14, 2014 12:47
An example of use of jiffy
{[{<<"arr">>,[1,2,3,4]},
{<<"arrStr">>,[<<"a">>,<<"b">>]},
{<<"arrobj">>,[{[{<<"a">>,1},{<<"b">>,2}]}]},
{<<"obj">>,
{[{<<"key1">>,<<"payload1">>},{<<"key2">>,<<"payload1">>}]}},
{<<"testBool">>,true},
{<<"testInt">>,1},
{<<"testStr">>,<<"abc">>},
{<<"testReal">>,1.2}]} = jiffy:decode(<<"
{
@epappas
epappas / ObjectTraverse.js
Created June 19, 2014 11:41
Traverse complex objects
function obj(o) {
var args = Array.prototype.slice.call(arguments, 1);
return (function __get(o, args) {
var key = args.shift();
if(key !== undefined) return __get(o[key] || { }, args);
return o;
})(o, args);
}
@epappas
epappas / safeObj.js
Created June 20, 2014 09:36
Safely traverse through object
function safeObj(obj) {
return (function obj() {
var args = Array.prototype.slice.call(arguments, 0);
return (function __get(obj, args) {
var key = args.shift();
if(key !== undefined) return __get.call(this, obj[key] || { }, args);
return obj;
}).call(this, this, args);
}).bind(obj || {});
}
@epappas
epappas / json2xml.js
Created June 24, 2014 13:55
Lightweight JSON to XML translator
module.exports = function json2xml(obj) {
var str = '';
for(var key in obj) {
str += __json2xml(key, obj[key]);
}
return str;
};
function __json2xml(parrent, props) {
'use strict';
var fs = require('fs');
var path = require('path');
var safeObj = require('./safeObj');
module.exports = function JsonStore(name, filestoreDir) {
var self = this;
var sourceData = { };
var loopPtr;
@epappas
epappas / allochron.js
Created July 11, 2014 13:05
Allochron; how async.parallel should be like.
'use strict';
module.exports = function allochron(funcs, onComplete, limit) {
funcs = typeof funcs === 'function' ? [funcs] : funcs;
limit = limit || 3;
var scope = this;
var length = Object.keys(funcs).length;
var shouldRun = {val: true};
var counter = {i: length};
@epappas
epappas / setjdk
Created July 11, 2014 15:08
setjdk
function setjdk() {
if [ $# -ne 0 ]; then
removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin'
if [ -n "${JAVA_HOME+x}" ]; then
removeFromPath $JAVA_HOME
fi
export JAVA_HOME=`/usr/libexec/java_home -v $@`
export PATH=$JAVA_HOME/bin:$PATH
fi
}