Skip to content

Instantly share code, notes, and snippets.

View mattscilipoti's full-sized avatar

Matt Scilipoti mattscilipoti

View GitHub Profile
@mattscilipoti
mattscilipoti / .powenv
Last active January 18, 2021 22:09 — forked from flarik/dot.powrc.sh
Pow's .powenv config file for use with RVM's config files .rvmrc or .ruby-version (+ optional .ruby-gemset)
#!/usr/bin/env bash
if [ -f "${rvm_path}/scripts/rvm" ]; then
source "${rvm_path}/scripts/rvm"
# use the config files
# .rvmrc supersedes all others
if [ -f ".rvmrc" ]; then
source ".rvmrc"
@mattscilipoti
mattscilipoti / gist:bd357b2413b1d0213afe95be5c4dc2a6
Created January 3, 2018 16:16
git: clean up local branches that have been deleted remotely
# 1. saves possible branches to file, opens in editor
# 2. remove branches you don't want to delete from the list and save.
git fetch --prune && git branch --no-color --merged | egrep -v "(^\*|master)" > /tmp/merged-branches && vi /tmp/merged-branches && xargs git branch -d < /tmp/merged-branches
@mattscilipoti
mattscilipoti / postgres.rake
Last active May 1, 2019 18:42
rake db:kill_postgres_connections
puts "WARN: We are patching rake tasks to support postgres. You have upgraded Rails and may not need this patch any more (lib/tasks/postgres.rake)." if Rails.version > "3.2.8"
namespace :db do
desc 'kills connections to postgres db'
task :kill_postgres_connections => :environment do
env = ENV['RAILS_ENV']
db_config = Rails.configuration.database_configuration[env]
fail(ArgumentError, "Could not find db config entry for env (#{env})") unless db_config
db_name = db_config['database']
@mattscilipoti
mattscilipoti / log_slow_queries.rb
Created February 20, 2011 05:10
Rails3: Log slow queries.
# see: http://weblog.therealadam.com/2011/02/12/simple-ruby-pleasures/comment-page-1/#comment-315
class QueryTracer < ActiveSupport::LogSubscriber
ACCEPT = %r{^(app|config|lib)}.freeze
FRAMES = 5
THRESHOLD = 300 # In ms
def sql(event)
return unless event.duration > THRESHOLD

Keybase proof

I hereby claim:

  • I am mattscilipoti on github.
  • I am mattscilipoti (https://keybase.io/mattscilipoti) on keybase.
  • I have a public key whose fingerprint is DFD4 1E67 9A6B C312 AA9F 2912 546F C3BA 8673 E21A

To claim this, I am signing this object:

require 'spec_helper'
RSpec.describe FactoryGirl do
# convention: "base" factories return valid models.
# without these tests, factories with invalid associations are difficult to identify and debug
# Note: performs build, not create.
describe 'all factories,' do
factories_to_skip = {}
@mattscilipoti
mattscilipoti / FasterRailsLoadTimes.md
Last active April 20, 2016 15:19
Faster Rails Load Times

Faster load times? (circa 2011)

  • Benchmark with:

        $ time script/rails runner "puts 1"
  • Dropped from 18 to 13s using :require => false judiciously in Gemfile.

  • (outdated with ruby 2.3, I think) Dropped from 13 to 8.5s using patched ruby:

@mattscilipoti
mattscilipoti / pre-push.sh
Last active January 3, 2016 06:39 — forked from pixelhandler/pre-push.sh
pre-push script: Protects some branches from destructive actions.
#!/usr/bin/env ruby
# NOTE! this is a work in progress. This is not tested or used regularly.
# Ensures we do not call destructive commands on protected branches.
#
# Called by "git push" after it has checked the remote status,
# but before anything has been pushed.
#
# If this script exits with a non-zero status nothing will be pushed.
@mattscilipoti
mattscilipoti / syntax_highlighter_footer.js
Created November 10, 2013 16:20
The snippets I use for blog.clearto.me
db_tasks = %w[db:migrate db:migrate:up db:migrate:down db:rollback db:seed db:version] # db:forward]
namespace :multitenant do
desc 'List all existing tenants/customers'
task :list => :environment do
puts Customer.all.collect &:name
end
#create a multitenant task for each db task
db_tasks.each do |task_name|