Skip to content

Instantly share code, notes, and snippets.

gem 'bootstrap-sass'
gem 'bcrypt-ruby', '~> 3.1.2'
gem_group :development, :test do
gem 'debugger'
end
gem_group :development do
gem 'commands'
Rails.if __FILE__ == $PROGRAM_NAME
$stdout.puts ENV['ouch']['ouch']
end
@delba
delba / connect.rb
Last active August 29, 2015 13:56
Gribouillis / Scrawl
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)
# 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
@delba
delba / stripe_charger.rb
Created March 28, 2014 00:39
Processing payment in a queue
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
@delba
delba / Terminal.coffee
Created April 22, 2014 14:46
Polling bank account status
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"}
@delba
delba / charge.coffee
Created April 22, 2014 14:48
Charge with Backbone
class @Charge extends Backbone.Model
@statusUrl = '/charges/status'
defaults:
currency: 'usd'
initialize: ->
@on 'change:number', @setType
@on 'change:number', @validateNumber
@on 'change:expiry', @validateExpiry
@delba
delba / callback.rb
Created April 22, 2014 14:50
Stripe callback
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]
@delba
delba / expert.rb
Created April 22, 2014 14:51
Weekly notification draft
class Expert < ActiveRecord::Base
include Notifiable
has_many :trackings do
def recent
where('created_at >= ?', proxy_association.owner.notified_at)
end
end
end
import UIKit
class PlayViewController: UIViewController {
var label: UILabel?
override func viewDidLoad() {
super.viewDidLoad()