# i use this method instead of "render" render_from_cache_or_render(:cache_key =>â€cache keyâ€, :cache_expire_after => ConstantHelper::TAG_CLOUD_EXPIRED_IN, # minute ...
Ruby fragment cache
def test_destroy_category_with_dependent
category = Category.find(3)
...
Ruby managable test method
in my test case method, i w...
def replace_keywords(keyword_hash, text_to_parse)
keyword_hash.each do |key, value|
new_key = key.dup
...
Ruby Simple Text Replacement
A simple method that replac...
#!/usr/bin/env ruby
files = ARGV.collect { |fname| File.new(fname, 'w') }
...
Ruby Randomly split input lines.
My first Ruby script. I'm c...
<%= (@post.category ? @post.category.name : '') + ' ' + link_to(@post.title, post_path(@post)) %>
Ruby Handling nil object
@post.category can be nil, ...
#Input string msg = "I wonder if this code can be better." ...
Ruby Circular Cipher
Simple cipher program. Modi...
class PostsController < ResourceController::Base ...
Ruby resource_controller: Redesi...
Backstory on my blog: http:...
regexp = Regexp.new(ARGV[0]) match_index = (ARGV[1] || 1).to_i ...
Ruby Print out the Regex Capture
My aim: Print out the regex...
require 'rubygems' require 'uri' require 'net/http' ...
Ruby Technorati Ping
This code is made to be in ...
has_many :expenses, :dependent => :destroy do
def for_week(day)
find(:all, :conditions => { :spent_at => day.to_time.beginning_of_week.to_date..(day.to_time.beginning_of_week.to_date + 6)})
...
Ruby Finding all in a date range...
So my User has an associati...
module ModelHelpers def self.included(base) ...
Ruby textilize model helper
OK, so I just realized ther...
SIXTYTWO = ('0'..'9').to_a + ('a'..'z').to_a + ('A'..'Z').to_a
def to_s_62(i)
...
Ruby Base 62 Encoding
Base WHAT??? Well, 62 is th...
class String
def postal?
self.match(/[a-zA-Z]{1}\d{1}[a-zA-Z]{1}([\x20-])*\d{1}[a-zA-Z]{1}\d{1}/) ? true : false
...
Ruby Is This String Postal?
We've had the debate over w...
# String#to_proc # # See http://weblog.raganwald.com/2007/10/stringtoproc.html ( Subscribe in a reader) ...
Ruby String#to_proc (by Reginald...
Reginald Braithwaite has a ...
namespace :migrations do desc 'reverts, renames and re-executes uncommitted migrations that conflict with already committed migrations' ...
Ruby Rails migration conflict re...
Explained here: http://www....
# Note: Kuwait does not use DST. # See how the utc_offset value represents ...
Ruby A DST-adjusted UTC offset
I need to get the Daylight-...
<%= f.text_field :first_name, :size => 15 %> ...
Ruby Three groups, three bits of...
I have three classes of peo...
require "erb" # build data class ...
Ruby Need explaination
This is from the documentat...
has_attachment :content_type => :image ...
Ruby attachment_fu integration
I have used the attachment_...
def new @course = Course.new ...
Ruby Using partials for a golf s...
I'm building a golf applica...
keys = {
"a" => %w(q w s z),
"b" => %w(v n g h),
...
Ruby Getting QWERTY misstypes
This is not really a refact...
class Bug attr_accessor :type attr_accessor :name ...
Ruby Rubyize this : 4th edition
Welcome to the 4th edition ...
def args_eval(line) tokens = [] while(data = line.match(/\[.*\]/)) ...
Ruby Argument eval
this code evaluates a strin...
class TreeNode
def TreeNode.action(action)
@@action = action
...
Ruby Changing contexts in a DSL ...
I use this code in a blog p...
i was getting serious perfo...