This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.expand_path('../boot', __FILE__) | |
require 'rails/all' | |
# Require the gems listed in Gemfile, including any gems | |
# you've limited to :test, :development, or :production. | |
Bundler.require(*Rails.groups) | |
module MyProject | |
class Application < Rails::Application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'faraday' | |
class WordpressController < ApplicationController | |
@@wp_client = Faraday.new(url: "http://#{ENV['WP_DOMAIN']}") do |builder| | |
builder.adapter Faraday.default_adapter | |
builder.headers = {'Content-Type' => 'application/json'} | |
builder.request :url_encoded | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# What the heck is this spec about? | |
# | |
# It's a gut-check that runs against every controller in the application. | |
# It is NOT a replacement for writing controller specs for each controller. | |
# | |
# What this does is things like check to make sure you didn't forget to lock | |
# down the index action of a controller to authorized users, checks to see if | |
# common routes are throwing silly errors, etc. | |
# | |
# Your controller passing these tests does not guarantee that it is healthy. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 = "" |