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 SimpleDelegator | |
| def delegation_chain | |
| [self].tap do |output| | |
| object = self | |
| while object.respond_to?("__getobj__") | |
| object = object.__getobj__ | |
| output << object | |
| end | |
| end | |
| 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
| namespace :deploy do | |
| before :restart, :tag do | |
| on roles(:app) do | |
| within "#{deploy_to}/repo" do | |
| execute :git, "tag -f deployed-to-#{fetch(:stage)}" | |
| begin | |
| execute :git, "remote add upstream #{fetch(:repo_url)}" | |
| rescue | |
| # The remote might already exist. We don't care if it does. | |
| 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
| require 'rspec/matchers' | |
| module Suite | |
| class Table < Struct.new(:table) | |
| def rows | |
| @rows ||= table.all('tbody tr').map do |tr| | |
| tr.all('td').map(&:text) | |
| end | |
| end | |
| 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
| require 'date' | |
| require 'twitter' | |
| require 'dotenv' | |
| Dotenv.load | |
| class TwitterSearch | |
| def fetch(query) | |
| client.search("#{query} since:#{Date.today}").collect do |tweet| | |
| Tweet.new(tweet) | |
| 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
| class Account < ActiveRecord::Base | |
| has_many :users | |
| accepts_nested_attributes_for :users | |
| serialize :account #If you want to store the recurly account, you need to serialise the object | |
| validates_presence_of :company, :on => :create, :message => "can't be blank" | |
| # Before_create will be called once only | |
| before_create :create_external_account |
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 Foo < ActiveRecord::Base | |
| after_initialize :do_stuff | |
| def do_stuff | |
| self.parameter = "string" if self.parameter.nil? | |
| end | |
| 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
| trussell@whopper:~/Projects/app/$ php -a | |
| Interactive shell | |
| php > $foo = "16.83"; | |
| php > echo $foo; | |
| 16.83 | |
| php > $bar = (float) $foo; | |
| php > echo $bar; | |
| 16.83 | |
| php > $baz = $bar * 100; |
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 ContactController < ApplicationController | |
| def new | |
| @message = Message.new | |
| end | |
| def create | |
| @message = Message.new(params[:message]) | |
| if @message.valid? | |
| Contact.contact(@message).deliver |
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
| # Contact Mailer | |
| class Contact < ActionMailer::Base | |
| #default :to => "contact@advicecapital.dk" | |
| def contact(message, sender) | |
| @message = message | |
| @sender = sender | |
| mail( | |
| :from => sender, | |
| :to => "znowm4n@gmail.com", |
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 CreateLoginRecords < ActiveRecord::Migration | |
| def self.up | |
| create_table :login_records do |t| | |
| t.integer :user_id | |
| t.datetime :logged_in | |
| t.timestamps | |
| end | |
| add_index(:login_records, :user_id) | |
| add_index(:login_records, :logged_in) |
OlderNewer