mkdir -p ~/Sites/myapp
cd ~/Sites/myapp
echo 3.3.5 > .ruby-version
rbenv install 3.3.2
bundler init
echo "source 'https://rubygems.org'" > Gemfile
echo "ruby '3.3.5'" >> Gemfile
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 UsersController < ApplicationController | |
before_action :set_user, only: %i[ show edit update destroy ] | |
# GET /users or /users.json | |
def index | |
@users = User.all | |
end | |
# GET /users/1 or /users/1.json | |
def show |
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
#<RuboCop::Cop::Registry:0x00007fec7340f7b0 | |
@cops_by_cop_name= | |
{"Migration/DepartmentName"=>[RuboCop::Cop::Migration::DepartmentName], | |
"Bundler/DuplicatedGem"=>[RuboCop::Cop::Bundler::DuplicatedGem], | |
"Bundler/GemComment"=>[RuboCop::Cop::Bundler::GemComment], | |
"Bundler/InsecureProtocolSource"=>[RuboCop::Cop::Bundler::InsecureProtocolSource], | |
"Bundler/OrderedGems"=>[RuboCop::Cop::Bundler::OrderedGems], | |
"Gemspec/DuplicatedAssignment"=>[RuboCop::Cop::Gemspec::DuplicatedAssignment], | |
"Gemspec/OrderedDependencies"=>[RuboCop::Cop::Gemspec::OrderedDependencies], | |
"Gemspec/RequiredRubyVersion"=>[RuboCop::Cop::Gemspec::RequiredRubyVersion], |
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
# frozen_string_literal: true | |
module WithinTables | |
# Use to test the values of columns for certain row | |
# | |
# Add <tt>offset</tt> to start matching at a certain column | |
# | |
# %tr | |
# %td Hi | |
# %td Hello |
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 | |
# frozen_string_literal: true | |
class String | |
def underscore | |
return self unless /[A-Z-]|::/.match?(self) | |
word = to_s.gsub("::", "/") | |
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2') | |
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2') | |
word.tr!("-", "_") |
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/environments/development.rb | |
config.generators do |generator| | |
generator.orm :hooks | |
end | |
# lib/generators/rails/hooks/hooks_generator.rb | |
require 'rails/generators/active_record/model/model_generator' |
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
# Run this in terminal, then paste in csv into terminal window | |
# https://stackoverflow.com/questions/17157850/quotation-mark-into-csv-per-field-awk-sed/17158450#17158450 | |
ruby -rcsv -ne 'puts CSV.generate_line(CSV.parse_line($_), :force_quotes=>true)' |
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/workers/active_admin_export_worker.rb | |
class ActiveAdminExportWorker | |
include Sidekiq::Worker | |
sidekiq_options queue: 'high' | |
def perform(options = {}) | |
model = options[:model_name].classify.constantize | |
path = "#{Rails.root.to_s}/tmp/#{filename(options[:name])}" | |
columns = model.send(:column_names) |
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
# frozen_string_literal: true | |
require 'rails_helper' | |
feature 'Updating Admin Clinics feature' do | |
let(:admin) { create(:admin) } | |
let!(:clinic) { create(:clinic) } | |
before do | |
login_as(admin, scope: :user) |
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
# Found from https://coderwall.com/p/j9btlg/reset-the-mysql-5-7-root-password-in-ubuntu-16-04-lts | |
# Stop MySQL | |
sudo service mysql stop | |
# Make MySQL service directory. | |
sudo mkdir /var/run/mysqld | |
# Give MySQL user permission to write to the service directory. | |
sudo chown mysql: /var/run/mysqld | |
# Start MySQL manually, without permission checks or networking. | |
sudo mysqld_safe --skip-grant-tables --skip-networking & |
NewerOlder