Skip to content

Instantly share code, notes, and snippets.

@jch
jch / sql_explain.rb
Created October 31, 2011 21:12
lazy man's 'explain' method on active record scopes
module SqlExplain
extend ActiveSupport::Concern
module InstanceMethods
def explain
results = ActiveRecord::Base.connection.execute "EXPLAIN EXTENDED" + to_sql
Hash[results.fields.zip(results.first)]
end
end
end
@jch
jch / .gemrc
Created November 1, 2011 19:10
gemrc example
# http://docs.rubygems.org/read/chapter/11
---
gem: --no-ri --no-rdoc
benchmark: false
verbose: true
update_sources: true
sources:
- http://gems.rubyforge.org/
- http://rubygems.org/
backtrace: true
@jch
jch / project_management.md
Created November 3, 2011 14:44
project management cli

Services

  • [Mingle]
  • [Bugly] - single landing page, commit integration, rest api
  • [ActiveCollab] - one time fee $250 - $500, invoicing, time tracking
  • Splendid Bacon - project management for hackers
  • YouTrack - integrates w/ rest of jetBrains
  • PlanBox - chat, user feedback
@jch
jch / db_clean.md
Created November 11, 2011 16:52
transaction vs truncation for cleaning db's

Database cleaning

  • truncate prevents you from having seed data in test db

  • use txn whenever possible

  • use a separate environment for integration tests?

  • wish environments were inheritable so you can say:

    Environment.configure :integration, :parent => :development do

override configs here.

@jch
jch / vhost.txt
Created November 16, 2011 23:37
sample vhost
<Directory "/Users/jch/Sites/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
# lib/tasks/export.rake
require 'pathname'
def export(path)
path = Pathname.new('export' + path) # prefix a folder to export to to
path.dirname.mkpath # creates any intermediate folders
`curl http://localhost:3000/#{path} > #{path.to_s}`
end
desc "Export pages"
def response
resp = MultiJson.decode(last_response.body)
# add all of last_response's methods to resp
end
@jch
jch / Gemfile
Created December 1, 2011 05:00
Grape Path and Header Versioning
source 'http://rubygems.org'
gem 'grape', :git => '[email protected]:intridea/grape.git'
gem 'rack'
gem 'rack-test'
@jch
jch / count_gems.sh
Created December 1, 2011 21:38
number of gem dependencies in a project
ruby -ne 'next unless $_ =~ /\(/; puts $_.strip!.gsub(/ .*/, "")' < Gemfile.lock | sort | uniq | wc -l
#!/bin/sh
# For an easy increase in speed in local dev with ruby 1.9.2-p290
#
# To run:
#
# bash < <(curl -s https://raw.github.com/gist/1422116/14ffe8df0d561cd7c30c8dcfdf382fc9838347bb/optimized-ruby-1.9.2-p290.sh)
git clone https://github.com/michaeledgar/ruby-patches.git
cd ruby-patches
rvm uninstall 1.9.2-p290