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 Array | |
def contains_sum?(n) | |
return false if n.nil? | |
low = 0 | |
high = 0 | |
sum = first | |
while sum != n && low < size | |
if sum < n || low == high | |
return false if high == size - 1 |
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
# Upload local file at filepath to <fog_directory>/directory/filename | |
def upload_file(filepath, directory, filename: nil, acl: 'public-read') | |
filename ||= File.basename(filepath) | |
s3 = Aws::S3::Resource.new(region: region) | |
obj = s3.bucket(bucket).object("#{directory}/#{filename}") | |
obj.upload_file(filepath, acl: acl) | |
end | |
# Download file from <fog_directory>/remote_filepath to local filepath |
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 IndexSearchable | |
extend ActiveSupport::Concern | |
class_methods do | |
def search(options = {}) | |
queries = searchable_terms.map { |term| term_search(term, options[term.to_sym]) } | |
queries << query_search(options[:query]) | |
queries.compact.reduce(:merge) | |
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 MorePluckable | |
extend ActiveSupport::Concern | |
class_methods do | |
def pluck_in_batches(*column_names, batch_size: 1000) | |
column_names = column_names.map(&:to_sym) | |
column_names.delete(:id) | |
column_names.unshift(:id) | |
data = [] |
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
[development] # CREATE TABLE test (id integer, name text); | |
[development] # ALTER TABLE test ADD CHECK (name is not null) NOT VALID; | |
[development] # \d test | |
Table "public.test" | |
Column | Type | Modifiers | |
--------+---------+----------- | |
id | integer | | |
name | text | | |
Check constraints: | |
"test_name_check" CHECK (name IS NOT NULL) NOT VALID |
OlderNewer