Skip to content

Instantly share code, notes, and snippets.

View chikamichi's full-sized avatar
🙈
You good?

Jean-Denis Vauguet chikamichi

🙈
You good?
View GitHub Profile
@chikamichi
chikamichi / init.rb
Created July 27, 2009 01:18
Marshalization plugin: how to override an instance private method from ActiveRecord::Dirty
# rails/init.rb
require 'marshalize'
ActiveRecord::Base.send(:include, Marshalization::Base)
ActiveRecord::Base.send(:include, Marshalization::AttributeMethods)
ActiveRecord::Base.send(:include, Marshalization::Dirty)
- use respond_to (or something else?) in send_data to externalize the .js processing, in the same fashion one would use a .rjs file.
- be able to use :method => "get" without triggering the show action.
@chikamichi
chikamichi / hello
Created December 28, 2009 14:20
rackcodehighlighter, ultraviolet and maruku
actually it's views/hello.md, but gist would trigger Markdown highlighting
# Fibonacci numbers in Ruby
:::ruby
def fib(n)
if n < 2
1
else
fib(n-2) + fib(n-1)
@chikamichi
chikamichi / Gemfile
Created March 10, 2010 00:58
rails3 + cucumber ok
source 'http://gemcutter.org'
gem "rails", "3.0.0.beta"
gem "sqlite3-ruby", :require => "sqlite3"
gem "test-unit"
gem "rspec-rails", ">= 2.0.0.beta.1"
gem 'capybara'
gem 'database_cleaner'
@chikamichi
chikamichi / gem list
Created March 10, 2010 01:44
rails3 + cucumber fail
$ gem list
*** LOCAL GEMS ***
abstract (1.0.0)
actionmailer (3.0.0.beta)
actionpack (3.0.0.beta)
activemodel (3.0.0.beta)
activerecord (3.0.0.beta)
activeresource (3.0.0.beta)
# no explicit reference to web_steps
# that is, features/authentication/step_definitions/authentication_steps.rb contains:
Given /^I am not authenticated$/ do
# do nothing
end
$ cucumber features/authentication/authentication.feature
Using the default profile...
Feature: User authentication
To ensure the safety of the application
@chikamichi
chikamichi / plugins_standalone.rb
Created March 21, 2010 02:07
plugins system: standalone
module Base
class Server
def blabla(argument)
@config ||= "default"
if @config == "default"
p "Server says: #{argument}"
end
puts "config: #{@config}"
@chikamichi
chikamichi / base.rb
Created March 21, 2010 02:12
plugins system: nested
# ./base.rb
require 'base/plugins'
module Base
class Server
include Plugins
def say(what)
p "say: #{what}"
module Base
module Plugins
def self.plugins
@plugins ||= []
end
def self.activate plugin_name
begin
plugin = Base::Plugins.const_get(plugin_name.capitalize)
rescue
@chikamichi
chikamichi / do.rb
Created March 26, 2010 13:57
dynamic instances extending mechanism for Metamorphosis
require 'facets/kernel/constant'
require 'active_support/core_ext/module/attribute_accessors'
module Metamorphosis
module Injector
@@receiver = "Foo"
def clutch cst_path, *directives, &blk
raise ArgumentError unless cst = Object.constant([@@receiver, cst_path].join("::"))
raise ArgumentError unless cst.is_a? Class or cst.is_a? Module