Skip to content

Instantly share code, notes, and snippets.

Florian Dutey fdutey

View GitHub Profile
View post.rb
class Post < ActiveRecord::Base
validates_unchanged_value :title, :if => published?,
:message => :frozen_attribute_when_published
View gist:102477
module ActiveRecord
module CustomValidations
def validates_unchanged_value(*attr_names)
configuration = { :message => :frozen_attribute }
configuration[:on] = :update
validates_each(attr_names, configuration) do |record, attr_name, value|
View gist:1613585
module Formol
class Post < ActiveRecord::Base
attr_protected :topic_id, :user_id, :created_by_topic
#Virtual attributes
attr_accessor :created_by_topic, :quote_id, :register_user_as_subscriber
#Default values
default_value_for :created_by_topic, false
View gist:2358352
Comme nous l'avons vu, il n'y a pas de classe en JavaScript.
La notion même d'héritage tel que conçu de manière traditionnelle n'a donc aucun sens.
Il existe plusieurs façons de concevoir et mettre en oeuvre l'héritage en JS:
* héritage de prototype
* héritage classique
* copie
View gist:2938865
describe :note_for do
it 'give notes for the project' do
CategoryProject.create(:project => project,
:category => category,
:description => 'test')
params = { :category => category }
project.notes.create params.merge(:value => 8)
2.times{ project.notes.create params.merge(:value => 3) }
View sum.rb
def parse_arg(arg)
a, b, q = arg.split(' ').map(&:to_i)
[, b), q]
inputs = []
while arg = STDIN.gets
inputs << parse_arg(arg)
View dependency_injection.rb
# lib/services/user/signup_service.rb
module Services
module User
class SignUpService
attr_reader :publish_statistics_service,
def initialize(
You can’t perform that action at this time.