Skip to content

Instantly share code, notes, and snippets.

View FelipeJz's full-sized avatar

Felipe Jimenez FelipeJz

View GitHub Profile
@FelipeJz
FelipeJz / redirect.js
Last active September 29, 2016 17:35
Nodejs, Express simple redirect
var express = require('express')
var app = express();
app.set('port', (process.env.PORT || 8080))
app.get('*', function(request, response) {
response.redirect('http://example.com')
})
app.listen(app.get('port'), function() {
@FelipeJz
FelipeJz / arrayIndexByPropertyValue.js
Last active August 5, 2016 17:44
Get array index by the value of the object property
//array = [{object: 'property'}, {object2: 'property2'}]
var arrayIndexByPropertyValue = function (array, property, value){
//Runs the array
for(var i = 0, m = null; i < array.length; ++i) {
//Compares the property value
if(array[i][property] == value) {
//If correct returns it
return i;
break;
@FelipeJz
FelipeJz / Logger.js
Last active August 5, 2016 17:06 — forked from santhoshtr/Logger.js
Winston based configurable node logger
var winston = require( 'winston' ),
fs = require( 'fs' ),
logDir = 'log', // Or read from a configuration
env = process.env.NODE_ENV || 'development',
logger;
winston.setLevels( winston.config.npm.levels );
winston.addColors( winston.config.npm.colors );
if ( !fs.existsSync( logDir ) ) {
Array.prototype.remove = function(value) {
var idx = this.indexOf(value);
if (idx != -1) {
return this.splice(idx, 1);
}
return false;
}