Joel Wietelmann jwietelmann

View gist:5832216
1 2 3 4 5 6 7 8 9 10
var sys = require('child_process');
 
function commandExists(cmd) {
var exists = false;
sys.exec(cmd, function(err) {
if(err === null) // of maybe: if(!err instanceof Error)
exists = true;
});
View gist:4252663
1 2 3 4 5 6 7 8 9 10
error: Error running command start
error: Nodejitsu Error (500): Internal Server Error
error: There was an error while attempting to deploy the app
error:
error: tar exited with code: 2
error: Error output from Haibu:
error:
error: Error: tar exited with code: 2
error: at ChildProcess.Tar.init (/root/haibu-orchestra/node_modules/haibu/lib/haibu/repositories/tar.js:58:26)
error: at ChildProcess.EventEmitter.emit (events.js:91:17)
View mongoose-single-subdoc.js
1 2 3 4 5 6 7 8 9 10
// mongoose doesn't like single embedded schemas
// it likes them as arrays of an embedded schema
// so this is a cheater hack to fake a single subdoc
// it creates a field named `_yourField` and a virtual named `yourField`
// and it makes sure the array keeps just one element in it
// USAGE EXAMPLE:
/*
var models = require('models')
, ChildSchema = models.ChildSchema
, singleSubdoc = require('mongoose-single-subdoc');
View mongoose-unique-ref.js
1 2 3 4 5 6 7 8
module.exports = function(schema, options) {
schema.method('addUniqueRef', function(field, item) {
if(this[field].indexOf(item) < 0) this[field].push(item);
});
schema.method('removeUniqueRef', function(field, item) {
this[field].splice(this[field].indexOf(item));
});
};
View massAssign.js
1 2 3 4 5 6 7 8 9 10
var mongoose = require('mongoose');
 
module.exports = exports = function(schema, options) {
schema.method('massAssign', function(fields) {
for(var i in schema.tree) {
if(schema.tree[i].protect || fields[i] == null) continue;
this[i] = fields[i];
}
});
schema.static('massAssign', function(fields) {
View singleSubDoc.js
1 2 3 4 5 6 7 8 9 10
models.util = {
singleSubDoc: function(schema, virtualName) {
var realName = '_' + virtualName;
schema.virtual(virtualName)
.get(function() {
if(this[realName].length) return this[realName][0];
else return null;
})
.set(function(value) {
this[realName] = [value];
View handlebars_helpers.coffee
1 2 3 4 5 6 7 8 9
helpers =
test: (templateName) ->
"THIS IS A TEST"
 
addHelpers = (handlebars) -> handlebars.registerHelper name, fn for name, fn of helpers
 
# server-side
if module? && module.exports?
module.exports = addHelpers
View abort_xhr.coffee
1 2 3 4 5 6 7 8 9
class My.Model extends Backbone.Model
 
sync: (method, model, options) ->
 
if xhr = this["_#{method}Xhr"]
xhr.abort()
 
this["_#{method}Xhr"] = Backbone.sync method, model, options
View handlebone.js.coffee
1 2 3 4 5 6 7 8 9 10
# patched version of Handlebars with helper - passes current view to next context
Handlebars.registerHelper "with", (context, options) ->
context.view = this.view if this.view # the patch
options.fn context
 
# patched version of Handlebars each helper - passes current view to next context
Handlebars.registerHelper "each", (context, options) ->
fn = options.fn
inverse = options.inverse
ret = ""
View json_helper.rb
1 2 3 4 5 6 7 8 9 10
class JsonHelper
 
# Usage:
# json_register("hello", "Hello, World!")
# json_register("foo.bar", @foobar)
def json_register(name, data)
@json_registry ||= {}
 
pieces = name.split('.')
last = pieces.pop
Something went wrong with that request. Please try again.