Skip to content

Instantly share code, notes, and snippets.

@evanphx
Created July 27, 2011 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanphx/1110378 to your computer and use it in GitHub Desktop.
Save evanphx/1110378 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'net/http'
require 'sinatra'
require 'json'
def get_url(file)
response = nil
Net::HTTP.start('rubygems.org', 80) do |http|
response = http.head("/gems/#{file}")
end
response['location']
end
urls = {}
counts = Hash.new(0)
get '/gems/:file' do
file = params[:file]
if u = urls[file]
counts[file] += 1
else
u = get_url(file)
urls[file] = u
count = 0
end
redirect u
end
get '/stats' do
counts.to_json
end
get '/refresh_stats' do
c = counts
counts = Hash.new(0)
c.to_json
end
get '/*' do
redirect "http://rubygems.org/#{params[:splat].first}"
end
@raggi
Copy link

raggi commented Jul 29, 2011

Hey Evan,

Something I put together a while ago, the Fuse dependency is probably too heavy for many uses, but as a combined concept, could be somewhat interesting to build progressive mirrors:

https://gist.github.com/1113280

Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment