Skip to content

Instantly share code, notes, and snippets.

View mattscilipoti's full-sized avatar

Matt Scilipoti mattscilipoti

View GitHub Profile
@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|
@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 / rake-hooks(newly-minted).gemspec
Created June 19, 2012 14:20
gem rake-hooks (1) has an invalid gemspec
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/rake/hooks/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ["Matt Scilipoti"]
gem.email = ["matt@scilipoti.name"]
gem.description = %q{Is this valid?}
gem.summary = %q{I hope it is valid}
gem.homepage = ""
@mattscilipoti
mattscilipoti / cucumber.yml
Created June 6, 2012 14:58
cucumber.yml that moves rerun.txt to tmp (DRYly)
<%
# vars for default formats. These are overridden by command line args.default_format_multi = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'}"
default_format_single = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}"
html_report_options = " --format html --out='public/reports/features.html'"
# Use tmp dir for rerun.txt (vs. root)
rerun_file = File.join('tmp', 'rerun.txt')
rerun = File.file?(rerun_file) ? IO.read(rerun_file) : ""
rerun_format = "--format rerun --out #{ rerun_file }"
alias gst='git status '
alias gc='git commit '
alias gca='git commit -a '
alias ga='git add '
alias gco='git checkout '
alias gb='git branch '
alias gd='git diff '
alias gm='git merge '
alias gmm='git merge master'
alias gcom='git checkout master'
@mattscilipoti
mattscilipoti / postgres.rake
Created August 19, 2011 19:18
rake files for postgres support
#
# This patch makes structure dump a first class citizen
#
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.0.9"
Rake.application.remove_task('db:schema:dump')
Rake.application.remove_task('db:schema:load')
namespace :db do
namespace :schema do
@mattscilipoti
mattscilipoti / gist:1079638
Created July 13, 2011 03:09
sudo -i eybackup --download 44:cx_production
$ sudo -i eybackup --download 44:cx_production
WARNING: Nokogiri was built against LibXML version 2.7.2, but has dynamically loaded 2.7.3
Downloading gs_production.cx_production/cx_production.2011-07-12T07-18-21.sql.gz.part1 to /mnt/tmp
/usr/local/ey_resin/ruby/lib/ruby/gems/1.8/gems/excon-0.6.3/lib/excon/response.rb:72:in `<<': failed to allocate memory (NoMemoryError)
from /usr/local/ey_resin/ruby/lib/ruby/gems/1.8/gems/excon-0.6.3/lib/excon/response.rb:72:in `parse'
from /usr/local/ey_resin/ruby/lib/ruby/gems/1.8/gems/excon-0.6.3/lib/excon/connection.rb:163:in `request'
from /usr/local/ey_resin/ruby/lib/ruby/gems/1.8/gems/fog-0.7.2/lib/fog/core/connection.rb:20:in `request'
from /usr/local/ey_resin/ruby/lib/ruby/gems/1.8/gems/fog-0.7.2/lib/fog/storage/aws.rb:323:in `request'
from /usr/local/ey_resin/ruby/lib/ruby/gems/1.8/gems/fog-0.7.2/lib/fog/storage/requests/aws/get_object.rb:53:in `get_object'
from /usr/local/ey_resin/ruby/lib/ruby/gems/1.8/gems/fog-0.7.2/lib/fog/storage/models/aws/files.rb:44:in
# I'm in features/support/selectors.rb
module HtmlSelectorsHelper
def selector_for(scope)
case scope
when /the body/
"html > body"
else
begin
scope =~ /the (.*)/
@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