Skip to content

Instantly share code, notes, and snippets.


Tore Darell toretore

View GitHub Profile
View donkey
donkeys are awesome
View gist:77472
# Norwegian, norsk bokmål, by
sentence_connector: "og"
default: "%d.%m.%Y"
short: "%e. %b"
long: "%e. %B %Y"
View application_helper.rb
module ApplicationHelper
def labelled_form_for(*attrs, &proc)
options = attrs.last.is_a?(Hash) ? attrs.pop : {}
object = attrs.pop
:builder => LabellingFormBuilder
View gist:313401
module Kernel
def recurse(*a, &b)
send(caller(1).first[/`(.*?)'\Z/, 1], *a, &b)
class Foo
def bar(stop=false)
View registerable.rb
#Keeps a list of registered names associated with classes at a "base" class
# class Base
# extend Registerable
# end
# class Foo < Base
# register :foo
# end
toretore / README
Created Apr 9, 2011
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="">
* The FB server returns some HTML & JS with an automatically submitting form:
<form id="humbaba" target="">
<input type="hidden" name="signed_request"/></form>
View gist:953941
# 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 / README
Created May 4, 2011
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 / explicit.rb
Created Nov 15, 2011 — forked from mikebaldry/gist:1366593
find subclasses
View explicit.rb
class PullSource
def self.implementations
@implementations ||= {}
def self.register(name)
implementations[name] << self
toretore / gist:1922637
Created Feb 27, 2012
something like this in the contract model
View gist:1922637
class Contract < ActiveRecord::Base
'contract_status_id' => {
:association => 'contract_status'
:field => 'name'