Skip to content

Instantly share code, notes, and snippets.

View linus-amg's full-sized avatar
👉
👌

Linus Gubenis linus-amg

👉
👌
View GitHub Profile
console.log(new Date().time(),'[INFO]','Testing...');
Number.prototype.pad = function (len) {
return (new Array(len+1).join('0') + this).slice(-len);
};
Date.prototype.time = function () {
var dateMS = this;
return dateMS.getHours().pad(2)+':'+dateMS.getMinutes().pad(2)+':'+dateMS.getSeconds().pad(2);
};
Usage
Hello world:
$ pm2 start app.js
Raw Examples
# Fork mode
$ pm2 start app.js --name my-api # Name process
var result = str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(letter, index) {
var result = index === 1 ? letter.toLowerCase() : (!isNaN(last) ? letter.toUpperCase() : ' '+letter.toUpperCase());
last = parseInt(letter);
return result;
});
@linus-amg
linus-amg / gist:0dfb3cabfe5408fff0e8
Created October 22, 2014 16:28
bootstrap tooltip template para controlar con css
$('#password').tooltip({
trigger: 'manual',
template: '<div id="owaspResponse" class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
});
var util = require('util');
var parser = require('xml2json');
var express = require('express');
var app = express();
app.use(anyBodyParser);
app.post('/xml_to_json', function (req, res) {
var json = parser.toJson(req.rawBody, { arrayNotation: true });
res.send(json);
view = Marionette.ItemView.extend({
initialize: function() {
this.listenTo(this.model, 'change:detail', this.calculateTotal);
this.listenTo(this.model, 'change:total', this.render);
},
calculateTotal: function() {
var newTotal = calc();
this.model.set('total', newTotal);
}
});
N4Ig+glgJiBcIFYAsA2Axig7GgjAn2aAZkgEw4DMVSRKAnCADQgB2AhgLYCmcIAYgHsAThzYAXAQAIAqiwhopULpICyAgG4QOELiwmSlkgApchAZwHsANkxBmIALx7xSmOgA9yKW8J17xEJa86rYADmwA5lxmcADaoPZOvK4eXraQMPDI6Fi4+IQk5FQUNChsthBiXBwxsPGsnM4gUOICZqGmFtbRtlBauvaWtaAAFlwQESNicKR0AAzMAO7QYiNwmEgLIACecAQIzO4zCAC+zAKhYoEsw3Zi21bOoFXu07CgbFYTLLyPRNNnEBESxvUCLcaTN6sYSiGzMRJNFgwz4gQFaSJPED3Dq8MxiIRcMRoNaAgBGwiUQjgz22OPgFi+MBOzOYLTE5XeIHRUTgLAArlYrMxQlY2GguCMBFZKbwjKLxZLpaZbKLSVwbPAACKtMzGTqWT49QHhAl6XkCoVY2lNMxcNBXILMNAE8RcTIgVGMUDsbi8CAsUJ8sQ4Xr9G7XW5jCZTOCbJYrNawUgoA47GZzLZHJOnc6XCPUu4PTEvUEgT7fX5cf6eoEggvg6NQpEiFHwxw22E2NGiHmc7E2/GE4k18lCGV9624qXQVEs5riDmgbnOfmC4XyiVS8cgAAyWkdIFV6t4AEEOoLoFIjK6hEiaybdFC2W0OuYDY8Ysx+36A0HbM6uFdd1PW9RpfjYNUrBDVkw0GG4CyjSFjnjKBVnWOM01gfZDmOQELgdeDOTxIsCxLAtywiH54HFPRlUBYEzU5BskPgZtYVsBFwKEHluwxUjJ3pQciRJZhR3HGk6TsacmTnNlFy5HsVwtdcxU3JUqXgOVVMVGVmCPDUQE1E8ABUAHkAGVjAAUQAJXM0yADkTx3KzzPvNhTSfHVXy6Q1PytSTVnVCDjydF0qmAs5QN9ek7QI0hQ24cMhgQiEYywjMULQ2A6FTXZYAQTNcNzAjbmIx5SK4V5yK+SjK2rei6yYtKm2ROE7HbXg2JRXjewkgcCWEkcKWVCdJ
@linus-amg
linus-amg / handlebars.helpers.js
Created December 1, 2014 17:06
handlebars helpers 1 (lleva por ejemplo add, substract, divide, modulus, multiply, floor, ceil, round, remainder, sum)
var Utils = helpersUtils.Utils;
var Library = helpersUtils.Library;
var Dates = helpersUtils.Dates;
var HTML = helpersUtils.Html;
Handlebars.registerHelper('first', function (array, count) {
if (!Utils.isUndefined(array)) {
array = Utils.result(array);
if (!Utils.isUndefined(count)) {
count = parseFloat(Utils.result(count));
@linus-amg
linus-amg / controller.coffee
Created December 30, 2014 14:37
Valid controller pattern for repetitive shows?
NavigationView = require 'views/navigation.coffee'
HomeView = require 'views/home.coffee'
OtherView = require 'views/other.coffee'
LogoutView = require 'views/logout.coffee'
ListView = require 'views/list/index.coffee'
TableView = require 'views/table/index.coffee'
ListCollection = require 'collections/list.coffee'
TableCollection = require 'collections/table.coffee'
module.exports = Marionette.Controller.extend
@linus-amg
linus-amg / application.coffee
Created December 30, 2014 14:44
application coffee
Controller = require 'controller.coffee'
Router = require 'router.coffee'
Components = require 'components/index.coffee'
require 'handlebars/helpers/index.coffee'
module.exports = App = new Marionette.Application()
App.addRegions
header: '#header-region'
main: '#main-region'