Skip to content

Instantly share code, notes, and snippets.

View swalberg's full-sized avatar

Sean Walberg swalberg

View GitHub Profile
class MyClass
def self.blah(opts, &block)
result = somefunction(opts)
block.call(result)
end
end
class YourClass
def self.blah(opts)
result = somefunction(opts)
class Blah
def self.foo(&block)
bar
end
def bar(&block)
block.call("abc")
end
end
class ActionController::Base
def self.check_signatures(key, *args)
before_filter lambda { check_signature(key)}, *args
end
def self.check_signature(key)
raise InvalidWebhookSignature
end
end
[user]
name = Sean Walberg
email = [email protected]
[color]
ui = auto
[core]
editor = /usr/bin/vim
[alias]
co = checkout
ci = commit
>> :foo.object_id
=> 302268
>> :foo.object_id
=> 302268
>> "foo".object_id
=> 2165056460
>> "foo".object_id
=> 2165052320
ree-1.8.7-2011.03 :030 > PayrollRun.create
ArgumentError: wrong number of arguments (2 for 1)
from /Users/sean/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/activerecord-3.1.2/lib/active_record/base.rb:508:in `initialize'
from /Users/sean/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/activerecord-3.1.2/lib/active_record/base.rb:508:in `new'
from /Users/sean/.rvm/gems/ree-1.8.7-2011.03@rails31/gems/activerecord-3.1.2/lib/active_record/base.rb:508:in `create'
from (irb):30
ree-1.8.7-2011.03 :031 > PayrollRun.new
=> #<PayrollRun id: nil, employer_id: nil, start: nil, finish: nil, created_at: nil, updated_at: nil, status: "pending">
app/controllers/webhooks/versapay_controller.rb:
class Webhooks::VersapayController < ApplicationController
check_versapay_signatures VERSAPAYSIGNINGKEY
...
end
from gem:
class ActionController::Base
class LocalFormBuilder < ActionView::Helpers::FormBuilder
def label(method, text = nil, options = {})
#Check to see if text for this label has been supplied and humanize the field name if not.
text = text || method.to_s.humanize
#Get a reference to the model object
#Add any additional text that might be needed on the label
text += " <span class=\"text\">#{h options[:description]}</span>".html_safe if options[:description]
text += "<span class=\"required\">*</span>".html_safe if options[:required]
#Finally hand off to super to deal with the display of the label
application helper:
def title(phrase, container=nil)
@page_title ||= phrase
content_tag(container, phrase) if container
end
layout:
<title><%= @page_title || "Default page title" %></title>
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<title>Action Controller: Exception caught</title>
<style>
body { background-color: #fff; color: #333; }
body, p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}