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
users_file = Rails.root.join('storage', 'users.yml.erb') | |
if File.exist? users_file | |
users = YAML.load(ERB.new(File.read(users_file)).result) | |
User.insert_all( | |
users.map { |user| user.except("password") }, | |
unique_by: :username | |
) | |
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
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'activerecord', require: 'active_record' | |
gem 'sqlite3' | |
gem 'lockbox', git: 'https://github.com/ankane/lockbox.git' | |
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
# USAGE: Hash.from_xml:(YOUR_XML_STRING) | |
require 'nokogiri' | |
# modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#1231297 | |
class Hash | |
class << self | |
def from_xml(xml_io) | |
begin | |
result = Nokogiri::XML(xml_io) | |
return { result.root.name.to_sym => xml_node_to_hash(result.root)} |
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
def fit_dimensions( original, target ) | |
original_ratio = original[:height].to_f / original[:width].to_f | |
target_ratio = target[:height].to_f / target[:width].to_f | |
result = target.clone | |
case original_ratio <=> target_ratio | |
when -1 then result[:height] = target[:width].to_f * original_ratio | |
when 1 then result[:width] = target[:height].to_f / original_ratio | |
end | |
return result | |
end |