This file contains hidden or 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 'json' | |
| require 'stripe' | |
| Stripe.api_key = 'sk_test_wEA2idIv05QuQH4RLu8hz8PA' | |
| event = JSON.parse File.read('event.json'), | |
| symbolize_names: true | |
| if event[:type] == 'charge.succeeded' | |
| charge = event[:data][:object] |
This file contains hidden or 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
| class @Charge extends Backbone.Model | |
| @statusUrl = '/charges/status' | |
| defaults: | |
| currency: 'usd' | |
| initialize: -> | |
| @on 'change:number', @setType | |
| @on 'change:number', @validateNumber | |
| @on 'change:expiry', @validateExpiry |
This file contains hidden or 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
| Started GET "/bank_account/status?id=11" for 127.0.0.1 at 2014-04-08 10:40:21 -0700 | |
| Processing by BankAccountsController#status as JSON | |
| Parameters: {"id"=>"11"} | |
| BankAccount Load (0.2ms) SELECT "bank_accounts"."id", "bank_accounts"."status" FROM "bank_accounts" WHERE "bank_accounts"."id" = $1 LIMIT 1 [["id", 11]] | |
| Completed 200 OK in 1ms (Views: 0.1ms | ActiveRecord: 0.2ms) | |
| Started GET "/bank_account/status?id=11" for 127.0.0.1 at 2014-04-08 10:40:22 -0700 | |
| Processing by BankAccountsController#status as JSON | |
| Parameters: {"id"=>"11"} |
This file contains hidden or 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
| class StripeCharger | |
| include Sidekiq::Worker | |
| def perform(charge_id) | |
| @charge = Charge.find(charge_id) | |
| begin | |
| stripe_charge = Stripe::Charge.create(charge_params) | |
| @charge.update stripe: stripe_charge.to_json | |
| rescue Stripe::CardError => e |
This file contains hidden or 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
| # As a first example, let's consider an "adjacency list", a tree represented in a table. Suppose we have a table comments, representing a threaded discussion: | |
| comments = Arel::Table.new(:comments) | |
| # [:id, :body, :parent_id] | |
| replies = comments.alias | |
| comments_with_replies = \ | |
| comments.join(replies).on(replies[:parent_id].eq(comments[:id])) | |
| # => SELECT * FROM comments INNER JOIN comments AS comments_2 WHERE comments_2.parent_id = comments.id |
This file contains hidden or 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
| class ConnectController | |
| def authorize | |
| redirect_to stripe_authorize_url | |
| end | |
| def callback | |
| if code = params[:code] | |
| auth_token = client.auth_code.get_token(code) | |
| current_user.update!(token: auth_token) |
This file contains hidden or 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
| Rails.if __FILE__ == $PROGRAM_NAME | |
| $stdout.puts ENV['ouch']['ouch'] | |
| end |
This file contains hidden or 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
| gem 'bootstrap-sass' | |
| gem 'bcrypt-ruby', '~> 3.1.2' | |
| gem_group :development, :test do | |
| gem 'debugger' | |
| end | |
| gem_group :development do | |
| gem 'commands' |
This file contains hidden or 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
| class Person | |
| @all = [] | |
| def self.all | |
| @all | |
| end | |
| def self.where(conditions) | |
| all.select do |person| | |
| conditions.map do |k, v| |
This file contains hidden or 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
| module Macchiato | |
| class Application < Rails::Application | |
| config.autoload_paths += Dir[Rails.root.join('lib', 'validators').to_s] | |
| end | |
| end |