Skip to content

Instantly share code, notes, and snippets.

View linus-amg's full-sized avatar

Linus Gubenis linus-amg

  • Mexico, Berlin
  • 11:49 (UTC -06:00)
View GitHub Profile
@linus-amg
linus-amg / gist:e3201b0dd7e8a78cbabd
Created August 28, 2015 17:48
workaround optimization killers
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 August 29, 2015 01:57
new Date() .time() .unix_timestamp() and Number.pad() methods !!
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
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);
};
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 / 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'