Skip to content

Instantly share code, notes, and snippets.

José Valim josevalim

Block or report user

Report or block josevalim

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View render_sibling_helper.rb
# José Valim <jose.valim@gmail.com>
# http://josevalim.blogspot.com/
# http://www.pagestacker.com/
#
# This render_sibling paste is Rails 2.2 compatible.
# For Rails 2.1 render_sibling, please check here: http://gist.github.com/19674
module RenderSiblingHelper
# What?
#
View _benchmark_result
# ab -n 1000 -c 5 localhost:3000/main/get_with_component
Requests per second: 51.04 [#/sec]
Time per request: 97.969 [ms]
# ab -n 1000 -c 5 localhost:3000/main/get_with_sibling
Requests per second: 57.35 [#/sec]
Time per request: 87.188 [ms]
# ab -n 1000 -c 5 localhost:3000/main/get_with_partial
Requests per second: 59.04 [#/sec]
View render_sibling_helper.rb
# José Valim <jose.valim@gmail.com>
# http://josevalim.blogspot.com/
# http://www.pagestacker.com/
#
# This render_sibling paste is Rails 2.1 compatible.
# For Rails 2.2 render_sibling, please check here: http://gist.github.com/19631
module RenderSiblingHelper
# What?
#
View routes_locale_wise.diff
diff --git a/actionpack/lib/action_controller/routing/route_set.rb b/actionpack/lib/action_controller/routing/route_set.rb
index ff44849..f3a4f09 100644
--- a/actionpack/lib/action_controller/routing/route_set.rb
+++ b/actionpack/lib/action_controller/routing/route_set.rb
@@ -170,18 +170,24 @@ module ActionController
def #{selector}(*args)
#{generate_optimisation_block(route, kind)}
+ locale = #{route.segment_keys.include?(:locale) ? '{ :locale => I18n.locale || I18n.default_locale }' : '{}'}
+
View dismaxsolr.xml
<!-- DisMaxRequestHandler allows easy searching across multiple fields
for simple user-entered phrases.
see http://wiki.apache.org/solr/DisMaxRequestHandler
-->
<requestHandler name="dismax" class="solr.DisMaxRequestHandler" >
<lst name="defaults">
<str name="echoParams">explicit</str>
<float name="tie">0.01</float>
<str name="qf">
text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 manu^1.1 cat^1.4
View snippet.sh
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# username@Machine ~/dev/dir[master]$ # clean working directory
# username@Machine ~/dev/dir[master*]$ # dirty working directory
function parse_git_deleted {
[[ $(git status 2> /dev/null | grep deleted:) != "" ]] && echo "-"
}
function parse_git_added {
[[ $(git status 2> /dev/null | grep "Untracked files:") != "" ]] && echo '+'
View fixture.rb
class Fixtures < (RUBY_VERSION < '1.9' ? YAML::Omap : Hash)
def self.destroy_fixtures(table_names)
NestedScenarios.delete_tables(table_names)
end
end
module Test #:nodoc:
module Unit #:nodoc:
class TestCase #:nodoc:
superclass_delegating_accessor :scenario_path
View ensure_confirmation_of_matcher.rb
module Remarkable # :nodoc:
module ActiveRecord # :nodoc:
module Matchers # :nodoc:
class EnsureConfirmationOfMatcher < Remarkable::Matcher::Base
include Remarkable::ActiveRecord::Helpers
def initialize(*attributes)
load_options(attributes.extract_options!)
@attributes = attributes
end
View localized_rescue.rb
# actionpack/lib/action_controller/rescue.rb
#
module ActionController
class Base
protected
# Attempts to render a static localized error page based on the <tt>status_code</tt>
# thrown, or just return headers if no such files exists. For example, if a 500 error
# is being handled Rails will first attempt to render the file based on the current
# locale such as <tt>public/500.pt-BR.html</tt>. If it does not exist, attempts to
View macro_stubs.rb
describe ProjectsController do
describe "responding to GET show" do
receives :find, :on => Project, :with => { :id => '37' }, :and_returns => mock_project
get :show, :id => '37'
should_assign_to(:project)
describe "mime XML" do
mime Mime::XML
#
You can’t perform that action at this time.