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
#!/usr/bin/env ruby | |
### USAGE: `./convert_slim_to_erb path/to/views/` | |
### LIMITATIONS: | |
### - Does not add closing tags such as `<% end %>` or `</div>` | |
SELF_CLOSING_TAGS = ["input","br","hr","img","meta","area","base","col","embed","link","source","track","wbr","param"].freeze | |
@line = nil |
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
DATE_FORMAT = "%F".freeze ### Rails default is "%m/%d/%Y" | |
TIME_FORMAT = "#{DATE_FORMAT} %l:%M%p %Z".freeze | |
format_defaults = { | |
date_time12: TIME_FORMAT, | |
date_time24: "#{DATE_FORMAT} %H:%M %Z".freeze, | |
}.freeze | |
Date::DATE_FORMATS.merge!(format_defaults.merge({default: DATE_FORMAT})) | |
Time::DATE_FORMATS.merge!(format_defaults.merge({default: TIME_FORMAT})) |
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
### config/initializers/arel_sql_monkey_patch.rb | |
ActiveRecord::Relation.class_eval do | |
### FIX ERRORS FOR Arel.sql in Rails 6+ | |
### FIX DEPRECATION WARNINGS FOR Arel.sql in Rails =5.2 | |
if Rails::VERSION::STRING.to_f >= 5.2 | |
def pluck(*args) | |
if args.any?{|x| x.is_a?(String) } | |
new_args = args.map{|x| x.is_a?(String) ? Arel.sql(x) : x } |
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
app_path = File.expand_path(File.dirname(__FILE__) + '/..') | |
log_tmp_path = File.expand_path(app_path + '/..') | |
#directory '/home/deploy/my_app' | |
### TO VIEW PUMA LOGS USE, `journalctl -u puma` | |
### TO SEND PUMA LOGS TO FILE SEE BELOW | |
#stdout_redirect '/home/deploy/tmp/puma-stdout.log', '/home/deploy/tmp/puma-stderr.log', true | |
# Puma can serve each request in a thread from an internal thread pool. |
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 sample_pdf_upload | |
sample_path = Rails.root.join("spec/fixtures/sample_file.pdf") | |
#fixture_file_upload(sample_path, 'application/pdf') ### MINITEST | |
Rack::Test::UploadedFile.new(sample_path) ### RSPEC | |
end | |
def sample_csv_upload | |
sample_path = Rails.root.join("spec/fixtures/sample_file.csv") | |
#fixture_file_upload(sample_path, 'text/csv') ### MINITEST | |
Rack::Test::UploadedFile.new(sample_path) ### RSPEC |
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 'capybara/rails' | |
require 'capybara/rspec' | |
require 'rack/handler/puma' | |
require 'selenium/webdriver' | |
# Default cache time of 24 hours before webdrivers checks for new versions | |
Webdrivers.cache_time = 24.hours.to_i | |
# Logging levels are :info (more verbosity), :warn (default), :error, etc |
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
conn = ActiveRecord::Base.connection | |
if conn.adapter_name.downcase == "sqlite" | |
### Write-Ahead Logging - https://sqlite.org/wal.html | |
### - Pros: Better Concurrency, Faster | |
### - Cons: All DB access must be from the same host | |
### TODO: Future Improvements (2019/2020) | |
### WAL2 & 'BEGIN CONCURRENT' | |
### https://stackoverflow.com/a/54475279/3068360 |
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
window.generate_params_query_string = function(json){ | |
if(typeof json == 'string'){ | |
json = JSON.parse(json); | |
} | |
var params_str_array = []; | |
var parse_plain_value = function(current_obj, current_prefix){ | |
var strParam = current_prefix + "=" + encodeURIComponent(current_obj); | |
params_str_array.push(strParam); |
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 Forms::BaseForm | |
include ActiveModel::Validations | |
def initialize(attrs={}) | |
attrs ||= {} | |
attrs.each do |k,v| | |
self.send("#{k}=", v) ### Use send so that it checks that attr_accessor has already defined the method so its a valid attribute | |
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
### USE YAML BACKEND FOR THIS SCRIPT | |
I18n.backend = I18n::Backend::Simple.new | |
namespace :translations do | |
task yaml_export: :environment do | |
base_path = Rails.root.join("config/locales/export/") | |
FileUtils.mkdir_p(base_path) |