Skip to content

Instantly share code, notes, and snippets.

View noahhendrix's full-sized avatar

Noah Hendrix noahhendrix

View GitHub Profile
@noahhendrix
noahhendrix / gist:1035064
Created June 20, 2011 03:18
Sample Log File with Sprockets
Started GET "/clients/5" for 127.0.0.1 at 2011-06-19 22:02:54 -0500
Processing by ClientsController#show as HTML
Parameters: {"id"=>"5"}
...
Completed 200 OK in 495ms (Views: 401.1ms | ActiveRecord: 2.0ms)
Started GET "/assets/application.js" for 127.0.0.1 at 2011-06-19 22:02:55 -0500
Compiled ~/Sites/invoicey/app/assets/javascripts/application.js (3ms) (pid 2725)
Compiled ~/.rvm/gems/ruby-1.9.2-p180@invoicey/gems/jquery-rails-1.0.11/vendor/assets/javascripts/jquery.js (0ms) (pid 2725)
@noahhendrix
noahhendrix / ContentBlock Class
Created June 16, 2011 22:39
Content Block Class
class ContentBlock
attr_accessor :template
delegate :content_tag, :to => :template
def initialize(template, options = {}, block)
@template = template
@title = options[:title] || ''
@block = block
@tabs = []
end
@noahhendrix
noahhendrix / total_time.sql
Created November 19, 2010 20:34
sum of difference of two datetime columns
SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(s.ended_at, s.started_at))))
Contact.limit(5).search({ :deleted_at_is_blank => true })
ActiveRecord::StatementInvalid: PGError: ERROR: invalid input syntax for type timestamp: ""
: SELECT "contacts".* FROM "contacts" WHERE (("contacts"."deleted_at" IS NULL OR "contacts"."deleted_at" = '')) LIMIT 5
ActiveRecord::StatementInvalid: PGError: ERROR: column "sales.id" must appear in the GROUP BY clause or be used in an aggregate function
: SELECT "sales".* FROM "sales" WHERE (branch_name = 'St. Joseph') AND ("sales"."invoiced_on" = '2010-08-09') GROUP BY date_part('year', invoiced_on)
can :read, Contact, :deleted_at => nil
#SELECT * FROM contacts WHERE (deleted_at IS NULL or deleted_at = "")
gem 'sqlite3-ruby', :require => 'sqlite3', :group => :development
gem 'mysql', :group => :production
def index
@activities = current_user.activities.search(params[:search]
end
WillPaginate::ViewHelpers.pagination_options[:renderer] = "ProperPagination"
class Ability
include CanCan::Ability
def initialize(user)
if user.is? :admin
can :read, :all
can :manage, Activity, :user_id => [user.id, *user.asm_ids]
elsif user.is? :supervisor
can :manage, Activity, :user_id => [user.id, *user.asm_ids]
elsif user.is? :ASM