This file contains 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
[ | |
{ | |
"code": "ARI", | |
"name": "Cardinals", | |
"full_name": "Arizona Cardinals" | |
}, | |
{ | |
"code": "ATL", | |
"name": "Falcons", | |
"full_name": "Atlanta Falcons" |
This file contains 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 'csv' | |
def dump_relation(file_name, relation) | |
File.open(file_name, 'w') do |file| | |
# Load the data once | |
records = relation.to_a | |
# Write headers | |
file.puts records.first.attributes.keys.to_csv | |
# Write records | |
records.each { |record| file.puts record.attributes.values.to_csv } |
This file contains 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
# Before | |
Rails.application.config.assets.version = '1.0' | |
Rails.application.config.assets.paths << Emoji.images_path | |
Rails.application.config.assets.precompile += %w( search.js ) | |
# After | |
Rails.application.config.assets.tap do |assets| | |
assets.version = '1.0' | |
assets.paths << Emoji.images_path | |
assets.precompile += %w( search.js ) |
This file contains 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
Show hidden characters
{ | |
"folders": | |
[ | |
{ | |
"file_exclude_patterns": | |
[ | |
"*.sqlite3" | |
], | |
"folder_exclude_patterns": | |
[ |
This file contains 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 DateRangeParams | |
extend ActiveSupport::Concern | |
included do | |
helper_method :start_date | |
helper_method :end_date | |
helper_method :date_range | |
def self.set_default_end_date(&block) | |
@default_end_date = block |
This file contains 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 'benchmark/ips' | |
MONDO_HASH = (1..50).each_with_object({}) { |num, hash| | |
hash[num.to_s] = num | |
} | |
# Monkey-patching a map_values to test; this should probably be a refinement | |
class Hash | |
def map_values | |
merge({}) { |key, value| yield(value) } |
This file contains 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
# This file lives in `app/.elasticbeanstalk/config.yml.erb` | |
branch-defaults: | |
master: | |
environment: <%= eb_environment %> | |
# environment: contigo-worker-env # Enable for worker | |
# Put global configs below! |
This file contains 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 WholeNumberValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
unless value =~ /\A\d+\.0*\z/ | |
record.errors[attribute] << (options[:message] || "must be a whole number") | |
end | |
end | |
end |
This file contains 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
# Processes CSV compiled from http://names.mongabay.com/most_common_surnames.htm | |
# into a surnames text file and a CSV | |
require 'csv' | |
require 'active_support/core_ext/string' | |
surnames_data = {} | |
def process_name(name) | |
# Format names like McCallister |
This file contains 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
unless File.exist?('Gemfile') | |
File.write('Gemfile', <<-GEMFILE) | |
source 'https://rubygems.org' | |
gem 'rails', github: 'rails/rails' | |
gem 'arel', github: 'rails/arel' | |
gem 'sqlite3' | |
GEMFILE | |
system 'bundle' | |
end |