JavaScript On Double 'if'

by Adam, August 24, 2010 16:01

Good point. Like I have sai...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
def format_category_list(categories)
  link_to_categories(categories.first(3)).tap do |output|
    if categories.size > 3
...

Ruby On Generating a list of 3 entr...

by Adam, August 24, 2010 15:30
A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
class Feeds
  FEEDS = %W(
    http://feed.kennisnet.nl/Basisonderwijs
...

Ruby On Fetch and parse feeds with ...

by Adam, August 24, 2010 00:41 Star_fullStar_fullStar_fullStar_fullStar_full
A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
var message;

if (XMLHttpRequest.responseText.length > 0) {
...

JavaScript On Double 'if'

by Adam, August 23, 2010 19:26
A8d3f35baafdaea851914b17dae9e1fc Talk
1
CartItem.group('cart_id').having('quantity > 6').sum(:quantity)

Ruby On Sum of the Column

by Adam, August 23, 2010 03:07

You would be correct. Misre...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
uri = URI.parse(the_uri)
uri.query = CGI.parse(uri.query).merge!('size' => size).map { |key,value| URI.escape("#{key}=#{value}") }.join('&')

Ruby On Set value of key in uri

by Adam, August 22, 2010 03:10 Star_fullStar_fullStar_fullStar_fullStar_full
A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
CartItem.group(:cart_id).where('quantity > 6').sum(:quantity)
# => #<OrderedHash {1=>16, 2=>12}>

Ruby On Sum of the Column

by Adam, August 22, 2010 02:53

I disagree that you want to...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
attributes = openid_mapping.inject({}) do |hash,(key,maps)|
  hash.update(key => result.values_at(*maps).compact.first)
end

Ruby On Hash + Array refactor

by Adam, August 19, 2010 19:04
A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
class Item < ActiveRecord::Base
  belongs_to :cart  
  belongs_to :product
...

Ruby On Add product to cart, reject...

by Adam, August 17, 2010 00:20

Additionally, set your quan...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
array.inject({}) { |hash,key| hash.update(key => func(key)) }

Ruby On How to make it more idiomatic?

by Adam, August 16, 2010 23:35

True, but Hash#update is ev...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
percentile = 1.0 / items.sum { |item| item.fragments.count } * 100

Ruby On Calculate sum of items in a...

by Adam, August 16, 2010 19:33

ActiveSupport defines Enume...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
array.inject({}) { |hash,key| hash.merge(key => func(key)) }

Ruby On How to make it more idiomatic?

by Adam, August 16, 2010 15:02
A8d3f35baafdaea851914b17dae9e1fc Talk

Ruby On Handling NoMethodError

by Adam, August 13, 2010 19:43

Whoops, yes, you are correc...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
class User
  delegate :name, :to => :user_group, :prefix => :user_group, :allow_nil => true  
  
...

Ruby On Handling NoMethodError

by Adam, August 13, 2010 18:14 Star_fullStar_fullStar_fullStar_fullStar_full

On second thought, you migh...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
@group_name = @user.user_group.try(:name) if @user.try(:role) == 'user'

Ruby On Handling NoMethodError

by Adam, August 13, 2010 17:39

Note: If Object#try is not ...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
tab = [ ["a","b"] , ["c","e"] , ["d"]]

def generate(tab)
...

Ruby On Generate code for parsing a...

by Adam, August 11, 2010 16:23

Not sure why you are genera...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
@groups = ldap.get_groups("DC=example,DC=com")
@group_names = @groups.map { |group| group[:cn ] }.flatten!

Ruby On Refactor array of hashes

by Adam, August 09, 2010 23:33 Star_fullStar_fullStar_fullStar_fullStar_full
A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
def translated?
  [ params, cookies, session ].any? { |store| store[:lang] == 'en' || store[:locale] == 'en' }
end

Ruby On too many ifs and ands

by Adam, August 09, 2010 17:35 Star_fullStar_full
A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
def is_pos_activation?(&block)
  session[:pos_activation] && (block || Proc.new { true }).call
end

Ruby On better way?

by Adam, July 22, 2010 20:49

@Martin - Good point. Refac...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
def is_pos_activation?
  return yield if block_given?
  session[:pos_activation]
...

Ruby On better way?

by Adam, July 22, 2010 00:06
A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
require 'rubygems'
require 'active_support/core_ext/object/blank'

...

Ruby On Vigenere cipher implementation

by Adam, July 19, 2010 05:32
A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
class Issue < ActiveRecord::Base
  has_many :logs
  
...

Ruby On Named Scope Trouble

by Adam, July 15, 2010 05:33

I attempted to infer your m...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
function dataStringToArray(string) {
    return string.split('|').map(function(segment) {
        return segment.split(',').map(function(digit) {
...

JavaScript On Delimited data string to ne...

by Adam, July 08, 2010 02:56 Star_fullStar_fullStar_fullStar_fullStar_full
A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
require 'rubygems'
require 'active_support/core_ext/hash/indifferent_access'

...

Ruby On val.respond_to? x, but val....

by Adam, July 07, 2010 17:22

You don't even need a Rails...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
class Object
  def keys_to_sym
    self
...

Ruby On val.respond_to? x, but val....

by Adam, July 07, 2010 04:40

The problem in your code is...

A8d3f35baafdaea851914b17dae9e1fc Talk