Skip to content

Instantly share code, notes, and snippets.

View gist:ffe88f1475552130c78d
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);
};
View gist:351d16157baa926861ee
Usage
Hello world:
$ pm2 start app.js
Raw Examples
# Fork mode
$ pm2 start app.js --name my-api # Name process
View test
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 Oct 22, 2014
bootstrap tooltip template para controlar con css
View gist:0dfb3cabfe5408fff0e8
$('#password').tooltip({
trigger: 'manual',
template: '<div id="owaspResponse" class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
});
View gist:a2c2da706d937dffd0ea
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 listenTo model itemview
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);
}
});
View gist:646aa8356fc722591d94
N4Ig+glgJiBcIFYAsA2Axig7GgjAn2aAZkgEw4DMVSRKAnCADQgB2AhgLYCmcIAYgHsAThzYAXAQAIAqiwhopULpICyAgG4QOELiwmSlkgApchAZwHsANkxBmIALx7xSmOgA9yKW8J17xEJa86rYADmwA5lxmcADaoPZOvK4eXraQMPDI6Fi4+IQk5FQUNChsthBiXBwxsPGsnM4gUOICZqGmFtbRtlBauvaWtaAAFlwQESNicKR0AAzMAO7QYiNwmEgLIACecAQIzO4zCAC+zAKhYoEsw3Zi21bOoFXu07CgbFYTLLyPRNNnEBESxvUCLcaTN6sYSiGzMRJNFgwz4gQFaSJPED3Dq8MxiIRcMRoNaAgBGwiUQjgz22OPgFi+MBOzOYLTE5XeIHRUTgLAArlYrMxQlY2GguCMBFZKbwjKLxZLpaZbKLSVwbPAACKtMzGTqWT49QHhAl6XkCoVY2lNMxcNBXILMNAE8RcTIgVGMUDsbi8CAsUJ8sQ4Xr9G7XW5jCZTOCbJYrNawUgoA47GZzLZHJOnc6XCPUu4PTEvUEgT7fX5cf6eoEggvg6NQpEiFHwxw22E2NGiHmc7E2/GE4k18lCGV9624qXQVEs5riDmgbnOfmC4XyiVS8cgAAyWkdIFV6t4AEEOoLoFIjK6hEiaybdFC2W0OuYDY8Ysx+36A0HbM6uFdd1PW9RpfjYNUrBDVkw0GG4CyjSFjnjKBVnWOM01gfZDmOQELgdeDOTxIsCxLAtywiH54HFPRlUBYEzU5BskPgZtYVsBFwKEHluwxUjJ3pQciRJZhR3HGk6TsacmTnNlFy5HsVwtdcxU3JUqXgOVVMVGVmCPDUQE1E8ABUAHkAGVjAAUQAJXM0yADkTx3KzzPvNhTSfHVXy6Q1PytSTVnVCDjydF0qmAs5QN9ek7QI0hQ24cMhgQiEYywjMULQ2A6FTXZYAQTNcNzAjbmIx5SK4V5yK+SjK2rei6yYtKm2ROE7HbXg2JRXjewkgcCWEkcKWVCdJ
@linus-amg
linus-amg / handlebars.helpers.js
Created Dec 1, 2014
handlebars helpers 1 (lleva por ejemplo add, substract, divide, modulus, multiply, floor, ceil, round, remainder, sum)
View handlebars.helpers.js
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 Dec 30, 2014
Valid controller pattern for repetitive shows?
View controller.coffee
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
View 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'