Skip to content

Instantly share code, notes, and snippets.

View mattscilipoti's full-sized avatar

Matt Scilipoti mattscilipoti

View GitHub Profile
#!/usr/bin/ruby
#
# I deliberately didn't DRY /usr/local references into a variable as this
# script will not "just work" if you change the destination directory. However
# please feel free to fork it and make that possible.
#
# If you do fork, please ensure you add a comment here that explains what the
# changes are intended to do and how well you tested them.
#
# 30th March 2010:
if 'SQLite' == ActiveRecord::Base.connection.adapter_name && !defined?(JRUBY_VERSION) #SQLite3 returns SQLite as well.
raise "You have upgraded rails. These monkey patches may no longer be needed. Please remove, if possible." if RAILS_GEM_VERSION != '2.3.5'
ActiveRecord::ConnectionAdapters::SQLiteAdapter.class_eval do
#Fixes issue dumping schema for files with defined primary key.
#see: http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1153-make-schemadumper-dump-primary-keys-not-named-id-correctly-in-sqlite3
def pk_and_sequence_for(table_name) #:nodoc:
[primary_key(table_name), nil]
end
end
#
# = Capistrano database.yml task
#
# Provides a couple of tasks for creating the database.yml
# configuration file dynamically when deploy:setup is run.
#
# Category:: Capistrano
# Package:: Database
# Author:: Simone Carletti <weppos@weppos.net>
# Copyright:: 2007-2009 The Authors
require 'formula'
class Dialog <Formula
url 'ftp://invisible-island.net/dialog/dialog.tar.gz'
homepage 'http://en.wikipedia.org/wiki/Dialog_(software)'
# wikipedia page is more complete than (and contains link to)
# homepage 'http://invisible-island.net/dialog/'
md5 '519c0a0cbac28ddb992111ec2c3f82aa'
version '1.1.20070704'
@mattscilipoti
mattscilipoti / all_factories_spec.rb
Created January 3, 2011 19:53
Ensures all factories are valid (with exceptions)
require 'spec_helper'
describe Factory 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 = {}
factories_to_skip[:user_session] = "You must activate the Authlogic::Session::Base.controller with a controller object before creating objects"
@mattscilipoti
mattscilipoti / gist:807831
Created February 2, 2011 15:22
#cucumber IRC fragment: team thought the app could only be tested manually
19:03 <#cucumber> cheezyworking with a team close to my home
19:05 <#cucumber> cheezywe are wrapping cukes around a telephone queueing and routing system
19:05 <#cucumber> cheezywicked stuff
19:05 <#cucumber> aslakhellesoy_wow cool!
19:05 <#cucumber> aslakhellesoy_ui or headless cukes?
19:06 <#cucumber> cheezyit's all headless
19:06 <#cucumber> aslakhellesoy_i like headless - much faster
19:06 <#cucumber> cheezyi wrote a c layer that simulates the hardware and a ruby lib with ffi
19:06 <#cucumber> cheezyand a dsl over the lib
19:07 <#cucumber> cheezythe app doesn't really have a head - just c++
@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
# 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 / 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
@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