Skip to content

Instantly share code, notes, and snippets.

@kpdecker
kpdecker / gist:2822100
Created May 29, 2012 01:48
expandToken - simple mustache replacement
function expandToken(input, scope) {
if (input && input.indexOf && input.indexOf('{{') >= 0) {
var re = /(?:\{?[^{]+)|(?:\{\{([^}]+)\}\})/g,
match,
ret = [];
function deref(token, scope) {
var segments = token.split('.'),
len = segments.length;
for (var i = 0; scope && i < len; i++) {
if (segments[i] !== 'this') {
@kpdecker
kpdecker / gist:3919679
Created October 19, 2012 18:06
Possible bindToRoute programatic navigation fix
diff --git a/js/lib/backbone.historytracker.js b/js/lib/backbone.historytracker.js
index 9dbedd6..f9f4dc5 100644
--- a/js/lib/backbone.historytracker.js
+++ b/js/lib/backbone.historytracker.js
@@ -100,6 +100,10 @@
}
}
_navigate.call(this, fragment, options);
+
+ if (!options || !options.trigger) {
@kpdecker
kpdecker / gist:4005095
Created November 2, 2012 23:53
lumbar-route-grouper
/*jshint node: true */
var _ = require('underscore'),
Config = require('lumbar').config;
var queryStringParam = /^\?(.*)/,
namedParam = /:([\w\d]+)/g,
splatParam = /\*([\w\d]+)/g,
escapeRegExp = /[-[\]{}()+?.,\\^$|#\s]/g;
@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=
@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 / library.json
Created May 4, 2013 21:30
Lumbar mixin terminology update
{
"name": "something-unique",
"mixins": {
"base": {
"scripts": [
"global.js",
"base.js"
]
},
@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 / 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 / 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: {
'passing': function (done) {
var a = function (self, x, callback) {
return callback(self, x + 10);
};
var B = function () {
this.y = 10;
};
B.prototype.go = function () {