Skip to content

Instantly share code, notes, and snippets.

View oelmekki's full-sized avatar

kik oelmekki

View GitHub Profile
class I18nGenerator < Rails::Generators::NamedBase
def create_files
I18n.available_locales.each do |locale|
create_locale_file( locale )
end
end
private
def namespaces
namespace :routes do
desc 'Print out all defined routes in match order, with names, per constraint class. Target specific constraint class with CONSTRAINT=x. Target specific controller with CONTROLLER=x.'
task constrained: :environment do
Rails.application.reload_routes!
constraints_routes = Hash.new
Rails.application.routes.routes.each do |route|
group = (route.app.class == ActionDispatch::Routing::Mapper::Constraints ? route.app.send( :constraints ).first.to_s : 'No constraint class')
constraints_routes[group] ||= []
@oelmekki
oelmekki / any_of.rb
Last active December 16, 2015 07:09
class ActiveRecord::Base
def self.any_of( *queries )
queries = queries.map do |query|
query = where( query ) if [ String, Hash ].any? { |type| query.kind_of? type }
query = where( *query ) if query.kind_of?( Array )
query.arel.constraints.reduce( :and )
end
where( queries.reduce( :or ) )
end
@oelmekki
oelmekki / test.rb
Last active December 10, 2015 22:18
module Purchasable
def purchase( attrs = nil )
Purchase.new( attrs || purchase_attributes ).process
end
class Purchase
attr_reader :total, :card
def initialize( options = {} )
@total, @card = options[ :total ] || 0, options[ :card ] || test_card
@oelmekki
oelmekki / user_info.rb
Created November 4, 2012 16:42 — forked from apneadiving/solution.rb
quizz
class UserInfo
attr_accessor :contact
delegate :name, :mail, :phone, to: :contact
def initialize(contact = nil)
self.contact = contact
end
end

Les problèmes essentiels de jQuery

Cet article fait suite à la discussion entre Metal3d et Mathieu Robin.

Saluons d'abord l'article de metal3d, qui pose enfin des questions intéressantes après un article écrit trop tôt qui soulignait surtout les difficultés qu'il avait en découvrant jQuery et en essayant de l'utiliser comme Mootools (ce qui ne peut bien sûr pas fonctionner).

Cependant, on sent bien dans cet article que les problèmes fondamentaux commencent à être touchés sans toutefois être exactement saisis. Laissez-moi vous présenter mon point de vue.

La peur des natives

IRB.conf[:PROMPT][:CUSTOM] = {
:PROMPT_I=>"\n> ",
:PROMPT_N=>"> ",
:PROMPT_S=>"\n%l ",
:PROMPT_C=>"* ",
:RETURN=>"=> %s\n"
}
IRB.conf[:PROMPT_MODE] = :CUSTOM
IRB.conf[:AUTO_INDENT] = true
@oelmekki
oelmekki / go_out.rb
Created May 19, 2012 11:29
kik goes out
#!/usr/bin/env ruby
class Person
attr_accessor :name
def initialize(name)
@name = name
@go_out = 0
end
require 'yaml'
module Delayed
module Backend
module Base
def payload_object
YAML::ENGINE.yamler = 'psych'
@payload_object ||= YAML.load(self.handler)
rescue TypeError, LoadError, NameError, ArgumentError => e
raise DeserializationError,
n /mnt/data/code/rails/TextMaster.com/spec/requests/admin_area/authors_admin_workflow_spec.rb
409 it "should display author's description" do
410 within( '.copywriter-language' ) do
411 within( '.content' ) do
412 within( '.description' ) do
413 debugger
=> 414 page.should have_content( @author.author_profile.author_profiling.copywriter_languages.first.description )
415 end
416 end
417 end