1 2 3 4
# camera related def frame_diagonal(frame_horizontal, frame_vertical) @frame_diagonal = Math.sqrt((frame_horizontal**2) + (frame_vertical**2)) ...
Ruby Photograhy methods
by sfusion.myopenid.com,
December 05, 2008 11:42,
No refactoring, tagged with photography, camera, lens, ruby, math
1 2 3 4
module Verbal module English ...
Ruby Displaying numbers to words.
by ytse.myopenid.com,
November 27, 2008 13:45,
4 refactorings
Is it possible to refactore...
1
named_scope :with_description, :conditions => "description IS NOT NULL and trim(description) != ''"
Ruby Doing a 'blank?' in named_s...
Can you do a .blank? in a n...
1 2 3 4
/* sample input h1. Introduction * s5 is way cool, but I think in textile ...
Ruby Converting Textile to S5
by MattK,
November 25, 2008 14:08,
No refactoring, tagged with redcloth, textile, loops, regular regular expression
I'd like to take a bunch of...
1 2 3 4
def field_row(options={}, &block) concat("<div class="field_row">", block.binding) concat(capture(&block), block.binding) ...
Ruby Cheap ruby block templating
Hello all. I've got the fol...
1 2 3 4
def test(a, b) capitalize_args puts a # => Hello ...
Ruby Bindings on caller
I dont really have a need f...
1 2 3 4
def monitor(uri) Thread.new(uri) do |uri| begin ...
Ruby Initial script execution ve...
by Tj Holowaychuk,
November 22, 2008 02:27,
No refactoring
Below is a little snippit o...
1 2 3 4
select = [] joins = [] %w[first second third forth].each{ |semester| joins << ":pdp_#{semester}_semester"; (1..5).each{ |n| select << "pdp_#{semester}_semesters.objetive_#{n} AS #{semester}_objetive_#{n}" }} ...
Ruby Arrays, loops, strings...
Can this be done in one line?
1 2 3 4
class Publication < ActiveRecord::Base def publisher_name ...
Ruby Similar virtual attributes ...
by foxdemon,
November 20, 2008 13:42,
4 refactorings, tagged with getter, setter, virtual attributes
My Publication class has a ...
1
/(?<part>(w(?!ww)|w(?=www)|w(?=[a-z0-9]+ww)|ww(?=[a-z0-9]+w)|www[a-z0-9]+|[a-vx-z0-9])[a-z0-9]*)\.example\.com/
Ruby Shortest regular expression...
I have written this regular...
1 2 3 4
describe Stock do it "should be valid when new" do ...
Ruby repeated code in rspec mode...
how do i clean up this repe...
1 2 3 4
def factorial( n ) if !(n.is_a? Integer) raise ArgumentError, "argument must be a positive integer" ...
Ruby A simple factorial program.
by lordzoner.myopenid.com,
November 12, 2008 02:16,
7 refactorings, tagged with short, ruby, factorial
I'm quite new to Ruby, and ...
1 2 3
class PropertiesController < ApplicationController before_filter :authorise_action ...
Ruby Condensing nested conditionals
The code below works, but f...
1 2 3 4
# Suppose I have San::Languages::JavaScript as the 'lang' local var below # I want a string of 'JavaScript' from this example ...
Ruby Retrieve class name only
by Tj Holowaychuk,
November 07, 2008 04:41,
1 refactoring
Im sure there is a better w...
1 2 3 4
# [user@host ~]$ ls -l blah # -rwxr--r-- 1 user users 0 2008-11-06 15:20 foo ...
Ruby Pretty output of permission...
This snippet is designed to...
1 2 3
class PeopleController < ApplicationController ...
Ruby Re-use code for new and cre...
Hello,
I have a 'people'...
1 2 3 4
for directory in @directories xml.item do xml.title "#{directory.name} (PR #{directory.pagerank})" ...
Ruby xml rss feed
by chovy.myopenid.com,
November 05, 2008 07:13,
2 refactorings, tagged with Ruby on Rails, proc, xml, ruby
Looking for a better way to...
1 2 3 4
# GET /neighbourhoods/map_filter def map_filter @map_filter_errors = nil # Stores errors related to a filter request. ...
Ruby DRY up a controller action
My Neighbourhood "map_filte...
1 2 3 4
/^(?:(\d)[ \-\.]?)?(?:\(?(\d{3})\)?[ \-\.])?(\d{3})[ \-\.](\d{4})(?: ?x?(\d+))?$/ # expanded version w/ comments ...
Ruby Phone number regex
by Lex,
October 31, 2008 16:00,
3 refactorings, tagged with phone number, regex, regexp, regular expression
I wrote this regex for pars...
1 2 3
id ...
Ruby Inserting dynamic string in...
by DG,
October 31, 2008 10:21,
1 refactoring
Let me explain the scenario...
1 2 3 4
def compress(source) source.gsub!(/\s+/, " ") # collapse space source.gsub!(/\/\*(.*?)\*\//, "") # remove comments - caution, might want to remove this if using css hacks ...
Ruby Gsubing
There is a lot of repetitio...
1 2 3 4
Event.find(:all, :conditions => "((strftime('%m%d', ends_at) <= strftime('%m%d', starts_at)) AND (strftime('%m%d', 'now') <= strftime('%m%d', ends_at))) OR ...
Ruby Yearly recurring event
Users can add yearly recurr...
Any comments, corrections, ...