1 2 3 4
def self.capture_system(*args) args = args.flatten.compact.collect { |arg| arg.to_s } return false if args.blank? ...
1 2 3 4
def score(dice) count = [0,0,0,0,0,0] ...
Ruby Looking for other/better so...
# Greed is a dice game wher...
1 2 3 4
for y in 0...height for x in 0...width # BGR => RGB & miror y ...
Ruby Symplify few loops
I need to reformat .bmp dat...
1 2 3 4
module FancyDates (1..12).each do |mo| t = Time.mktime(1999,mo) ...
Ruby Cleaner way to define const...
This is code that lets you ...
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
How can I turn this into so...
1 2 3
def rot_encode(s, offset=2) s.split('').map{ |char| (char.ord + offset).chr }.join end
Ruby rot encode
Rotation encoding with vari...
1 2 3 4
original_file = File.open('content1.txt', 'r') new_file = File.open('master1.txt', 'w') ...
Ruby Making email addresses out ...
I have a text file with jus...
1 2 3 4
module Rack class Request def subdomains ...
Ruby Personalized URL (Purl) Sub...
by grayfm,
January 11, 2010 22:25,
No refactoring, tagged with url, rack, sinatra, subdomain, domain
So i need to define @purl_b...
1 2 3 4
def splitlines() sraw = self.to_s sraw = sraw.gsub(/\r\n/,"\n"); ...
Ruby line up delimited text into...
by dreftymac.myopenid.com,
January 11, 2010 17:02,
No refactoring, tagged with ruby, delimited, pretty, formatting
allow any character(s) as t...
1 2 3 4
class Item < ActiveRecord::Base ALL_VOTES = "all_votes" SCORE = "score" ...
Ruby Complex query in Ruby on Ra...
I have a method called rank...
1 2 3 4
require 'net/http' require 'rexml/document' require 'download.rb' ...
Ruby help with processing nzb/xm...
by bain19.myopenid.com,
January 09, 2010 23:51,
4 refactorings, tagged with nzb, usenet, download, parse, slow, ruby, xml
I was bored during ruby cla...
1 2 3 4
# generate(100, 200, 2, 3) => # [[100, 200], [125, 188], [150, 176], [125, 212], [150, 200], [175, 188]] ...
Ruby rotating a rectangle
Think of a section of squar...
1 2 3 4
def sort if params[:fact_id] @fact = Fact.find_by_id(params[:fact_id]) || Fact.new ...
Ruby Ugly IF, ELSE
Trying to make this a lot c...
1 2 3 4
namespace :deploy do require 'net/ssh' ...
Ruby Git deployment rake task
Simple and FAST frameworkle...
1 2 3 4
class Array def with_indices n = 0 ...
Ruby Stable sort in ruby
Ruby's sort isn't stable. L...
1 2 3 4
#!/usr/bin/env ruby -w require 'rexml/document' ...
Ruby Let me merge my Tomboy notes!
Learning Ruby, and learning...
1 2 3 4
pages.keys.each do |k| logger.debug "Pages for #{k} channel:" ...
Ruby Can this be less clunky?
"pages" is a Hash and conta...
1 2 3 4
def has_just_one_kind_of_thing?(item, controller)
if (controller == 'foos' && item.widgets.blank?) || (controller == 'foos' && item.doohickeys.blank?) || (controller == 'bars' && item.widgets.blank?) || (controller == 'bars' && item.doohickeys.blank?) || (controller == 'bazes' && item.widgets.blank?) || (controller == 'bazes' && item.contraptions.blank?)
...
Ruby 6 embarassingly ugly line m...
Hi everyone,
I'm trying ...
1 2 3 4
class Numeric def evenize(round="+") eval "self #{round} (self.modulo(2))" ...
Ruby Numeric#evenize
It almost feels stupid to d...
1
from_date.empty? || ( from_date.empty? == false && role.updated_at > from_date)
Ruby boolean
by macsig.myopenid.com,
November 17, 2009 23:44,
2 refactorings
Is there a way to make this...
1 2 3 4
def get_token self.class.precedence.each do |token| if val = send(token) ...
Ruby lexer
by Tj Holowaychuk,
November 13, 2009 16:41,
5 refactorings
Everything else in my lib i...
Is there a shorter way to d...