Tuesday, December 24, 2013

Ruby: split vs regex, Benchmark

http://stackoverflow.com/questions/7533479/ruby-string-search-which-is-faster-split-or-regex

require 'benchmark'
Benchmark.bm do |x|
    x.report { 50000.times { a = 'a@b.c'.split('@')[0] } }
    x.report { 50000.times { a = 'a@b.c'[/[^@]+/] } }
end

Sunday, December 22, 2013

Rails: routes

If we want to 'namespace' our routes, but do not want the 'named routes' to have namespace's name in the prefix:


namespace :admin, as: '' do
   get '/post/new' => 'posts#new', as: 'new_admin_post'
end

To learn Orchard CMS

Monday, December 9, 2013

Ruby: each_with_index


X.each_with_index do |item, index|
  puts "current_index: #{index}
end

Monday, December 2, 2013

Rails: Reordering Columns

Sometimes it is necessary to reorder columns so that data is presented, by default, in a more meaningful way e.g. the 'key' columns probably should appear in the beginning, followed by other columns that do not allow a Null value, followed by columns that can take in Null values (basically, are not that important)

http://stackoverflow.com/questions/18899011/rails-4-migration-how-to-reorder-columns

Sunday, December 1, 2013

Rails: scope in models

scope :my_books, lambda {|user_id| {:conditions => ["user_id = ?", user_id] }}

Have to read about scope and conditions - how to specify And , Or ?

Followers

Blog Archive