This file contains 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
require 'uri' | |
def generate_canonical_link | |
query_elements = [] | |
query_elements << "page=#{params[:page]}" unless params[:page].to_i <= 1 # page=0 should be valid? | |
query_elements << "query=#{params[:query]}" if params[:query] | |
# use URI::Generic.build2 to automatically escape the query params | |
# you can actually get away with simple string manipulation here, but you get the idea | |
uri = URI::Generic.build( :scheme => request.env['rack.url_scheme'], |
This file contains 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
// Simplified one-liner version with a bit of added functionality | |
String.prototype.namespace = function(objects, scope, separator){ | |
return Object.extend(this.split(separator || '.').inject((scope || window), function(parent, child){ | |
return (parent[child] = parent[child] || {}); | |
}), objects || {}); | |
} | |
// Sample usage | |
'com.pixeldepo.some.package'.namespace(); | |
'com.pixeldepo.some.other.package'.namespace(); |