Skip to content

Instantly share code, notes, and snippets.

Avatar

Marc Ignacio padi

View GitHub Profile
@padi
padi / in_relentless_pursuit_of_rest_notes.md
Created Sep 9, 2020 — forked from benoittgt/in_relentless_pursuit_of_rest_notes.md
"In Relentless Pursuit of Rest" from Derek Prior
View in_relentless_pursuit_of_rest_notes.md
@padi
padi / 00_Heroku-Release-Phase-Review-Apps-Rails_README.md Heroku Release Phase script for managing Rails DB migrations, and playing nice with Review Apps and postdeploy scripts
View 00_Heroku-Release-Phase-Review-Apps-Rails_README.md

Heroku Release Phase + Review Apps + Rails

This is a simplified, but fairly thorough, set of scripts and configuration to enable Heroku Release Phase for Rails apps. Further, this particular set up plays nicely with Heroku Review Apps in that the release phase script will:

  1. Fail, loudly, if the DB does not yet exist.
  2. Load the DB schema if the current schema version (as determined by bin/rails db:version) is 0.
  3. Run DB migrations otherwise.

For a "normal" app that usually means it will run the DB migrations.

@padi
padi / fix_exfat_drive.md
Created Aug 27, 2020 — forked from scottopell/fix_exfat_drive.md
Fix corrupted exFAT disk macOS/OSX
View fix_exfat_drive.md

exFAT support on macOS seems to have some bugs because my external drives with exFAT formatting will randomly get corrupted.

Disk Utility is unable to repair this at first, but the fix is this:

  1. Use diskutil list to find the right drive id.
  2. You want the id under the IDENTIFIER column, it should look like disk1s1
  3. Run sudo fsck_exfat -d <id from above>. eg sudo fsck_exfat -d disk1s3
  4. -d is debug so you'll see all your files output as they're processed.
  5. Answer YES if it gives you the prompt Main boot region needs to be updated. Yes/No?
@padi
padi / Gemfile
Created Jul 9, 2020 — forked from dhh/Gemfile
HEY's Gemfile
View Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@padi
padi / db_fixtures_export.rake
Last active Apr 8, 2020 — forked from existentialmutt/db_fixtures_export.rake
Generate fixtures from db. Readable by rake db:fixtures:load
View db_fixtures_export.rake
# https://gist.github.com/kuboon/55d4d8e862362d30456e7aa7cd6c9cf5
namespace 'db:fixtures' do
desc "generate fixtures from the current database"
task :export => :environment do
Rails.application.eager_load!
models = defined?(ApplicationRecord) ? ApplicationRecord.descendants : ActiveRecord::Base.descendants
models.each do |model|
puts "exporting: #{model}"
@padi
padi / db_fixtures_export.rake
Created Apr 8, 2020 — forked from kuboon/db_fixtures_export.rake
Generate fixtures from db. Readable by rake db:fixtures:load
View db_fixtures_export.rake
# lib/tasks/db_fixtures_export.rake
namespace 'db:fixtures' do
desc "generate fixtures from the current database"
task :export => :environment do
Rails.application.eager_load!
models = defined?(AppicationRecord) ? ApplicationRecord.decendants : ActiveRecord::Base.descendants
models.each do |model|
puts "exporting: #{model}"
@padi
padi / original.db_fixtures_dump.rake
Last active Apr 8, 2020 — forked from ecleel/db_fixtures_dump.rake
Rails 5: Dump Rails db to fixtures (Fixed spacing in the latter)
View original.db_fixtures_dump.rake
# Original from http://snippets.dzone.com/posts/show/4468 by MichaelBoutros
#
# Optimized version which uses to_yaml for content creation and checks
# that models are ActiveRecord::Base models before trying to fetch
# them from database.
namespace :db do
namespace :fixtures do
desc 'Dumps all models into fixtures.'
task :dump => :environment do
models = Dir.glob(Rails.root + 'app/models/**.rb').map do |s|
@padi
padi / bench.sh
Created Mar 26, 2020 — forked from james2doyle/bench.sh
A website benchmarking script using Apache ab. This script hits a target with requests and then generates a small report for each case.
View bench.sh
#!/usr/bin/env bash
# idea from https://www.devside.net/wamp-server/load-testing-apache-with-ab-apache-bench
# if you are testing a base url, you need a trailing slash
SITE="http://example.com/"
OUTFILE="output.txt"
DIVIDER="\n====================================================================\n"
# if the file doesnt exist, make it
View gist:9e90f1bdbb947e2a97dbcd96f4a7e5cf

Setup

Replace IRB with Pry (in your Gemfile) and Byebug with pry-byebug.

gem 'pry-rails', group: [:development, :test]
gem 'pry-byebug', group: [:development, :test]

Using PRY

@padi
padi / post_checkout_migrations.sh
Created Mar 27, 2018 — forked from brysgo/post_checkout_migrations.sh
Post checkout hook for managing rails migrations and bundle install
View post_checkout_migrations.sh
CHECKING_OUT_BRANCH=$3
OLD_BRANCH=$1
NEW_BRANCH=$2
if [ $CHECKING_OUT_BRANCH -eq 1 ]
then
FILES_CHANGED=`git diff $OLD_BRANCH $NEW_BRANCH --name-status`
MIGRATIONS_REMOVED=`echo "$FILES_CHANGED" | egrep 'D\tdb/migrate/([0-9]+)' | sort -r`
MIGRATIONS_ADDED=`echo "$FILES_CHANGED" | egrep 'A\tdb/migrate/([0-9]+)'`