Skip to content

Instantly share code, notes, and snippets.

Avatar

Marc Ignacio padi

View GitHub Profile
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]+)'`
@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]+)'`
@padi
padi / gist:82f84fe73eca1b68f6c9cf4770a49040
Created Dec 6, 2017 — forked from giannisp/gist:ebaca117ac9e44231421f04e7796d5ca
Upgrade PostgreSQL 9.6.5 to 10.0 using Homebrew (macOS)
View gist:82f84fe73eca1b68f6c9cf4770a49040
After automatically updating Postgres to 10.0 via Homebrew, the pg_ctl start command didn't work.
The error was "The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 10.0."
Database files have to be updated before starting the server, here are the steps that had to be followed:
# need to have both 9.6.x and latest 10.0 installed, and keep 10.0 as default
brew unlink postgresql
brew install postgresql@9.6
brew unlink postgresql@9.6
brew link postgresql
@padi
padi / development.log
Last active Dec 6, 2017
chaos-app: GET /products on first load (development environment)
View development.log
Started GET "/products" for 127.0.0.1 at 2017-12-06 14:29:33 +0800
Processing by ProductsController#index as HTML
User Load (1.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 2], ["LIMIT", 1]]
Spree::Preference Load (4.0ms) SELECT "spree_preferences".* FROM "spree_preferences" WHERE "spree_preferences"."key" = $1 LIMIT $2 [["key", "spree/app_configuration/currency"], ["LIMIT", 1]]
Spree::Store Load (5.3ms) SELECT "spree_stores".* FROM "spree_stores" WHERE (url like '%tsi.lvh.me%') ORDER BY "spree_stores"."id" ASC LIMIT $1 [["LIMIT", 1]]
Spree::Store Load (6.3ms) SELECT "spree_stores".* FROM "spree_stores" WHERE "spree_stores"."default" = $1 ORDER BY "spree_stores"."id" ASC LIMIT $2 [["default", "t"], ["LIMIT", 1]]
Spree::Order Load (2.8ms) SELECT "spree_orders".* FROM "spree_orders" WHERE "spree_orders"."completed_at" IS NULL AND "spree_orders"."currency" = $1 AND "spree_orders"."guest_token" = $2 AND "spree_orders"."store_id" = $3
@padi
padi / evaluate_multiline_script.rb
Created Sep 11, 2017 — forked from beccasaurus/evaluate_multiline_script.rb
Capybara helper for calling evaluate_script with multiple lines of JavaScript, supporting short-circuit return statements, etc etc. Just wraps your JS in a function and then calls it.
View evaluate_multiline_script.rb
# Given a multiline script, this will wrap the script in a function and then
# call it so Capybara's evaluate_script knows how to get the return value properly.
# By default, Capybara just prepends a 'return ' to your script.
#
# Usage:
#
# value = page.evaluate_multiline_script %{
# var foo = [];
# $('li').each(function(i, li) {
# foo[foo.length] = $(li).text();
@padi
padi / no_animations.rb
Created Sep 8, 2017 — forked from keithtom/no_animations.rb
Rack Middleware to disable Disable CSS3/jQuery Animations for Capybara
View no_animations.rb
module Rack
# disable CSS3 and jQuery animations in test mode for speed, consistency and avoiding timing issues.
# Usage for Rails:
# in config/environments/test.rb
# config.middleware.use Rack::NoAnimations
class NoAnimations
def initialize(app, options = {})
@app = app
end
@padi
padi / kill_rubies.sh
Created Aug 17, 2017
Script to kill all spring and rogue ruby processes
View kill_rubies.sh
#!/bin/sh
ps aux | grep ruby | grep -v grep | awk '{print $2}' | xargs kill
@padi
padi / run_rubocop_in_branch.sh
Created Feb 14, 2017
Check rubocop against file changes in your feature-branch (compared to origin/master)
View run_rubocop_in_branch.sh
git diff origin/master --name-only --diff-filter=ACMR | grep '.rb' | grep -v 'schema' | xargs rubocop -c .rubocop.yml --force-exclusion --display-cop-names
@padi
padi / run_rubocop_in_branch.sh
Created Feb 14, 2017
Check rubocop against file changes in your feature-branch (compared to origin/master)
View run_rubocop_in_branch.sh
git diff origin/master --name-only --diff-filter=ACMR | grep '.rb' | ag -v 'schema' | xargs rubocop -c .rubocop.yml --force-exclusion --display-cop-names