1 2 3 4
module NameAssociation def self.extended(object) object.instance_eval(<<-EOS, '(__NAME_ASSOCIATION__)', 1) ...
1 2 3 4
class Object def self.cache_method(method, options = {}) define_method("#{method}_with_memoization") do |*args| ...
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...
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 ...
1 2 3 4
class PropertiesController < ApplicationController PUBLIC_ACTIONS = %w[index show map_info_window] LANDORD_ACTIONS = %w[new edit create update destroy] ...
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...
1 2 3 4
for directory in @directories xml.item do xml.title "#{directory.name} (PR #{directory.pagerank})" ...
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...
1 2 3 4
class Photo < ActiveRecord::Basse URL_PREFIX = 'http://s3.carfinancechief.com.au' DIMENSIONS = { 'search' => '200x100', 'module' => '100x50', 'main' => '418x155' } ...
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...
1 2 3 4
class MutableFixnum instance_methods.each { |method| undef_method(method) unless method =~ /^__.*__$/ } ...
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 ...
1 2 3 4
def inject(accumulator = 0) each { |element| accumulator = yield(accumulator, element) } accumulator ...
