This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; variables local to this directory and its children | |
| ((nil . ((auto-whitespace-cleanup . t)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def resource_available?(url) | |
| uri = URI(url) | |
| Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == "https") do |http| | |
| http.head(uri.request_uri) | |
| end.code =~ /^[123]/ | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ApplicationController < ActionController::Base | |
| protected | |
| # A version of the params map which copies members to session (per | |
| # controller) on access. Use this to make parameters sticky; for | |
| # instance for a page number or search fields. | |
| def sticky_params | |
| params.dup.tap do |m| | |
| m.instance_variable_set("@http_session", session) | |
| m.instance_variable_set("@http_context", self.class.name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module MochaHelper | |
| def with_mocked_const(name, &block) | |
| original = Object.const_get(name) | |
| Object.instance_eval do | |
| remove_const(name) | |
| const_set(name, Mocha::Mock.new(name)) | |
| end | |
| yield |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (comment ; given | |
| (defn authenticated? [username password] | |
| ..)) | |
| (comment ; with compojure | |
| (defroutes public-handler | |
| (GET ..)) | |
| (defroutes protected-handler | |
| (POST ..)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Ehm.. | |
| Company.first.employees.class # => Array | |
| Array === Company.first.employees # => false | |
| Enumerable === Company.first.employees # => false | |
| # But how? | |
| ActiveRecord::Associations::AssociationCollection === Company.first.employees # => true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Simple continuous slide show using JQuery. | |
| Usage: | |
| <div id="slides"> | |
| <div class="slide">First</div> | |
| <div class="slide">Second</div> | |
| <div class="slide">Third</div> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mysql> INSERT INTO tags (name) VALUES ('test '); | |
| Query OK, 1 row affected (0.00 sec) | |
| mysql> SELECT * FROM tags WHERE name = 'test'; | |
| +----+-------+ | |
| | id | name | | |
| +----+-------+ | |
| | 1 | test | | |
| +----+-------+ | |
| 1 row in set (0.00 sec) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Make controller render and render partial fall back to ancestor | |
| # controllers. Very hackish because it overrides rails private | |
| # methods. Tested on rails 2.3.5 till 2.3.11. | |
| module InheritableViewsHelper | |
| def render_partial_with_inheritance(options = {}) | |
| if [String, Symbol, NilClass].find{|k| k === options[:partial]} | |
| if options[:partial].include?('/') | |
| render_partial_without_inheritance(options) | |
| else | |
| err = nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Extend functional test case with asserts for missing translations. | |
| # These asserts are automatically included on +assert_response+ and | |
| # +should_respond_with+. | |
| class ActionController::TestCase | |
| def assert_no_missing_translations | |
| assert(@response.body !~ %r{ class=.*translation_missing.*?(>|>)(.+?)(<|<\\?)/span}, | |
| "missing translation in body: #{$2.inspect}") | |
| assert(@response.body !~ /^translation missing: (.*)$/, | |
| "missing translation in body: #{$1.inspect}") |