1
2
3
4
Gender.create([
  {:name => "Male", :is_default => true},
  {:name => "Female", :is_default => true}
...

Ruby Create database records

by nimeshnikum.myopenid.com, March 18, 2010 11:33, No refactoring, tagged with speed rails activerecord rails ruby sql

Can't we create first all r...

Bc572b4652b1df3ea13619423acd6127 Talk
1
2
3
4
  def validate_permalink(attr_name)
    if permalink?
      permalink = sanitize_permalink(attr_name)
...

Ruby Simple if staments

by rgoytacaz.myopenid.com, March 16, 2010 01:23, 3 refactorings, tagged with if else

easy one?

9fe77a0217c77ce4cb00096d863c8b45 Talk
1
2
3
#!/usr/bin/env ruby

...

Ruby Sort photos into folders on...

by deepspring.myopenid.com, March 15, 2010 19:07, 1 refactoring, tagged with ruby, sort, photos

Basically, I have a large n...

Avatar Talk
1
2
3
4
# In helper

def show_row(label, attribute)
...

Ruby Infer column name from inst...

by Josh, March 11, 2010 20:18, 1 refactoring, tagged with rails activerecord, models

Assume you have a model, li...

37d67924a83f566ba8220348a3e9bedb Talk
1
2
3
4
# Associations
#
# User: has_many :sources, :as => :sourceable, :dependent => :destroy
...

Ruby Get child elements from a o...

by Chris, March 11, 2010 08:27, No refactoring, tagged with model, assoziations, activerecord, rails activerecord

For a object (e.g. user), I...

5d7c8b8f2de06c07b2bf0848d20ce71f Talk
1
2
3
4
def make_verts(s, r)
  a = Math::PI/s
  b = Math::PI/(s/2)
...

Ruby Dynamic Vertices Generation

by slf, March 08, 2010 22:46, 2 refactorings, tagged with ruby math

Can somebody check my math?...

098e5c1a565b47e9860539fbebc3fa98 Talk
1
2
3
4
        def dedent()
            sRaw    =   self;
            sep     =   "\n";
...

Ruby ruby dedent whitespace in a...

by dreftymac.myopenid.com, March 05, 2010 16:37, 2 refactorings, tagged with ruby, string, monkeypatch

Remove leading whitespace f...

Avatar Talk
1
2
3
4
def hash_from_string(string, value)
  hash, split = {}, string.split(".")
  (split.size-1).downto(0) do |i|
...

Ruby Nested Hash from delimiter-...

by rubiii, March 04, 2010 21:38, 4 refactorings, tagged with ruby, functional

the string can contain 1-n ...

61d580cc983d52f3dc5050a6858fc788 Talk
1
2
3
4
File.open( "binary.bin", "wb" ) do |io|
  obj = BinData::String.new(:initial_value => "Binary file start-point").write(io)      
  obj = BinData::Uint32be.new(:initial_value => 0).write(io)
...

Ruby Creating a binary file with...

by podcaster, March 01, 2010 12:14, 3 refactorings, tagged with binary, ruby, io, bindata

Hi, I'm currently using Bin...

13d7a3ab12ec57e0d372d7115362cb91 Talk
1
2
3
4
    def flights_by_airline(airline_id, flight_number=nil, date=nil, params={})
      if flight_number && date
        t = convert_date(date)
...

Ruby Better way to offer several...

by jarodluebbert.myopenid.com, March 01, 2010 08:21, 3 refactorings, tagged with api, ruby, parameters

I'm wrapping an API in ruby...

3a5f66f6c3feb6092d375c3e145de0d4 Talk
1
2
3
4
tl = Time.now.localtime
(0..356).each {|i| d =  (Date.new(tl.year, tl.month, tl.day) +i );
 printf("\n%03s\n\n", Date::ABBR_MONTHNAMES[d.month]) if d.day == 1;
...

Ruby Generate Days of a Year

by gregelin.myopenid.com, February 27, 2010 15:51, 2 refactorings, tagged with short

I wrote the following to ge...

57f954ba5409a6504af785ed8d42e009 Talk
1
2
3
4
class String
  def squish
    x = 0
...

Ruby Function to remove consiste...

by mxcl, February 27, 2010 15:01, 3 refactorings

The code doesn't feel elega...

25ff3dfe48d3847ecf9971aab99589fb Talk
1
2
3
4
# Initial attributes Hash
# 
attributes = {
...

Ruby Ruby Hash Extraction Using ...

by notbrain.myopenid.com, February 24, 2010 23:13, 7 refactorings, tagged with ruby, rails, regex, hash, block

I'm looking for a better wa...

Avatar Talk
1
2
3
4
class Anagram

  def self.resolves?(first_word, second_word)
...

Ruby Anagram Solver

by aantix, February 19, 2010 21:39, 4 refactorings

This code outputs whether t...

66c680f88e8c379fe408d32299dfb4e6 Talk
1
2
3
4
  def update_materials
    jm = JobMaterial.find(:first, :conditions => {:material_id => params[:job_material][:material_id], :job_id => params[:job_id], :location => params[:job_material][:location]})
    if jm
...

Ruby add or increment item count

by kagedwolf.myopenid.com, February 16, 2010 22:23, 2 refactorings, tagged with rails

This is a custom method in ...

3b583d1c5e2d57db5ad32ee82b56adf4 Talk
1
2
3
def render_page_sitemap(scope, sitemapname,statics, machines, lang)
...

Ruby Speeding up Sitemap generation

by tiekuhn, February 14, 2010 16:35, 3 refactorings, tagged with speed, rake, sitemap, rails

Hi,

I'm looking for a wa...

175ab087b0647367da3d370fbf5bc024 Talk
1
2
3
def encode
    self[:code] = self[:code].gsub(/\&/, "&amp;").gsub(/\</, "&lt;").gsub(/\>/, "&gt;")
end

Ruby Ruby Html Encode

by codeimpossible, February 14, 2010 03:09, 2 refactorings, tagged with ruby, regular expression

I'm looking for an easier/b...

55997cec217233703cbf68b689578771 Talk
1
2
3
4
  #   code_for(0) => 0
  #   code_for(62) => 10
  #   code_for(124) => 20
...

Ruby Create a baseXX string base...

by adamfortuna, February 11, 2010 18:15, 6 refactorings, tagged with ruby

I'm trying to create Bit.ly...

8571728785e5e350ddb58cd458533b12 Talk
1
2
3
4
@merged << @array1
@merged << @array2
@merged.flatten!
...

Ruby Merging two active record a...

by KJF, February 09, 2010 21:28, 2 refactorings, tagged with rails activerecord

I'm merging two active reco...

A529b78031f700ca2005bdbd1af5ee7b Talk
1
2
3
4
def self.capture_system(*args)
  args = args.flatten.compact.collect { |arg| arg.to_s }
  return false if args.blank?
...

Ruby Silencing current output, b...

by k776.myopenid.com, February 03, 2010 02:34, No refactoring, tagged with form, output, process, exec, system

Is there a shorter way to d...

74198b06bc9e68739debfe6c23e070d3 Talk
1
2
3
4
def score(dice)
  
  count = [0,0,0,0,0,0]
...

Ruby Looking for other/better so...

by websymphony.blogspot.com, February 02, 2010 21:42, 9 refactorings, tagged with dice game, ruby

# Greed is a dice game wher...

D7b8e44d9c430f24a9426725d4c33480 Talk
1
2
3
4
for y in 0...height
  for x in 0...width
    # BGR => RGB & miror y
...

Ruby Symplify few loops

by darkleo.myopenid.com, January 30, 2010 20:36, 7 refactorings, tagged with ruby, short

I need to reformat .bmp dat...

61f1b34f172ee1fbc1af42ab3ce0eca9 Talk
1
2
3
4
module FancyDates
  (1..12).each do |mo| 
    t = Time.mktime(1999,mo)
...

Ruby Cleaner way to define const...

by erikpukinskis.myopenid.com, January 19, 2010 20:45, 4 refactorings, tagged with ruby, DateTime

This is code that lets you ...

6015f1c7d2c5057f668f4951f3303b28 Talk
1
2
3
Clip.find_by_sql(["select * from clips where not exists
        (select 'clip_id' from histories where histories.clip_id = clips.id
        and histories.user_id = ?) ORDER BY clips.created_at DESC LIMIT 20", user.id])

Ruby ActiveRecord find_by_sql

by David, January 17, 2010 20:52, 5 refactorings, tagged with activerecord, rails, ruby, sql, short

How can I turn this into so...

Avatar Talk
1
2
3
def rot_encode(s, offset=2)
   s.split('').map{ |char| (char.ord + offset).chr }.join
end  

Ruby rot encode

by Sam Figueroa, January 17, 2010 11:44, 5 refactorings, tagged with rot, rotation, encode, strings

Rotation encoding with vari...

45596033957b2b6d7ef8fe6545e0b7e7 Talk