Skip to content

Instantly share code, notes, and snippets.

@linus-amg
linus-amg / gist:e3201b0dd7e8a78cbabd
Created Aug 28, 2015
workaround optimization killers
View gist:e3201b0dd7e8a78cbabd
var errorObject = {value: null};
function tryCatch(fn, ctx, args) {
try {
return fn.apply(ctx, args);
}
catch(e) {
errorObject.value = e;
return errorObject;
}
}
@linus-amg
linus-amg / utils.coffee
Last active Aug 29, 2015
new Date() .time() .unix_timestamp() and Number.pad() methods !!
View utils.coffee
Number::pad = (len) ->
return (new Array(len + 1).join('0') + @).slice(-len)
Date::time = ->
returnValue = ''
returnValue += @getHours().pad(2) + ':'
returnValue += @getMinutes().pad(2) + ':'
returnValue += @getSeconds().pad(2)
return returnValue
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 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
View gist:564283d1c2b3577d401e
history:
im on:
/cars
the navigation shows,
cars, houses, baseball, horses
im on:
/cars/1
the navigation is hidden
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'