Skip to content

Instantly share code, notes, and snippets.

View bullfight's full-sized avatar
🚀

Patrick Schmitz bullfight

🚀
View GitHub Profile
@bullfight
bullfight / assets.rake
Created December 1, 2011 15:36
modified asset rake
require 'rubygems'
require 'aws/s3'
require 'digest/md5'
require 'mime/types'
## This defines the rake task `assets:deploy`.
namespace :assets do
desc "Deploy all assets in public/**/* to S3/Cloudfront"
task :deploy_staging do
Rake::Task["assets:precompile"].execute
class SubscriptionsController < ApplicationController
def new
@plan = Plan.find(params[:plan_id])
@subscription = @plan.subscriptions.build
end
def create
@subscription = Subscription.new(params[:subscription])
if @subscription.create_customer
redirect_to @subscription, :notice => "Thank you for subscribing!"
class Subscription < ActiveRecord::Base
def create_customer
if !coupon.blank? && coupon_valid?
customer = Stripe::Customer.create( description: email, plan: plan_id, card: stripe_card_token, coupon: coupon )
else
customer = Stripe::Customer.create( description: email, plan: plan_id, card: stripe_card_token )
end
rescue Stripe::InvalidRequestError => e
logger.error "Stripe error while creating customer: #{e.message}"
errors.add :base, "There was a problem with your credit card. Please try again."
@bullfight
bullfight / application.js
Created November 15, 2011 16:48
application.js
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require google_analytics
//= require jquery.spin
//= require spin.min
//= require nested_form
//= require global
//= require subscriptions/subscriptions
/app/views/shared/_page_search.html.haml
//current placeholder, this search bar is only found on controller index pages and is directed at the individual controller
= simple_form_for "SEARCH", :html => {:id=>'site-page_search'} do |f|
= f.input :q, :label => false, :required => false, :placeholder => "#{placeholder}..."
// a simple solution I have come up with so that search will work on each of the index pages.
= form_tag request.env['REQUEST_PATH'], :method => :get, :id=>'site-page_search' do
= text_field_tag :search, params[:search], :placeholder => "#{placeholder}..."
@bullfight
bullfight / example.feature
Created October 26, 2011 11:47
local tunnel class used to open ssh tunnel for webhook testing
Feature: Paying with Google Checkout
Background:
Given my test environment is available via an SSH tunnel
And the Google Checkout Sandbox is configured to callback to my test environment
Scenario: Paying with Google Checkout
Given I have some products in my cart
When I press "Google Checkout"
And I login to Google as "customer" with password "password"
@bullfight
bullfight / example.rb
Created September 28, 2011 11:26
example of need for negation of join
class Cat < ActiveRecord::Base
belongs_to :owner
end
class Owner < ActiveRecord::Base
has_one :cat
scope :adoptable lambda { includes(:cat).
where(:cat => {:id => nil}) }
scope :adopted, lambda { joins(:cat) }
@bullfight
bullfight / factories.rb
Created September 13, 2011 13:14 — forked from cblunt/factories.rb
Simulate paperclip attachments with FactoryGirl in Rails 3
Factory.define :application do |factory|
factory.attachment :sample, "public/samples/sample.doc", "application/msword"
end
<script type="text/javascript">
var queueBytesLoaded = 0;
var queueBytesTotal = 0;
var myQueue = null;
var queueChangeHandler = function(queue){
// alert('Uploading Started');
myQueue = queue;
// console.log("COLLECTION CHANGE!");
var list = document.getElementById('file_todo_list');
// This is my handler in the javascript
var uploadCompleteHandler = function(upload_options,event){
$.ajax({
url: '<%= notify_rails_of_successful_upload_path(:format => :js)%>',
global: false,
type: 'POST',
data: ({
'authenticity_token' : '<%= form_authenticity_token %>',
'upload' : {
'file_file_name' : upload_options.FileName,