Skip to content

Instantly share code, notes, and snippets.

View pier-oliviert's full-sized avatar

Pier-Olivier Thibault pier-oliviert

View GitHub Profile
class Ticket::GrouperValidator < ActiveModel::Validator
def validate(record)
record.errors.add :grouper, 'has already occurred!' if record.grouper.full?
record.errors.add :grouper, 'has already occurred!' if record.grouper.past?
end
end
@pier-oliviert
pier-oliviert / test.rb
Last active December 26, 2015 21:28 — forked from anonymous/gist:7215813
class User < ActiveRecord::Base
include Redis::Objects
counter :reminders_to_send
def purge
@@redis_objects = {}
end
end
class Foo
has_many :tags
has_many :states
# q is hash: { "tags" => "ruby", "states" => "open" }
def self.search(q)
# wat do?
end
end
class ApplicationController < ActionController::Base
protect_from_forgery
prepend_before_filter :authenticate!
before_filter :restrict_routes!
cattr_accessor :skipping_authentication
rescue_from Exits::Unauthorized do |exception|
flash.alert = t("restrictions.unauthorized")
def negotiate(handshake)
config = Rails.application.config
key_generator = Rails.application.key_generator
secret_token = config.secret_token
secret_key_base = config.secret_key_base
host = handshake.headers['Host']
cookies = Rack::Utils.parse_query(handshake.headers['Cookie'], ';,') { |s| Rack::Utils.unescape(s) rescue s }
cookies.map { |k,v| Array === v ? v.first : v }
options = {
module Ouan
def self.object
@test = '1234'
end
end
Ouan.object
#-> 1234
Ouan.instance_variable_get('@test')
class SomeController < ApplicationController
def create
@record = Record.new params[:record]
respond_to do |format|
format.js do
if @record.save
render "create"
else
Pathname.new(__FILE__) + "../what/ever/file.rb"
# VS
File.expand_path("../what/ever/file.rb", __FILE__)
class SimpleDelegator
attr_reader :object
def initialize(obj)
@object = obj
end
def method_missings(method, *args)
if obj.responds_to? method
obj.send(method, *args)
"active_support/descendants_tracker"
"active_support/file_update_checker"
"active_support/log_subscriber"
"active_support/notifications"
"active_support/backtrace_cleaner"
"active_support/base64"
"active_support/basic_object"
"active_support/benchmarkable"
"active_support/buffered_logger"
"active_support/cache"