1
2
3
4
key = [:fact_id, :image_id, :video_id, :community_idea_id, :stock_ad_id].detect {|k| params.has_key?(k)}

if key
...

Ruby On Ugly IF, ELSE

by danielharan, December 18, 2009 17:13

This smells of too many res...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
require 'ostruct'

class Page < OpenStruct
...

Ruby On Can this be less clunky?

by danielharan, November 26, 2009 16:53

I'd avoid the confusing has...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
def has_only_widgets_or_doohickeys?
  @item.widgets.blank? || @item.doohickeys.blank?
end
...

Ruby On 6 embarassingly ugly line m...

by danielharan, November 23, 2009 04:42

The people on StackOverflow...

880cbab435f00197613c9cc2065b4f5a Talk

Ruby On Numeric#evenize

by danielharan, November 18, 2009 04:38

I'd define floor_even and c...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
@subscriptions = [:free, :lite, :brisk, :jammin].inject({}) do |result, ele|
  result[ele] = SubscriptionType.make(ele)
  result
...

Ruby On Hash assignment

by danielharan, August 04, 2009 03:55

Hmm... that's a bit long. I...

880cbab435f00197613c9cc2065b4f5a Talk

Ruby On Hash assignment

by danielharan, August 03, 2009 20:32

Use inject({}). Technically...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
  def self.merge_sum_new(*hashes)
    returning(Hash.new {|h,k| h[k] = 0}) do |new_hash|
      hashes.each do |hash|
...

Ruby On Total the values in multipl...

by danielharan, July 08, 2009 02:03

Using Rails' K combinator, ...

880cbab435f00197613c9cc2065b4f5a Talk

Ruby On Redundant Method Calls

by danielharan, June 11, 2009 13:40

You could iterate over them...

880cbab435f00197613c9cc2065b4f5a Talk

Ruby On Create user, company and ro...

by danielharan, May 04, 2009 21:35 Star_fullStar_fullStar_fullStar_fullStar_full

Check out giraffesoft's act...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
pp 'The green hat is the twin of the green hat'.downcase.split.to_freq_hash

# from http://github.com/danielharan/support/blob/14178d993a566d8d2e583c24591f4e381e49d327/lib/support/array_ext.rb
...

Ruby On Count words in a string

by danielharan, May 03, 2009 00:29

That task occurred often en...

880cbab435f00197613c9cc2065b4f5a Talk

Ruby On acts_as_nested_set menu

by danielharan, May 01, 2009 15:12

I wrote a semantic-menu plu...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
				URL url = new URL("https://dev.psigate.com:7989/Messenger/XMLMessenger");
				HttpURLConnection connection = (HttpURLConnection)url.openConnection();
				connection.setDoInput(true);		
...

Java PSiGate

by danielharan, January 30, 2009 01:46, 4 refactorings, tagged with psigate, cc, xml, webservice

This seems particularly egr...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
def haar_1d(a)
  r = []
  (Math.log(a.length) / Math.log(2) - 1).to_i.downto(0) { |j|
...

Ruby On Fast Haar Wavelet Transform

by danielharan, January 26, 2009 04:31 Star_fullStar_fullStar_fullStar_full

Oy, I'd want unit tests bef...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
class SomeObjectWithComponent
  def component_value=(value)
    send("#{component}=", value)
...

Ruby On ruby metaprogramming

by danielharan, January 06, 2009 01:47 Star_fullStar_fullStar_fullStar_full

c.component sounds like a t...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
open("output.txt", 'a') do |file|
  1000.times do
    file.puts create_word('cvcvv') + '.com'
...

Ruby On Web2.0 Domain Name Generator

by danielharan, December 08, 2008 14:13 Star_fullStar_fullStar_fullStar_fullStar_full

Devin, your second entry gi...

880cbab435f00197613c9cc2065b4f5a Talk

Ruby On Phone number regex

by danielharan, October 31, 2008 16:56

Works well with North Ameri...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
def image_path(type)
  img_url = "http://s3.carfinancechief.com.au"
  photo = find_photo("F")
...

Ruby On DRY it up please

by danielharan, October 26, 2008 14:25

There is some repetition th...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
a = [['a', '1'], ['b', '2', '3']]
p Hash[*a.flatten]
ArgumentError: odd number of arguments for Hash
...

Ruby On Conversion from the 2d arra...

by danielharan, October 22, 2008 14:41

Actually, I assumed it was ...

880cbab435f00197613c9cc2065b4f5a Talk
1
[['a', '1'], ['b', '2']].inject({}) {|hash,i| k,v = i; hash[k] = v; hash}

Ruby On Conversion from the 2d arra...

by danielharan, October 22, 2008 14:19
880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
def setup_search
    @timetable = Timetable.find( :first,
      :conditions => [ 'day = ? AND status = "active"', params[:id] ]
...

Ruby On lengthy if statement. (Ruby...

by danielharan, October 22, 2008 02:43

Here's what I'd be aiming f...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
def search
  Course.paged_search nil, nil, nil, params[:page]
  # ... add breadcrumb and course_categories
...

Ruby On Search with fulltext, ago-c...

by danielharan, October 07, 2008 14:40

Is this what's going on whe...

880cbab435f00197613c9cc2065b4f5a Talk
1
2
3
4
class ReportReader
  def initialize(file_name)
    @lines = File.open(file_name).read.split("\n")
...

Ruby On Parsing non-delimited text

by danielharan, October 06, 2008 13:54

Separate out parsing logic ...

880cbab435f00197613c9cc2065b4f5a Talk

Ruby On Map fields array and data a...

by danielharan, September 22, 2008 17:07

It's rather odd not to know...

880cbab435f00197613c9cc2065b4f5a Talk
1
biggest_square = [1,4,3,5].inject(0){ |memo, i| [memo, square(i)].max }

Ruby On Conditional Assignment

by danielharan, September 22, 2008 16:34 Star_fullStar_fullStar_fullStar_full

I sent MA a link to your re...

880cbab435f00197613c9cc2065b4f5a Talk

Ruby On Format Filesize

by danielharan, September 22, 2008 16:18

Check out 'Show source' on ...

880cbab435f00197613c9cc2065b4f5a Talk