Skip to content

Instantly share code, notes, and snippets.

# First, set up a customer_create method.  This tells us how to create the
# customer in your persistence layer.
IsotopeSubscriptions.customer_create = lambda do |hash|
  customer = Customer.new(hash)
  if customer.save
    customer
  else
    false
  end

end

def braintree_create
result = Braintree::TransparentRedirect.confirm(request.query_string)
customer = IsotopeSubscriptions.customer_create.call(customer_hash(result.customer))
if customer
redirect_to customer_path(customer)
else
render action: 'new'
end
end
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines in the history. See bash(1) for more options
export HISTCONTROL=ignoredups
export EDITOR=vim
# Amazon's Web Services
export EC2_HOME=~/software/ec2
@knewter
knewter / gist:1946938
Created March 1, 2012 03:07
I N C E P T I O N . . .
nested_vendored_plugins = Dir["./vendor/plugins/mapto/vendor/plugins/**"]
nested_vendored_plugins = Dir["./vendor/plugins/mapto/vendor/cms/vendor/plugins/**"] + nested_vendored_plugins
# THIS DOES NEAT STUFF DON'T REMOVE
inject_nested_plugin = Proc.new do |plugin|
eval <<-EOF
config.plugin_locators.unshift(
Class.new(Rails::Plugin::Locator) do
def plugins
[Rails::Plugin.new(File.expand_path("#{plugin}"))]
end
clear Lock
keycode 0x42 = Escape
# Generates the link to determine where the site bar switch button returns to.
def site_bar_switch_link
link_to_if(admin?, t('.switch_to_your_website', site_bar_translate_locale_args),
#(if session.keys.map(&:to_sym).include?(:website_return_to) and session[:website_return_to].present?
#session[:website_return_to]
#else
#refinery.root_path(:locale => (Refinery::I18n.default_frontend_locale if Refinery.i18n_enabled?))
#end)) do
session[:website_return_to] || refinery.root_path(:locale => (Refinery::I18n.default_frontend_locale if Refinery.i18n_enabled?))
# Generates the link to determine where the site bar switch button returns to.
def site_bar_switch_link(html_options = {})
admin? ? admin_switch_link(html_options) : frontend_switch_link(html_options)
end
def admin_switch_link(html_options = {})
link_to t('.switch_to_your_website', site_bar_translate_locale_args),
session[:website_return_to] || refinery.root_path(:locale => (Refinery::I18n.default_frontend_locale if Refinery.i18n_enabled?)),
html_options
end
When /^I select classification "([^"]*)"$/ do |classification|
facet_link(classification).click
end
When /^I expand classification "([^"]*)"$/ do |classification|
facet_hitarea_element(classification).click
end
Then /^I should have classification "([^"]*)" applied$/ do |classification|
classification_filter(classification).text.should_not == ""
#require './config/environment' # FIXME REMOVE
require 'grit'
require 'fileutils'
namespace :git_repos do
desc "Clone or update git repos for all projects"
task :create => :environment do
workspace_dir = File.join(Rails.root, "tmp", "xrono_git_workspace")
puts "Creating workspace directory at #{workspace_dir}"
FileUtils.rm_rf File.join(workspace_dir) if Dir.exists?(workspace_dir)
Dir.mkdir( workspace_dir )
@knewter
knewter / gist:2344034
Created April 9, 2012 14:55
incorrect first effort at SRS algorithm (this one just gets cards that haven't been answered longest first)
#I'm implementing a flashcard learning system. I have cards and answers. I want a SQL query that will return the card that has been answered longest ago (so if you've not answered a card in a long time, you should be more likely to see it)
SELECT DISTINCT "cards".id FROM "cards" LEFT OUTER JOIN "answers" ON "answers"."card_id" = "cards"."id" LEFT OUTER JOIN "decks" ON "decks"."id" = "cards"."deck_id" WHERE (deck_id = 1) ORDER BY answers.created_at ASC LIMIT 1