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 / fact.js
Last active August 29, 2015 14:13
crazy JS factorial :)
var N = 10;
(function(N){
var arr = [];
for(var i=N+1; i--;) arr.push(i);
arr.pop(); // last elem is 0
return arr;
})(N).reduce(function (n, i) {
return n * i;
}, 1);
@epappas
epappas / pagination.jade
Created October 9, 2014 14:21
Angular Pagination + Jade
ul.pagination.right()
// if current page is > 10, have -10 back btn
li.arrow(ng-if="currentPage > 10")
a(ng-click='goToPage(currentPage - 10)') ««
// have previous & nect page as clicable option
li(ng-repeat='n in [-1, 0, 1]' ng-class="{current: currentPage == currentPage + n}")
a(ng-if="currentPage + n > 0 && (currentPage + n) < (total / 10)",
ng-click='goToPage(currentPage + n)') {{currentPage + n}}
// Next btn, if next exists
li.arrow(ng-if="currentPage < (total / 10) + 3 && (currentPage + 3) < (total / 10)")
@epappas
epappas / list_my_ips.sh
Created September 3, 2014 10:24
Getting my ips
$ ifconfig | grep 'inet ' | cut -d' ' -f2 | awk '{ print $1}'
@epappas
epappas / haproxyd
Created July 18, 2014 09:31
start|stop|restart haproxy
#!/usr/bin/env bash
# haproxyd
# Script to start|stop|restart haproxy from /etc/init.d/
HAPROXY_PATH=/usr/sbin
HAPROXY_DAEMON=$HAPROXY_PATH/haproxy
HAPROXY_CONFIG=/etc/haproxy/haproxy.cfg
test -x $HAPROXY_DAEMON || exit 0
test -f $HAPROXY_CONFIG || exit 1
@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
}
@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};
'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 / 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) {
@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 / 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);
}