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 Page < ActiveRecord::Base | |
| has_attached_file :image, sizes: {small: '10x10', large: '100x100'} | |
| has_attached_file :uploaded_image | |
| def safe_image_url | |
| if image | |
| image_url | |
| else | |
| 'spinner.gif' | |
| 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
| #import <Foundation/Foundation.h> | |
| #import <UIKit/UIKit.h> | |
| @interface ErrorFormatter : NSObject | |
| @property (strong, nonatomic) NSError *error; | |
| - (id)initWithError:(NSError *)error; | |
| - (UIAlertView *)alert; |
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 TeamFactory | |
| class PageValue < OpenStruct.new(:page, :name) | |
| end | |
| def self.build_from_individual_page page, name = nil, builder = self | |
| value = PageValue.new page, name | |
| team = builder.build_team value | |
| team_page = builder.build_team_page value | |
| builder.persist! team, team_page | |
| team |
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
| # When using dependency injection, I often find myself storing the dependency as | |
| # an attribute on the object. This is fine, except when you squint at the class there | |
| # looks to be more methods then what's really needed to understand the class. | |
| # | |
| # A typical class with dependency injection might look like this | |
| class TimeParam | |
| attr_writer :parser | |
| def initialize value | |
| @value = value |
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
| # Person has a polymorphic relationship called contactable. | |
| # We want the person's contactable method to return a contact | |
| # of our choosing. | |
| contact = Contact.new | |
| real_person = Person.find(1) | |
| mock_person = SimpleMock.new(real_person) | |
| mock_person.expect(:contactable, contact) | |
| mock_person.contact == contact # => true |
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 Countable | |
| def self.included do | |
| define_method "#{self.name}s" do | |
| # ... | |
| end | |
| end | |
| def self.name | |
| self.class.to_s.sub('FeedItem', '').downcase | |
| 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
| Upgrade rails to 2.3.9. | |
| 2.3.9 fixes a bug that we had come to depend on | |
| (https://github.com/rails/rails/pull/7661). It's best described with an | |
| example | |
| 2.3.8 | |
| p = Plan.new | |
| p.member = Member.first |
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
| <h1>New Plan</h1> | |
| <div ng-app> | |
| <%= form_for @plan do |form| %> | |
| <div ng-controller="PollCtrl" ng-init="polls = <%= @plan.polls.to_json %>"> | |
| <div ng-repeat="poll in polls"> | |
| <%= form.fields_for :polls, Poll.new, child_index: '{{$index}}' do |poll_form| %> | |
| <%= poll_form.text_field :title, id: 'plan_poll_{{$index}}', value: '{{poll.title}}' %> | |
| <% end %> | |
| <a href="#" ng-click="remove($index)" ng-show="isRemovable()">Remove</a> | |
| </div> |
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
| # Known poll types. Unknown types will raise | |
| # an exception. | |
| # | |
| # Poll::ChoiceTypes.time # => 'Choice::Time' | |
| # | |
| # @return [Struct] | |
| ChoiceTypes = Struct.new(:time, :place, :text).new.tap do |types| | |
| types.time = 'Choice::Time' | |
| types.place = 'Choice::Place' | |
| types.text = 'Choice::Text' |
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 RubyExample | |
| CONSTANT = /^[0-9]+ regex awesomes$/ | |
| attr_reader :colorscheme | |
| def initialize(attributes = {}) | |
| @colorscheme = attributes[:colorscheme] | |
| end | |
| def self.values |