1
2
3
4
module NameAssociation
  def self.extended(object)
    object.instance_eval(<<-EOS, '(__NAME_ASSOCIATION__)', 1)
...

Ruby On Similar virtual attributes ...

by Adam, November 21, 2008 06:12
A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
class SchoolYear < ActiveRecord::Base
  has_many :semesters
end
...

Ruby On Arrays, loops, strings...

by Adam, November 21, 2008 05:23

I get the feeling you would...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
require 'activesupport'

class Object
...

Ruby On Caching Methods

by Adam, November 19, 2008 06:03

Caching the result in memca...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
class Object
  def self.cache_method(method, options = {})
    define_method("#{method}_with_memoization") do |*args|
...

Ruby On Caching Methods

by Adam, November 19, 2008 06:02

Memoization with expiration.

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
#include <limits.h>

#define MIN(a,b) ((a) > (b) ? (b) : (a))
...

C On How to find max, min of thr...

by Adam, November 18, 2008 16:34 Star_fullStar_fullStar_fullStar_fullStar_full
A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
switch (V_VT(&var)) {
    case VT_BSTR:
        for (char *string = (char *)var.bstrVal; *string; string += 2) {
...

C++ On Stream ADODB recordset into...

by Adam, November 18, 2008 06:19

I don't know if it's any fa...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
<% form_for @user do |f| %>
<% end %>

Ruby On Re-use code for new and cre...

by Adam, November 12, 2008 16:51

I used respond_to? because ...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
1.upto(limit).inject(1) { |result,element| result * element }

Ruby On A simple factorial program.

by Adam, November 12, 2008 05:05

The require statement retur...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
require 'enumerator'

def factorial(limit)
...

Ruby On A simple factorial program.

by Adam, November 12, 2008 04:04
A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
class PropertiesController < ApplicationController
  PUBLIC_ACTIONS  = %w[index show map_info_window]
  LANDORD_ACTIONS = %w[new edit create update destroy]
...

Ruby On Condensing nested conditionals

by Adam, November 12, 2008 03:55
A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
class PropertiesController < ApplicationController
  before_filter :authorize_user_is_logged_in, :only => [ :new, :create, :edit, :update, :destroy ]
  before_filter :authorize_user_has_permission, :only => [ :new, :create, :edit, :update, :destroy ]
...

Ruby On Condensing nested conditionals

by Adam, November 11, 2008 23:43

I'm not sure what deny_acce...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
require 'filemode'
File.stat(ARGV[0]).to_s # => "-rw-r--r--"

...

Ruby On Pretty output of permission...

by Adam, November 07, 2008 03:12 Star_fullStar_fullStar_fullStar_fullStar_full
A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
<% @feeds.each_slice(3) do |feeds| %>
  <ul>
...

Ruby On View refactoring

by Adam, November 07, 2008 00:52 Star_fullStar_fullStar_fullStar_full
A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
for directory in @directories
  xml.item do
    xml.title "#{directory.name} (PR #{directory.pagerank})"
...

Ruby On xml rss feed

by Adam, November 05, 2008 16:12
A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
class UsersController < ApplicationController
  def new
    @user = User.new
...

Ruby On Re-use code for new and cre...

by Adam, November 05, 2008 15:56

Sometimes it is just a good...

A8d3f35baafdaea851914b17dae9e1fc Talk

Ruby On DRY up a controller action

by Adam, November 03, 2008 05:32

I get feeling that you real...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
# http://code.google.com/p/rainpress/
require 'rainpress/packer'

...

Ruby On Gsubing

by Adam, October 31, 2008 13:32 Star_fullStar_fullStar_fullStar_fullStar_full

You could do more with your...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
require 'rexml/document'

document = REXML::Document.new(xml)
...

Ruby On Simplest way to find the na...

by Adam, October 29, 2008 03:49
A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
class Photo < ActiveRecord::Basse
  URL_PREFIX = 'http://s3.carfinancechief.com.au'
  DIMENSIONS = { 'search' => '200x100', 'module' => '100x50', 'main' => '418x155' }
...

Ruby On DRY it up please

by Adam, October 27, 2008 04:48

Personally, I would probabl...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
class PriceFilter < ItemFilter
  DIRECTIONS = { 'at most' => '<=', 'at least' => '>=' }
  
...

Ruby On DRYing/shortening form proc...

by Adam, October 27, 2008 04:06

I am going to leave the imp...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
class MutableFixnum
  instance_methods.each { |method| undef_method(method) unless method =~ /^__.*__$/ }
  
...

Ruby On Yield by 'reference'

by Adam, October 24, 2008 16:15 Star_fullStar_fullStar_fullStar_fullStar_full

Not without a wrapper class...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
>> 1.object_id
=> 3

...

Ruby On Yield by 'reference'

by Adam, October 24, 2008 15:58

That's because Fixnums are ...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
[ 1, 2 ].inject(0) { |accumualtor,value| accumualtor + value } # => 3

[ 1, 2 ].inject(x = 0) { |accumualtor,value| accumualtor += 10; accumualtor + value } # => 23
...

Ruby On Yield by 'reference'

by Adam, October 24, 2008 02:26

@Tj - "It is interesting th...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
def inject(accumulator = 0)
  each { |element| accumulator = yield(accumulator, element) }
  accumulator
...

Ruby On Yield by 'reference'

by Adam, October 24, 2008 01:28 Star_fullStar_fullStar_fullStar_fullStar_full

Inject is implemented like ...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
<?php
    function unique_file($prefix, $suffix, $index = -1)
    {   
...

PHP On Generate a numbered file name

by Adam, October 23, 2008 15:18 Star_fullStar_fullStar_fullStar_full

Creates the file to prevent...

A8d3f35baafdaea851914b17dae9e1fc Talk