Skip to content

Instantly share code, notes, and snippets.

View linus-amg's full-sized avatar

Linus Gubenis linus-amg

  • Mexico, Berlin
  • 23:17 (UTC -06:00)
View GitHub Profile
@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.

var http = require('http');
var request = http.get({
url: '/',
headers: {
cookie: 'session.id=...'
}
}, function(res) {
var data = '';
res.on('data', function(chunk) {
{
"name": "...",
"scripts": {
"production": "forever -a --uid admin start index.js"
}
}
@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) {
@linus-amg
linus-amg / sortByPosition.js
Created June 24, 2015 16:09
sortByPosition
var sortByPosition = function(a, b) {
if(a.y<b.y || (a.y==b.y && a.x<b.x)) return -1;
if(a.y==b.x && a.x==b.x) return 0;
return 1;
}
@linus-amg
linus-amg / createorpush.js
Created June 29, 2015 17:13
create or push
var util = require('util');
global.$ = global.jQuery = require('jquery');
$.extend = require('extend');
var _ = require('underscore');
var Backbone = require('backbone');
Backbone.$ = $;
require('backbone-nested');
var Model = Backbone.NestedModel.extend({
createOrPush: function(key, newValue) {
@linus-amg
linus-amg / mafo.js
Created June 30, 2015 15:45
multiple async filereader onloads
for (var i in files) {
var file = files[i];
var reader = new FileReader();
reader.onload = (function(detail) {
return function(e) {
var plaintext = e.target.result;
console.log(plaintext);
};
})(file);
reader.readAsText(file);
class Router extends Marionette.AppRouter
routes:
'*default': ->
App.channel.comply 'routes:default'
module.exports = Router
class Controller extends Marionette.Service
radioCommands:
'global routes:default': ->
console.log 'default route triggered'
'app routes:default': ->
console.log 'default route triggered'
module.exports = Controller
Marionette.Application::_initChannel = ->
@channelName = _.result(@, 'channelName') || 'global'
@channel = _.result(@, 'channel') || Backbone.Radio.channel(@channelName)