Skip to content

Instantly share code, notes, and snippets.

View linus-amg's full-sized avatar

Linus Gubenis linus-amg

  • Mexico, Berlin
  • 20:26 (UTC -06:00)
View GitHub Profile
@linus-amg
linus-amg / nested-creator.js
Created June 22, 2015 21:31
nested-creator
var source = {
'1': { name: 'Linus' },
'2.1': { name: 'Raul' },
'2.2': { name: 'Beto' },
'2.3': { name: 'Alex' },
'2.4': { name: 'Josue' },
'3': { name: 'Florian' }
};
function createObjects(parent, chainArray, value) {
{
"name": "...",
"scripts": {
"production": "forever -a --uid admin start index.js"
}
}
var http = require('http');
var request = http.get({
url: '/',
headers: {
cookie: 'session.id=...'
}
}, function(res) {
var data = '';
res.on('data', function(chunk) {
@linus-amg
linus-amg / window.document.md
Created May 27, 2015 18:46
window document screen

Window is the main JavaScript object root, aka the global object in a browser, also can be treated as the root of the document object model. You can access it as window in most of the cases (in the browser);

window.screen is a small information object about physical screen dimensions.

window.document or just document is the main object of the visible document object model/DOM.

module.exports = (options) ->
#
# <- i want to do something like app.use here
# when im mounting this middleware
#
return (req, res, next) ->
# req.app is available here, but thats too late, i dont
# want the app instance in every request, i only want
# it when i mount the middleware
res.send('OK')
class Collection extends Backbone.Collection
model: User
query: (query) ->
query = new RegExp query, 'gi'
filtered = @filter (item) ->
state = !!item.attributes.details.firstName.match(query)
return state
return new Collection filtered
@linus-amg
linus-amg / plugins.coffee
Created May 19, 2015 20:45
plugins.coffee
# import dependencies
dependencies = {}
dependencies.Debugger = require 'lib/debugger'
# include vendors
$ = require 'jquery'
_ = require 'underscore'
Backbone = require('backbone').$ = $
Marionette = require 'backbone.marionette'
@linus-amg
linus-amg / gruntfile.coffee
Created May 19, 2015 20:42
grunt browserify
files:
'dist/assets/js/plugins.js': 'src/plugins.coffee'
options:
transform: ['caching-coffeeify']
browserifyOptions:
extensions: '.coffee'
paths: ['./src', './src/app']
@linus-amg
linus-amg / deepSum.js
Last active August 29, 2015 14:20
Deepsum.js
Handlebars.registerHelper('deepSum', function(source, key) {
var result;
if (typeof key === 'string') {
if (key.split('.').length > 1) {
source = _.pluckDeep(source, key);
} else {
source = _.pluck(source, key);
}
}
var render = function render(tplEl, htmlEl, context) {
var template = Handlebars.compile($(tplEl).text());
context = context || {};
return $(htmlEl).html(template(context));
};
render('#tpl-demo', '#doc', { name: 'John Doe' });