Skip to content

Instantly share code, notes, and snippets.

View aaronjensen's full-sized avatar

Aaron Jensen aaronjensen

View GitHub Profile
@aaronjensen
aaronjensen / gist:3091343
Created July 11, 2012 15:58
Git merge problem
I would like to combine 1f9c2db and 890164b so there is only one merge.
* 1f9c2db - (HEAD, integration) Merge branch 'topic' into integration (4 minutes ago) <Aaron Jensen>
|\
| * 890164b - (integration) Merge branch 'topic' into integration (4 minutes ago) <Aaron Jensen>
| |\
| | * 9f8452b - (topic) topic (4 minutes ago) <Aaron Jensen>
| |/
* | 2d51b1b - Merge branch 'topic2' into integration (5 minutes ago) <Aaron Jensen>
unless Rails.env.test?
Rack::MiniProfiler.config.position = 'right'
Rack::MiniProfiler.config.pre_authorize_cb = lambda {|env| true }
Rack::MiniProfiler.config.authorization_mode = :whitelist unless Rails.env.development?
end
@aaronjensen
aaronjensen / gist:3220780
Created July 31, 2012 21:34
tmux agenda
* What is tmux?
* Why tmux?
* tmux vs screen: http://www.wikivs.com/wiki/Screen_vs_tmux
* Install tmux
* brew install tmux
* tmux basics
* leader key (default sucks)
* sessions
* windows
* panes
@aaronjensen
aaronjensen / gist:3662238
Created September 7, 2012 01:14
hub and __git_ps1 are slow
[18:12:58 app (feature/403 $ u=)]$ time __git_ps1
(feature/403 $ u=)
real 0m0.072s
user 0m0.037s
sys 0m0.033s
[18:13:18 app (feature/403 $ u=)]$ which hub
hub is /usr/local/bin/hub
[18:13:32 app (feature/403 $ u=)]$ which git
git is /usr/local/bin/git
git is /usr/bin/git
@aaronjensen
aaronjensen / strong_parameters.rb
Created October 30, 2012 20:03
Force strong parameters
# Place in config/initializers
ActiveRecord::Base.class_eval do
class << self
def inherited_with_strong_params(sub)
inherited_without_strong_params(sub)
# Filter out plugin models that won't work with strong_parameters yet
unless sub.name =~ /^doorkeeper/i
sub.send :include, ActiveModel::ForbiddenAttributesProtection
end
end
@aaronjensen
aaronjensen / prevent_database_access.rb
Created November 15, 2012 19:32
Prevent database access in specs
# place in spec/support/prevent_database_access.rb
ActiveRecord::ConnectionAdapters::Mysql2Adapter.class_eval do
def execute_with_prevent_database_access(sql, name=nil)
if prevent_database_access?(sql)
raise "You should only access the database in model and acceptance specs.
If you really need to you can use :db to grant access for that spec.
Offending query: \"#{sql}\""
end
@aaronjensen
aaronjensen / edit_data_bag.rb
Created November 21, 2012 04:39
Edit encrypted data bags for use with chef-solo and knife-solo
#!/usr/bin/env ruby
Dir.chdir File.join(__FILE__, "../..")
unless ENV['EDITOR']
puts "No EDITOR found. Try:"
puts "export EDITOR=vim"
exit 1
end
unless ARGV.count == 2
@aaronjensen
aaronjensen / gist:4144850
Created November 25, 2012 19:18
DCI dynamic super class
# Define a new role "super class"
Applicant = Role.new do
def apply
# ...
end
end
# Applicant[User] returns a cacheable class that inherits from User but
# has the behavior of the Applicant role as well
# i.e. calling Applicant[User] is equivalent to writing this:
def create_very_rails
project = Project.create project_params
if project.persisted?
sync_new project
redirect_to project
else
redirect_to edit_project_path(project)
end
end
module EnableModelSync
extend ActiveSupport::Concern
included do
around_filter :enable_sync
end
def enable_sync
ModelSync.enable(self) do
yield