Skip to content

Instantly share code, notes, and snippets.

View FelipeJz's full-sized avatar

Felipe Jimenez FelipeJz

View GitHub Profile
Array.prototype.remove = function(value) {
var idx = this.indexOf(value);
if (idx != -1) {
return this.splice(idx, 1);
}
return false;
}
@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 ) ) {
@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 / 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 / pg_export.sh
Created June 18, 2024 14:02
Postgresql Export Using URL
#!/bin/bash
CONNECTION_URL=""
BACKUP_DIR="bks"
BACKUP_FILE="$BACKUP_DIR/backup_$(date +'%Y%m%d%H%M%S').sql"
# Function to parse connection URL
parse_url() {
local url="$1"
local proto="$(echo $url | grep '://' | sed -e's,^\(.*://\).*,\1,g')"