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 Mergesort | |
def self.sort(array) | |
return array if array.length <= 1 | |
middle = array.length/2 | |
left = sort(array[0..(middle-1)]) | |
right = sort(array[middle..-1]) | |
merge(left, right) | |
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
# Gemfile | |
gem "linkedin" | |
gem "omniauth" | |
gem "omniauth-linkedin" |
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 PersistenceTest | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
BRAINTREE_SYNC_STATUSES = %w(new synced changed) | |
# | |
# Top-level Fields | |
# | |
field :terms_accepted_at, :type => DateTime |
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
#!/usr/bin/env ruby | |
inputs = { | |
'a' => 18, | |
'b' => 13, | |
'c' => 9 | |
} | |
total = inputs.values.inject{|sum,x| sum + x } |
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
tail -n 10000 log/development.log | egrep -n '(Load|SQL|AREL|Request) \([2-9][0-9]{2,}.[0-9]ms\)' |
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
#!/usr/bin/env ruby | |
# Migrate local Refinery images & resources to S3. | |
# Assumes you've set up an AWS::S3 connection | |
# elsewhere (I have an initializer that does it). | |
image_classes = [Image] | |
data_classes = [Resource] | |
def upload(path, file, bucket, retries = 3) |
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 School < ActiveRecord::Base | |
scope :show_first, lambda{|val| order("(case country when '#{val}' then 0 else 1 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
class BlogPost < ActiveRecord::Base | |
# This Model has, in addition to title and other usual fields, | |
# two fields for creating custom urls: | |
# | |
# :use_custom_url, :boolean | |
# :custom_url, :string | |
validates :title, :presence => true, :uniqueness => true |