Skip to content

Instantly share code, notes, and snippets.

Darren Terhune darrenterhune

Block or report user

Report or block darrenterhune

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@darrenterhune
darrenterhune / active_admin_export_worker.rb
Last active Jun 30, 2019
Simple activeadmin export full table csv using a sidekiq background worker
View active_admin_export_worker.rb
# 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)
View compare_less_vs_scss.rb
#!/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!("-", "_")
@darrenterhune
darrenterhune / hooks_generator.rb
Created Mar 20, 2019
Hook into rails model generators to update a scope that requires changes each time a new model is added
View hooks_generator.rb
# 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'
@darrenterhune
darrenterhune / quote_csv.rb
Created Oct 11, 2018
Add quotes to a csv file directly in the terminal
View quote_csv.rb
# 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)'
@darrenterhune
darrenterhune / rails_install.md
Last active Jul 11, 2018
Installing rails without the initial gem install rails
View rails_install.md

Installing Rails w/o gem install

mkdir -p ~/Sites/myapp
cd ~/Sites/myapp
echo 2.4.2 > .ruby-version
rbenv install 2.4.2
bundler init
echo "source 'https://rubygems.org'" > Gemfile
echo "ruby '2.4.2'" >> Gemfile
@darrenterhune
darrenterhune / wordpress_wp_config.php
Last active Jan 27, 2018
Wordpress wp-config.php settings
View wordpress_wp_config.php
$table_prefix = 'wp_RANDOMUUID-HERE';
define('WP_AUTO_UPDATE_CORE', true);
define('WP_POST_REVISIONS', false);
define('FORCE_SSL_ADMIN', true);
@darrenterhune
darrenterhune / passwordless_ssh.zsh
Last active Jan 17, 2018
Dreamhost passwordless login
View passwordless_ssh.zsh
scp ~/.ssh/id_rsa.pub user@example.com:~/
ssh user@example.com
mkdir .ssh
cat id_rsa.pub >> .ssh/authorized_keys
rm id_rsa.pub
chmod go-w ~
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
View failure.rb
# 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)
View reset mysql root user password
# 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 &
View capybara_cheetsheet.rb
# SCOPING
within(*find_args) # within('div#delivery-address') do
within(a_node) # fill_in('Street', with: '12 Main Street')
# end
# MATCHERS
have_select(locator, options = {}) # expect(page).to have_select('id', options: ['Yes', 'No'])
# expect(page).to have_select('id', options: [1,2,3], selected: 2)
have_field(locator, options = {}) # expect(page).to have_field('id', placeholder: 'What city do you live in?')
# expect(page).to have_field('id', with: 'Some value', visible: false)
You can’t perform that action at this time.