Skip to content

Instantly share code, notes, and snippets.

View jasondew's full-sized avatar

Jason Dew jasondew

View GitHub Profile
class MyControllerOrPlainRubyObject
extend CodedOptions
coded_options :state, %w(initial active closed)
STATES = %w(initial active closed)
STATE_OPTIONS = [["initial", 0],
["active", 1],
["closed", 2]]
import Data.List
import Text.Printf
import Numeric
tolerance :: Double
tolerance = 1e-2
e :: Double
e = 2.718281828
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
getPixel :: Point -> Image -> IO Color
getPixel (x,y) i =
withImagePtr i $
\p -> gdImageGetTrueColorPixel p (int x) (int y)
require 'algebra'
class IRR
def self.calculate(profits)
begin
function(profits).zero
rescue Algebra::MaximumIterationsReached => mir
nil
end
module Algebra
class MaximumIterationsReached < Exception
end
class NewtonsMethod
def self.calculate(function, x)
x - function.evaluated_at(x) / function.derivative_at(x)
end
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
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
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
@client.diagnoses.include? Diagnosis.get(:hiv)