Skip to content

Instantly share code, notes, and snippets.

View jankuca's full-sized avatar

Jan Kuča jankuca

  • Prague, Czech Republic
  • 00:58 (UTC +02:00)
View GitHub Profile
init: function (done) {
// 1
if (this.$session['user_id'] == null) {
return this.redirectTo('backend:sign:login');
}
// 2
this.$users.one(this.$session['user_id'], function (err, user) {
// 4
if (!err) {
this.current_user = user;
var darkside = require('darkside');
var SignController = function (users) {
darkside.base(darkside.ViewController, this);
this.$users = users;
};
require('util').inherits(SignController, darkside.ViewController);
var darkside = require('darkside');
var DashboardController = function (users) {
darkside.base(darkside.ViewController, this);
this.$users = users;
};
require('util').inherits(DashboardController, darkside.ViewController);
@jankuca
jankuca / compose.js
Created July 14, 2012 17:50
OT Composition in JS
var assert = require('assert');
function dump(actions, graph) {
console.log();
actions.forEach(function (action) {
if (graph) {
switch (action[0]) {
case 'retain':
process.stdout.write(new Array(action[1] + 1).join('>') + ' | ');
@jankuca
jankuca / client.js
Created July 5, 2012 17:10
OT in JS
var area = document.getElementById('area');
var buffer = [];
var position = 0;
var last_id = 1;
var socket = io.connect('http://localhost:5000');
socket.on('operation', function (operation) {
@jankuca
jankuca / injector.js
Created May 14, 2012 23:05
Injector.js
/**
* @constructor
*/
function Injector() {
/**
* @type {!Object.<string, function(Injector=): !Object>}
*/
this.factories = {};
@jankuca
jankuca / utils.js
Created March 25, 2012 18:19
JS Kit (node.js)
Object.defineProperty(Function.prototype, 'initializing', {
value: false,
writable: true,
});
Object.defineProperty(Function.prototype, '$super', {
value: function () {
throw new Error('The $super method is not available.');
},
writable: true,
});
@jankuca
jankuca / example.js
Created November 12, 2011 16:40
gzip for native node.js http.Server
var http = require('http');
var gzip = require('http-gzip');
var server = http.createServer(function (req, res) {
gzip(req, res);
res.writeHead(200, {
'content-type': 'text/plain'
});
res.write('I am gonna be gzip encoded, dude!');
@jankuca
jankuca / index.js
Created August 5, 2011 14:46
Colored console for node.js
var stdout = process.stdout;
var info = console.info;
var warn = console.warn;
var error = console.error;
var DEFAULT = "\033[m";
var BLUE = "\033[1;34m";
var YELLOW = "\033[1;33m";
var RED = "\033[1;31m";
@jankuca
jankuca / deferred.js
Created August 4, 2011 09:12
JavaScript Deferred
goog.provide('Deferred');
/**
* Handles deferred calls
* @constructor
*/
var Deferred = function () {
this.pending_ = [];
this.completed = false;
this.status = null;