Skip to content

Instantly share code, notes, and snippets.

@hardbap
hardbap / tweet.rake
Created February 23, 2012 23:56
rake task with default args
namespace :tweets do
desc 'Send some tweets to a user'
task :send, [:username] => [:environment] do |t, args|
args.with_defaults(:username => 'cpytel')
Tweet.send(args[:username])
end
end
@hardbap
hardbap / Gemfile
Created January 17, 2012 16:03
test from ST2
group :guard do
gem 'guard', '= 0.8.8' # works with my (old) version of growl
gem 'rb-fsevent', :require => false
gem 'growl_notify', :require => false
gem 'guard-coffeescript'
gem 'guard-sass'
end
def reorder
redirect_to confirm_order_path and return if params[:reorder] == current_order.id.to_s
reorder = current_user.orders.find(params[:reorder])
redirect_to favorites_order_path, :notice => 'The order is no longer available.' and return if reorder.nil?
redirect_to favorites_order_path, :notice => 'There are items in your cart. Please cancel your current order before reordering.' and return if (current_order.items.any?)
search_result = reorder.next_available_delivery
@hardbap
hardbap / TechDecisions.md
Created November 27, 2011 14:37
Choices to make in a new Rails project

Team Support

Source Code Control

git (private server)
Alternative: github

Time Tracking

Cashboard

query = MyModel.where("id = :id", :id => 21)
query = query.merge(MyModel.some_scope)
MyModel.connection.select_all(query.to_sql)
new_order = reorder.xerox
new_order.save
current_order.destroy
current_order = new_order
current_order.status = 'open'
current_order.favorite = false
current_order.created_at = DateTime.now
current_order.updated_at = DateTime.now
current_order.mealsoft_response = nil
current_order.error_message = nil
@hardbap
hardbap / development.rb
Created August 26, 2011 14:13
Replace The Rails Console With Pry
# From Dan Watsons Coding Zen
# http://www.dotnetguy.co.uk/post/2011/08/23/replace-the-rails-console-with-pry
MyApp::Application.configure do
silence_warnings do
begin
require 'pry'
IRB = Pry
rescue LoadError
end
@hardbap
hardbap / gist:1027003
Created June 15, 2011 12:47
Output using migration for ar-hstore
NOTICE: return type hstore is only a shell
NOTICE: argument type hstore is only a shell
WARNING: => is deprecated as an operator name
DETAIL: This name may be disallowed altogether in future versions of PostgreSQL.
NOTICE: return type ghstore is only a shell
NOTICE: argument type ghstore is only a shell
@hardbap
hardbap / gist:1018815
Created June 10, 2011 13:25
inject jQuery into a page
var s=document.createElement('script');s.setAttribute('src', 'http://jquery.com/src/jquery-latest.js');document.getElementsByTagName('body')[0].appendChild(s);$j=jQuery.noConflict();
class QueryTracer < ActiveSupport::LogSubscriber
ACCEPT = %r{^(app|config|lib)}.freeze
FRAMES = 5
THRESHOLD = 300 # In ms
def sql(event)
return unless event.duration > THRESHOLD
callers = Rails.
backtrace_cleaner.