Skip to content

Instantly share code, notes, and snippets.

View ugisozols's full-sized avatar

Uģis Ozols ugisozols

View GitHub Profile
Benchmark.bmbm do |x|
x.report("each") do
count = 0
self.posts.each do |p|
count += 1 if p.live?
end
count
end
source 'http://rubygems.org'
gem 'rails', '~> 3.0.4'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Use unicorn as the web server
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@ugisozols
ugisozols / rails_3_1_beta_1_changes.md
Created May 7, 2011 13:39 — forked from ryanb/rails_3_1_rc4_changes.md
The Changelogs for Rails 3.1 Beta 1

Railties 3.1 Beta 1

  • The -j option of the application generator accepts an arbitrary string. If passed "foo", the gem "foo-rails" is added to the Gemfile, and the application JavaScript manifest requires "foo" and "foo_ujs". As of this writing "prototype-rails" and "jquery-rails" exist and provide those files via the asset pipeline. Default is "jquery". [fxn]

  • jQuery is no longer vendored, it is provided from now on by the jquery-rails gem. [fxn]

  • Prototype and Scriptaculous are no longer vendored, they are provided from now on by the prototype-rails gem. [fxn]

  • The scaffold controller will now produce SCSS file if Sass is available [Prem Sichanugrist]

@ugisozols
ugisozols / gist:1027992
Created June 15, 2011 20:13
Search Psych::SyntaxError
# This will help you trace .yml file which containts Psych::SyntaxError
require "rubygems"
require "psych"
$LOAD_PATH.unshift(File.dirname(__FILE__))
# specify your locales folder in Dir.glob("*") with relative path from this file
Dir.glob("*").sort.each do |file|
begin
%w(title menu_title).each do |column|
pages = pages.joins(:translations).select(
"#{translation_class.table_name}.#{column} as page_#{column}"
).where("#{translation_class.table_name}.#{column} IS NOT NULL")
end
@ugisozols
ugisozols / application.rb
Created September 6, 2011 14:25
assets lazily compiled in production
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
# Bundler.require *Rails.groups(:assets => %w(development test))
# If you want your assets lazily compiled in production, use this line
Bundler.require(:default, :assets, Rails.env)
end
def self.search_filter(name,manufacture_id,product_type_id)
f_manufacture_id = manufacture_id
f_manufacture_id = f_manufacture_id.join(', ') unless manufacture_id.nil?
result = order("id DESC")
result = result.where("name LIKE ?", "%#{name}%") unless name.empty?
result = result.where("manufacture_id IN (?)", f_manufacture_id) unless manufacture_id.nil?
result = result.where(:product_type_id => product_type_id) unless product_type_id.blank?
result
@ugisozols
ugisozols / gist:1467105
Created December 12, 2011 13:19
Refinery CMS specs using minitest
# Refinery CMS Core RSpec specs converted to MiniTest::Spec
# spec/minitest_helper.rb
require "minitest/spec"
require "minitest/autorun"
require "mocha"
ENV["RAILS_ENV"] = "test"
require File.expand_path("../dummy/config/environment", __FILE__)
@ugisozols
ugisozols / gist:1600844
Created January 12, 2012 14:32
Refinery::Blog routes
Refinery::Core::Engine.routes.draw do
# frontend
namespace :blog do
root :to => "posts#index"
resources :posts
end
# backend
namespace :blog, :path => "" do