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
## | |
# Sets the query component for this URI. | |
# | |
# @param [String, #to_str] new_query The new query component. | |
def query=(new_query) | |
@query = new_query ? new_query.to_str : nil | |
# Reset dependant values | |
@normalized_query = nil | |
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
def rand_hex_3(l) | |
"%0#{l}x" % rand(1 << l*4) | |
end | |
def rand_uuid | |
[8,4,4,4,12].map {|n| rand_hex_3(n)}.join('-') | |
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
UUID # a wrapper class for UUIDs, not a generator, with handy implicit to_str cast | |
UUID::Generator | |
UUID::TimestampGenerator.new | |
UUID::RandomGenerator.new | |
UUID::SHA1Generator.new(namespace) | |
UUID::MD5Generator.new(namespace) | |
UUID::Generator::DEFAULT = UUID::TimestampGenerator.new | |
uuid = UUID.new | |
#=> #<UUID:0xdb5268 UUID:012c377a-bfeb-11dd-b84a-001ec2186a45> |
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
$ SYDNEY=1 bin/rbx gem env | |
RubyGems Environment: | |
- RUBYGEMS VERSION: 1.3.1 | |
- RUBY VERSION: 1.8.6 (12/31/2009 patchlevel 111) [i686-apple-darwin9.5.0] | |
- INSTALLATION DIRECTORY: /Users/sporkmonger/Projects/Ruby/OpenSource/rubinius/gems/1.8 | |
- RUBYGEMS PREFIX: /Users/sporkmonger/Projects/Ruby/OpenSource/rubinius | |
- RUBY EXECUTABLE: /Users/sporkmonger/Projects/Ruby/OpenSource/rubinius/bin/rbx | |
- EXECUTABLE DIRECTORY: /Users/sporkmonger/Projects/Ruby/OpenSource/rubinius/bin | |
- RUBYGEMS PLATFORMS: | |
- ruby |
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
# http://github.com/sporkmonger/retrieve/tree/master | |
require "retrieve/clients/http" | |
connections = {} | |
100.times do | |
Retrieve.open("http://google.com/", :connections => connections) do |resource| | |
puts resource.read[0..75] + "..." | |
end | |
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
require "addressable/uri" | |
Addressable::URI.parse( | |
"http://example.com/a/b/c/?one=1&two=2#foo" | |
).extract_mapping( | |
"http://{host}/{-suffix|/|segments}?{-join|&|one,two,bogus}\#{fragment}" | |
) | |
#=> { | |
"host" => "example.com", | |
"segments" => ["a", "b", "c"], | |
"one" => "1", |
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
# WHY? | |
"/foo/bar/baz".split("/") | |
# => ["", "foo", "bar", "baz"] | |
"/foo/bar/baz/".split("/") | |
# => ["", "foo", "bar", "baz"] | |
"foo/bar/baz/".split("/") | |
# => ["foo", "bar", "baz"] | |
# What's the best way to get this result? |
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
# Percent encodes a URI or component. | |
# | |
# @param [String, #to_str] uri The URI or component to encode. | |
# | |
# @option [String, Regexp] character_class | |
# The characters which are not percent encoded. If a <tt>String</tt> | |
# is passed, the <tt>String</tt> must be formatted as a regular | |
# expression character class. (Do not include the surrounding square | |
# brackets.) For example, <tt>"b-zB-Z0-9"</tt> would cause everything | |
# but the letters 'b' through 'z' and the numbers '0' through '9' to be |
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
#!/usr/bin/env ruby | |
gem_home = `gem env home` | |
gem_repository = File.join(gem_home, "gems") | |
gem_name = ARGV.shift | |
if gem_name == nil || gem_name == "" | |
puts "Must supply a gem name." | |
exit(1) |
NewerOlder