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 MyControllerOrPlainRubyObject | |
| extend CodedOptions | |
| coded_options :state, %w(initial active closed) | |
| STATES = %w(initial active closed) | |
| STATE_OPTIONS = [["initial", 0], | |
| ["active", 1], | |
| ["closed", 2]] |
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 Data.List | |
| import Text.Printf | |
| import Numeric | |
| tolerance :: Double | |
| tolerance = 1e-2 | |
| e :: Double | |
| e = 2.718281828 |
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
| getPixels :: Image -> IO [[Color]] | |
| getPixels image = | |
| do (width, height) <- imageSize image | |
| pixelsPointer <- withImagePtr image $ | |
| \gdi -> #{peek gdImage, tpixels} gdi | |
| columnPixelArray <- peekArray height pixelsPointer | |
| mapM (\a -> peekArray width a) columnPixelArray |
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
| getPixel :: Point -> Image -> IO Color | |
| getPixel (x,y) i = | |
| withImagePtr i $ | |
| \p -> gdImageGetTrueColorPixel p (int x) (int y) |
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 'algebra' | |
| class IRR | |
| def self.calculate(profits) | |
| begin | |
| function(profits).zero | |
| rescue Algebra::MaximumIterationsReached => mir | |
| nil | |
| 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
| module Algebra | |
| class MaximumIterationsReached < Exception | |
| end | |
| class NewtonsMethod | |
| def self.calculate(function, x) | |
| x - function.evaluated_at(x) / function.derivative_at(x) | |
| 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 CreditCard < ActiveRecord::Base | |
| belongs_to :order | |
| has_one :billing_address, :as => :addressable, :class_name => "Address", :dependent => :destroy | |
| accepts_nested_attributes_for :billing_address | |
| before_validation :clean_number |
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 Courier < ActionMailer::Base | |
| CIPHER = ActiveSupport::MessageEncryptor.new("redacted", "aes-256-cbc") | |
| module ClassMethods | |
| delegate :encrypt, :to => :"Courier::CIPHER" | |
| def valid_email_address? email_address | |
| (not email_address.blank?) and email_address.include?("@") | |
| 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
| POSSCON = Conference.create(:awesome => true) do | |
| starts_on "2010-04-15" | |
| ends_on "2010-04-17" | |
| speakers %w(Obie Yehuda Wanstrath) | |
| end | |
| POSSCON.include?(self) or fail |
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
| @client.diagnoses.include? Diagnosis.get(:hiv) |