Skip to content

Instantly share code, notes, and snippets.

@kpdecker
kpdecker / backbone-start-hack.js
Created April 20, 2014 23:36
Hack for backbone router start requirement in Thorax
Backbone.history = new Backbone.History();
// Preload the root value so getFragment does not blow up prior to start being called
Backbone.history.root = '/';
@kpdecker
kpdecker / leaky-error.js
Created April 17, 2014 00:26
V8 error stack retention
// #! node --trace-gc --expose-gc leaky-error.js
var heapdump = require('heapdump');
function Root() {
this.exec = function() {
throw new Error('test');
};
}

Thorax Server Side Rendering

WARN: This is preliminary documentation and subject to change.

There are three major concerns that need to be solved to do full server-side rendering of our current code base, server-based routing, HTML rendering and restoring views once recieved on the client.

Server Routing

Server routing is built on top of Hapi's routing stack. At build time all backbone routes are converted to Hapi routes which the Scotsman project registers on server startup. This is done through the module-map.json config file, included in the static resource bundle.

'passing': function (done) {
var a = function (self, x, callback) {
return callback(self, x + 10);
};
var B = function () {
this.y = 10;
};
B.prototype.go = function () {
@kpdecker
kpdecker / index.js
Created November 5, 2013 16:26
Hapi error handling cases
var Hapi = require('hapi');
// Create a server with a host, port, and options
var server = new Hapi.Server('localhost', 8001);
server.route([
{
path: '/failure',
method: 'GET',
config: {
@kpdecker
kpdecker / detect.js
Created October 4, 2013 01:48
detect
// Based on https://github.com/madrobby/zepto/blob/master/src/detect.js
// Zepto.js
// (c) 2010-2012 Thomas Fuchs
// Zepto.js may be freely distributed under the MIT license.
/*jshint asi: true, boss: true, curly: false, eqeqeq: false */
module.exports = function($, ua){
var os = $.os = {},
browser = $.browser = {};
@kpdecker
kpdecker / handlebars.js
Created October 3, 2013 17:03
compiled es6 module
"use strict";
var base = require("./handlebars/base");
// Each of these augment the Handlebars object. No need to setup here.
// (This is done to easily share code between commonjs and browse envs)
var SafeString = require("./handlebars/safe-string")['default'];
var Exception = require("./handlebars/exception")['default'];
var Utils = require("./handlebars/utils");
var runtime = require("./handlebars/runtime");
@kpdecker
kpdecker / library.json
Created May 4, 2013 21:30
Lumbar mixin terminology update
{
"name": "something-unique",
"mixins": {
"base": {
"scripts": [
"global.js",
"base.js"
]
},
@kpdecker
kpdecker / pdf-to-tiff.sh
Created April 13, 2013 19:59
pdf-to-tiff
#!/bin/sh
# Converts PDF files to TIFF files suitible for antiquated systems.
# Usage:
# $ pdf-to-tiff.sh file1 file2
#
# Installation:
# $ brew install ghostscript
# $ brew install libtiff
# $ brew install --fresh --build-from-source imagemagick --with-libtiff
#
@kpdecker
kpdecker / check-image.sh
Created April 12, 2013 21:23
Prototype png color reduction script/linter
#! /bin/sh
QUALITY=95
DEPTHS="256 128 64 32 8 4 2"
totalSaved=0
for name in `find "$1" -name "*.png" -not -name "*-fs8.png"`; do
output=