Skip to content

Instantly share code, notes, and snippets.

View jbarnette's full-sized avatar

John Barnette jbarnette

View GitHub Profile
require "bundler/setup"
require "rack/streaming_proxy"
warn "Sleeping for a bit before starting gimme."
sleep 3
warn "Starting gimme."
nport = 2727
decorate: (n, fn) ->
target = this[n]
unless _.isFunction target
throw new Error "Can't decorate #{n}, it's not a Function."
unless target.fns?
wrap = ->
args = Array.prototype.slice.call arguments
finish = _.after wrap.fns.length, => wrap.old.apply this, args
require "tilt"
class Tilt::Whirl < Tilt::Template
def evaluate scope, locals, &block
file.split(".").reverse.inject data do |input, step|
klass = Tilt[step]
klass ? klass.new(file) { input }.render(scope, locals) : input
end
end
# Render a template file using Tilt. Templates can
# have multiple file extensions, which will be rendered one at a
# time. For example, "foo.md.erb" will first be run through ERB,
# then through Markdown.
def self.render template, context = nil, options = {}
context ||= Object.new
options.merge! default_encoding: Encoding::UTF_8
file = Dir["app/templates/#{template}.*"].first
# If an AJAX request starts with "/api", transform it into a
# cross-site request to the API server and attach an API token. If
# it's an AJAX request to the local stack, add X-CSRF. If an AJAX
# response status is 403, it means the current API token has expired,
# so ask the local stack for a new token and retry the request.
apiToken = $("meta[name='api.token']").attr "value"
apiURL = $("meta[name='api.url']").attr "value"
csrf = $("meta[name=csrf]").attr "value"
def bind superclass
klass = Class.new superclass do |c|
def c.name
superclass.name
end
def c.inspect
name
end
end
fs = require "fs"
path = require "path"
rimraf = require "rimraf"
url = require "url"
{exec, spawn} = require "child_process"
heroku = (callback) ->
exec "heroku config --shell", (err, stdout, stderr) ->
console.log "heroku config error: #{err}" if err
namespace :db do
desc "Replace the local dev DB with a copy from Heroku."
task :pull, [:src, :dest] do |t, args|
abort "Only in dev." unless ENV.development?
src = args.src || "heroku-app-name"
dest = args.dest || "local-db-name"
restore = "pg_restore -x -O -d #{dest}"
url = "heroku pgbackups:url --app #{src}"
task :quux
task :foo do |t|
tasks = Rake.application.top_level_tasks
args = tasks.slice! (tasks.index(t.name) + 1)..-1
unless args.empty?
puts "You passed me some args! \n#{args.inspect}"
end
end
$:.unshift "lib" if File.directory? "lib"
project = File.basename File.expand_path(".")
require project if File.file? "lib/#{project}.rb"