Skip to content

Instantly share code, notes, and snippets.

@toretore
toretore / donkey
Created July 20, 2008 20:32
werwer
donkeys are awesome
# Norwegian, norsk bokmål, by irb.no
"no":
support:
array:
sentence_connector: "og"
date:
formats:
default: "%d.%m.%Y"
short: "%e. %b"
long: "%e. %B %Y"
module ApplicationHelper
def labelled_form_for(*attrs, &proc)
options = attrs.last.is_a?(Hash) ? attrs.pop : {}
object = attrs.pop
options.reverse_merge!(
:builder => LabellingFormBuilder
)
module Kernel
def recurse(*a, &b)
send(caller(1).first[/`(.*?)'\Z/, 1], *a, &b)
end
end
class Foo
def bar(stop=false)
#Keeps a list of registered names associated with classes at a "base" class
#Example:
#
# class Base
# extend Registerable
# end
#
# class Foo < Base
# register :foo
# end
@toretore
toretore / README
Created April 9, 2011 23:23
Facebook Canvas apps, CSRF protection & session cookies
Facebook Canvas apps are loaded like this:
* User clicks link to app or tab ("page as tab")
* An iframe is inserted which loads content from the FB server (NOT yours, yet)
Something along the lines of:
<iframe src="http://facebook.com/page_proxy.php?appid=123">
* The FB server returns some HTML & JS with an automatically submitting form:
<form id="humbaba" target="http://you.com/facebook">
<input type="hidden" name="signed_request"/></form>
# Returns a set of hidden fields for params passed in the query string such that they are passed
# along with the form. Mostly for use with GET forms like search/filtering where you want to retain
# other state while adding another (<existing params>&q=pr0n)
#
# Options:
#
# :skip - An array of keys to leave out - Only works for first-level keys, i.e. not 'bar' in foo[bar]=baz
def hidden_fields_from_params(opts={})
#Use CGI.parse to get "raw" parameters that haven't been converted into arrays
#and hashes yet. This means it only has to concern itself with the one dimension
@toretore
toretore / README
Created May 4, 2011 08:08
Rails authentication
User authentication with Rails
This is all you need to have fully working and secure authentication in Rails.
Why use this instead of <bloated auth framework>? Well, there are a number of
reasons, but I guess you'll just have to go through a few apps where you
learn the hard way why the idea of a "fully featured" authentication
framework that doesn't get on your nerves is a mirage.
Don't simply copy and paste this without understanding everything it does. It's
@toretore
toretore / explicit.rb
Created November 15, 2011 10:03 — forked from mikebaldry/gist:1366593
find subclasses
class PullSource
def self.implementations
@implementations ||= {}
end
def self.register(name)
implementations[name] << self
end
@toretore
toretore / gist:1922637
Created February 27, 2012 09:02
something like this in the contract model
class Contract < ActiveRecord::Base
has_paper_trail
acts_as_restful_list
CHANGE_FIELDS_MAP = {
'contract_status_id' => {
:association => 'contract_status'
:field => 'name'
}